author | Claus Gittinger <cg@exept.de> |
Sat, 01 Sep 2018 17:32:13 +0200 | |
changeset 1086 | efc5221435a5 |
parent 917 | e92da349ec56 |
child 1156 | b6ca954ebfc9 |
permissions | -rw-r--r-- |
84 | 1 |
"{ Package: 'stx:goodies/monticello' }" |
2 |
||
3 |
MCPackageManager subclass:#MCWorkingCopy |
|
4 |
instanceVariableNames:'versionInfo ancestry counter repositoryGroup requiredPackages' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
600 | 7 |
category:'SCM-Monticello-Versioning' |
84 | 8 |
! |
9 |
||
10 |
||
11 |
!MCWorkingCopy class methodsFor:'as yet unclassified'! |
|
12 |
||
13 |
adoptVersionInfoFrom: anInstaller |
|
14 |
|viCache| |
|
15 |
viCache := Dictionary new. |
|
16 |
anInstaller versionInfo keysAndValuesDo: [:packageName :info | |
|
17 |
(self forPackage: (MCPackage named: packageName)) |
|
18 |
versionInfo: (self infoFromDictionary: info cache: viCache)]. |
|
19 |
[anInstaller clearVersionInfo] on: Error do: ["backwards compat"]. |
|
20 |
! |
|
21 |
||
22 |
ancestorsFromArray: anArray cache: aDictionary |
|
23 |
^ anArray ifNotNil: [anArray collect: [:dict | self infoFromDictionary: dict cache: aDictionary]] |
|
24 |
! |
|
25 |
||
26 |
infoFromDictionary: aDictionary cache: cache |
|
27 |
| id | |
|
28 |
id _ aDictionary at: #id. |
|
29 |
^ cache at: id ifAbsentPut: |
|
30 |
[MCVersionInfo |
|
31 |
name: (aDictionary at: #name) |
|
32 |
id: (aDictionary at: #id) |
|
33 |
message: (aDictionary at: #message) |
|
34 |
date: (aDictionary at: #date) |
|
35 |
time: (aDictionary at: #time) |
|
36 |
author: (aDictionary at: #author) |
|
37 |
ancestors: (self ancestorsFromArray: (aDictionary at: #ancestors) cache: cache)] |
|
38 |
! |
|
39 |
||
40 |
initialize |
|
41 |
Smalltalk |
|
42 |
at: #MczInstaller |
|
43 |
ifPresent: [:installer | self adoptVersionInfoFrom: installer]. |
|
44 |
self updateInstVars. |
|
45 |
"Temporary conversion code -- remove later" |
|
46 |
registry ifNotNil:[registry rehash]. "changed #=" |
|
47 |
self allInstancesDo:[:each| "moved notifications" |
|
48 |
Smalltalk at: #SystemChangeNotifier ifPresent:[:cls| |
|
49 |
cls uniqueInstance noMoreNotificationsFor: each. |
|
50 |
]. |
|
51 |
]. |
|
52 |
self registerForNotifications. |
|
53 |
! |
|
54 |
||
55 |
updateInstVars |
|
56 |
self allInstances do: [:ea | ea updateInstVars] |
|
57 |
! ! |
|
58 |
||
917 | 59 |
|
84 | 60 |
!MCWorkingCopy methodsFor:'accessing'! |
61 |
||
62 |
ancestors |
|
63 |
^ ancestry ancestors |
|
64 |
! |
|
65 |
||
66 |
ancestry |
|
67 |
^ ancestry |
|
68 |
! |
|
69 |
||
70 |
clearRequiredPackages |
|
71 |
requiredPackages _ nil |
|
72 |
! |
|
73 |
||
74 |
currentVersionInfo |
|
75 |
^ (self needsSaving or: [ancestry ancestors isEmpty]) |
|
76 |
ifTrue: [self newVersion info] |
|
77 |
ifFalse: [ancestry ancestors first] |
|
78 |
! |
|
79 |
||
80 |
description |
|
81 |
^ self packageNameWithStar, ' (', ancestry ancestorString, ')' |
|
82 |
! |
|
83 |
||
84 |
needsSaving |
|
85 |
^ self modified or: [self requiredPackages anySatisfy: [:ea | ea workingCopy needsSaving]] |
|
86 |
! |
|
87 |
||
88 |
requirePackage: aPackage |
|
89 |
(self requiredPackages includes: aPackage) ifFalse: [requiredPackages add: aPackage] |
|
90 |
! |
|
91 |
||
92 |
requiredPackages |
|
93 |
^ requiredPackages ifNil: [requiredPackages _ OrderedCollection new] |
|
94 |
! |
|
95 |
||
96 |
versionInfo: aVersionInfo |
|
97 |
ancestry _ MCWorkingAncestry new addAncestor: aVersionInfo |
|
98 |
! ! |
|
99 |
||
100 |
!MCWorkingCopy methodsFor:'migration'! |
|
101 |
||
102 |
updateInstVars |
|
103 |
ancestry ifNil: |
|
104 |
[ancestry _ MCWorkingAncestry new. |
|
105 |
versionInfo ifNotNil: |
|
106 |
[versionInfo ancestors do: [:ea | ancestry addAncestor: ea]. |
|
107 |
versionInfo _ nil]] |
|
108 |
! ! |
|
109 |
||
110 |
!MCWorkingCopy methodsFor:'operations'! |
|
111 |
||
112 |
adopt: aVersion |
|
113 |
ancestry addAncestor: aVersion info. |
|
114 |
self changed. |
|
115 |
! |
|
116 |
||
117 |
backportChangesTo: aVersionInfo |
|
917 | 118 |
| baseVersion fullPatch currentVersionInfo currentVersion newSnapshot newAncestry | |
119 |
currentVersionInfo := self currentVersionInfo. |
|
120 |
baseVersion := self repositoryGroup versionWithInfo: aVersionInfo. |
|
121 |
currentVersion := self repositoryGroup versionWithInfo: currentVersionInfo. |
|
122 |
fullPatch := currentVersion snapshot patchRelativeToBase: baseVersion snapshot. |
|
123 |
(MCChangeSelectionRequest new |
|
124 |
patch: fullPatch; |
|
125 |
label: 'Changes to Backport'; |
|
126 |
raiseSignal "signal" ) ifNotNilDo: |
|
127 |
[:partialPatch | |
|
128 |
newSnapshot := MCPatcher apply: partialPatch to: baseVersion snapshot. |
|
129 |
newAncestry := MCWorkingAncestry new |
|
130 |
addAncestor: aVersionInfo; |
|
131 |
addStepChild: currentVersionInfo; |
|
132 |
yourself. |
|
133 |
MCPackageLoader updatePackage: package withSnapshot: newSnapshot. |
|
134 |
ancestry := newAncestry. |
|
135 |
self modified: false; modified: true] |
|
84 | 136 |
! |
137 |
||
138 |
changesRelativeToRepository: aRepository |
|
139 |
| ancestorVersion ancestorSnapshot | |
|
140 |
ancestorVersion _ aRepository closestAncestorVersionFor: ancestry ifNone: []. |
|
141 |
ancestorSnapshot _ ancestorVersion ifNil: [MCSnapshot empty] ifNotNil: [ancestorVersion snapshot]. |
|
142 |
^ package snapshot patchRelativeToBase: ancestorSnapshot |
|
143 |
! |
|
144 |
||
145 |
loaded: aVersion |
|
146 |
ancestry _ MCWorkingAncestry new addAncestor: aVersion info. |
|
147 |
requiredPackages _ OrderedCollection withAll: (aVersion dependencies collect: [:ea | ea package]). |
|
148 |
self modified: false. |
|
149 |
self changed |
|
150 |
! |
|
151 |
||
152 |
merge: targetVersion |
|
153 |
| ancestorInfo merger ancestorSnapshot packageSnapshot | |
|
154 |
targetVersion dependencies do: [:ea | ea resolve merge]. |
|
155 |
ancestorInfo _ targetVersion info commonAncestorWith: ancestry. |
|
156 |
||
157 |
ancestorInfo = targetVersion info ifTrue: [^ MCNoChangesException signal]. |
|
158 |
||
159 |
packageSnapshot _ package snapshot. |
|
160 |
ancestorSnapshot _ ancestorInfo |
|
161 |
ifNotNil: [(self findSnapshotWithVersionInfo: ancestorInfo)] |
|
162 |
ifNil: [self notifyNoCommonAncestorWith: targetVersion. MCSnapshot empty]. |
|
163 |
||
164 |
(ancestry ancestors size = 1 |
|
165 |
and: [ancestry ancestors first = ancestorInfo] |
|
166 |
and: [(packageSnapshot patchRelativeToBase: ancestorSnapshot) isEmpty]) |
|
167 |
ifTrue: [^ targetVersion load]. |
|
168 |
||
169 |
merger _ MCThreeWayMerger |
|
170 |
base: packageSnapshot |
|
171 |
target: targetVersion snapshot |
|
172 |
ancestor: ancestorSnapshot. |
|
173 |
((MCMergeResolutionRequest new merger: merger) |
|
174 |
signal: 'Merging ', targetVersion info name) = true ifTrue: |
|
175 |
[merger loadWithNameLike: targetVersion info name. |
|
176 |
ancestry addAncestor: targetVersion info]. |
|
177 |
self changed |
|
178 |
! |
|
179 |
||
180 |
merged: aVersion |
|
181 |
ancestry addAncestor: aVersion info. |
|
182 |
self changed |
|
183 |
! |
|
184 |
||
185 |
newVersion |
|
186 |
^ (self requestVersionNameAndMessageWithSuggestion: self uniqueVersionName) ifNotNilDo: |
|
187 |
[:pair | |
|
188 |
self newVersionWithName: pair first message: pair last]. |
|
189 |
! |
|
190 |
||
191 |
newVersionWithName: nameString message: messageString |
|
192 |
| info deps | |
|
193 |
info _ ancestry infoWithName: nameString message: messageString. |
|
194 |
ancestry _ MCWorkingAncestry new addAncestor: info. |
|
195 |
self modified: true; modified: false. |
|
196 |
||
197 |
deps _ self requiredPackages collect: |
|
198 |
[:ea | |
|
199 |
MCVersionDependency |
|
200 |
package: ea |
|
201 |
info: ea workingCopy currentVersionInfo]. |
|
202 |
||
203 |
^ MCVersion |
|
204 |
package: package |
|
205 |
info: info |
|
206 |
snapshot: package snapshot |
|
207 |
dependencies: deps |
|
208 |
! |
|
209 |
||
210 |
notifyNoCommonAncestorWith: aVersion |
|
211 |
self notify: |
|
212 |
'Could not find a common ancestor between (', |
|
213 |
aVersion info name, |
|
214 |
') and (', |
|
215 |
ancestry ancestorString, '). |
|
216 |
Proceeding with this merge may cause spurious conflicts.' |
|
217 |
! |
|
218 |
||
219 |
unload |
|
220 |
MCPackageLoader unloadPackage: self package. |
|
221 |
self unregister. |
|
222 |
! ! |
|
223 |
||
224 |
!MCWorkingCopy methodsFor:'private'! |
|
225 |
||
226 |
findSnapshotWithVersionInfo: aVersionInfo |
|
227 |
^ aVersionInfo |
|
228 |
ifNil: [MCSnapshot empty] |
|
229 |
ifNotNil: [(self repositoryGroup versionWithInfo: aVersionInfo) snapshot] |
|
230 |
! |
|
231 |
||
232 |
initialize |
|
233 |
super initialize. |
|
234 |
ancestry _ MCWorkingAncestry new |
|
235 |
! |
|
236 |
||
237 |
nextVersionName |
|
881 | 238 |
^self nextVersionNameWithTemplate: '%(PACKAGE)-%(AUTHOR).%(REVISION_NUMBER)' |
239 |
||
240 |
"Modified: / 06-06-2013 / 20:02:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
241 |
! |
|
242 |
||
243 |
nextVersionNameWithTemplate: template |
|
244 |
"Return next version name based on given template. |
|
245 |
Following parameters are expanded: |
|
246 |
REVISION_NUMBER ... sequential version number (the higher, the newer, basically) |
|
247 |
PACKAGE ........... package name |
|
248 |
AUTHOR ............ author of the version |
|
249 |
" |
|
250 |
||
443 | 251 |
| branch oldName | |
252 |
ancestry ancestors isEmpty |
|
850
73e20681c8a0
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
799
diff
changeset
|
253 |
ifTrue: [counter ifNil: [counter := 0]. branch := package monticelloName asString copy replaceAll: $/ with: $_; replaceAll: $: with: $_] |
443 | 254 |
ifFalse: |
255 |
[oldName := ancestry ancestors first name. |
|
256 |
oldName last isDigit |
|
257 |
ifFalse: [branch := oldName] |
|
258 |
ifTrue: [branch := oldName copyUpToLast: $-]. |
|
259 |
counter ifNil: [ |
|
260 |
counter := (ancestry ancestors collect: [:each | |
|
261 |
each name last isDigit |
|
262 |
ifFalse: [0] |
|
263 |
ifTrue: [(each name copyAfterLast: $-) extractNumber]]) max]]. |
|
84 | 264 |
|
443 | 265 |
counter := counter + 1. |
881 | 266 |
^template expandPlaceholdersWith: |
267 |
(Dictionary new |
|
268 |
at: 'REVISION_NUMBER' put: counter; |
|
269 |
at: 'PACKAGE' put: branch; |
|
270 |
at: 'AUTHOR' put: ((OperatingSystem getFullUserNameFromID: OperatingSystem getUserID) reject:[:c|c isSeparator]); |
|
271 |
yourself) |
|
443 | 272 |
|
881 | 273 |
"Created: / 06-06-2013 / 20:02:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
84 | 274 |
! |
275 |
||
276 |
possiblyNewerVersions |
|
277 |
||
278 |
^Array streamContents: [:strm | |
|
279 |
self repositoryGroup repositories do: [:repo | |
|
280 |
strm nextPutAll: (self possiblyNewerVersionsIn: repo)]] |
|
281 |
! |
|
282 |
||
283 |
possiblyNewerVersionsIn: aRepository |
|
284 |
||
285 |
^aRepository possiblyNewerVersionsOfAnyOf: self ancestors |
|
286 |
! |
|
287 |
||
288 |
requestVersionNameAndMessageWithSuggestion: aString |
|
443 | 289 |
^ (MCVersionNameAndMessageRequest new suggestedName: aString) raiseRequest |
290 |
||
291 |
"Modified: / 23-08-2011 / 07:42:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
84 | 292 |
! |
293 |
||
294 |
uniqueVersionName |
|
295 |
|versionName| |
|
296 |
counter _ nil. |
|
297 |
[versionName _ self nextVersionName. |
|
298 |
self repositoryGroup includesVersionNamed: versionName] whileTrue. |
|
299 |
^ versionName |
|
300 |
! |
|
301 |
||
302 |
versionSeparator |
|
303 |
^ $_ |
|
304 |
! ! |
|
305 |
||
306 |
!MCWorkingCopy methodsFor:'repositories'! |
|
307 |
||
308 |
repositoryGroup |
|
309 |
^ repositoryGroup ifNil: [repositoryGroup _ MCRepositoryGroup new] |
|
310 |
! |
|
311 |
||
312 |
repositoryGroup: aRepositoryGroup |
|
313 |
repositoryGroup _ aRepositoryGroup |
|
314 |
! ! |
|
315 |
||
316 |
!MCWorkingCopy class methodsFor:'documentation'! |
|
317 |
||
318 |
version |
|
917 | 319 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCWorkingCopy.st,v 1.7 2014-02-25 13:39:03 cg Exp $' |
850
73e20681c8a0
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
799
diff
changeset
|
320 |
! |
73e20681c8a0
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
799
diff
changeset
|
321 |
|
73e20681c8a0
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
799
diff
changeset
|
322 |
version_CVS |
917 | 323 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCWorkingCopy.st,v 1.7 2014-02-25 13:39:03 cg Exp $' |
84 | 324 |
! ! |
325 |
||
799 | 326 |
|
84 | 327 |
MCWorkingCopy initialize! |