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