1445
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
1282
|
13 |
"{ Package: 'stx:libbasic3' }"
|
|
14 |
|
|
15 |
"{ NameSpace: Packages }"
|
|
16 |
|
|
17 |
Object subclass:#VersionHistory
|
|
18 |
instanceVariableNames:'versions'
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Package-helpers'
|
|
22 |
!
|
|
23 |
|
|
24 |
VersionHistory comment:'I am a version history. A version history is a collection of VersionNumbers that together form a tree of versions. I enforce rules about how versions are added and removed from the history.
|
|
25 |
|
|
26 |
To add a new version to a VersionHistory based on an existing version:
|
|
27 |
|
|
28 |
VersionHistory startingAt1 addNewVersionBasedOn: ''1'' asVersion; yourself
|
|
29 |
|
|
30 |
If you add 2 new versions based on the same version, a branch will be started:
|
|
31 |
|
|
32 |
VersionHistory startingAt1
|
|
33 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
34 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
35 |
yourself
|
|
36 |
|
|
37 |
To remove a single version (note: only versions at the tip of a branch, or at the base of the trunk (if it has only one successor) can be individually removed):
|
|
38 |
|
|
39 |
VersionHistory startingAt1
|
|
40 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
41 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
42 |
remove: ''1.1'' asVersion;
|
|
43 |
yourself
|
|
44 |
|
|
45 |
To remove an entire branch:
|
|
46 |
|
|
47 |
VersionHistory startingAt1
|
|
48 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
49 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
50 |
addNewVersionBasedOn: ''1.1'' asVersion;
|
|
51 |
addNewVersionBasedOn: ''1.2'' asVersion;
|
|
52 |
removeBranch: ''1.1'' asVersion;
|
|
53 |
yourself
|
|
54 |
|
|
55 |
To remove a portion of the trunk:
|
|
56 |
|
|
57 |
VersionHistory startingAt1
|
|
58 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
59 |
addNewVersionBasedOn: ''2'' asVersion;
|
|
60 |
addNewVersionBasedOn: ''3'' asVersion;
|
|
61 |
addNewVersionBasedOn: ''3'' asVersion;
|
|
62 |
removeTrunk: ''2'' asVersion;
|
|
63 |
yourself
|
|
64 |
|
|
65 |
To get a string description of a version history:
|
|
66 |
|
|
67 |
VersionHistory startingAt1
|
|
68 |
addNewVersionBasedOn: ''1'' asVersion;
|
|
69 |
addNewVersionBasedOn: ''2'' asVersion;
|
|
70 |
addNewVersionBasedOn: ''3'' asVersion;
|
|
71 |
addNewVersionBasedOn: ''3'' asVersion;
|
|
72 |
treeString
|
|
73 |
|
|
74 |
Also, the following methods are useful for accessing the versions:
|
|
75 |
|
|
76 |
#firstVersion
|
|
77 |
#versionBefore:
|
|
78 |
#versionsAfter:
|
|
79 |
#mainLineStartingAt:
|
|
80 |
#allVersionsAfter:
|
|
81 |
#allVersionsBefore:
|
|
82 |
'
|
|
83 |
!
|
|
84 |
|
|
85 |
!VersionHistory class methodsFor:'documentation'!
|
|
86 |
|
1445
|
87 |
copyright
|
|
88 |
"
|
|
89 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
90 |
All Rights Reserved
|
|
91 |
|
|
92 |
This software is furnished under a license and may be used
|
|
93 |
only in accordance with the terms of that license and with the
|
|
94 |
inclusion of the above copyright notice. This software may not
|
|
95 |
be provided or otherwise made available to, or used by, any
|
|
96 |
other person. No title to or ownership of the software is
|
|
97 |
hereby transferred.
|
|
98 |
"
|
|
99 |
!
|
|
100 |
|
1282
|
101 |
documentation
|
|
102 |
"
|
|
103 |
Taken from KomPackaging in squeak.
|
|
104 |
|
|
105 |
[author:]
|
|
106 |
|
|
107 |
[instance variables:]
|
|
108 |
|
|
109 |
[class variables:]
|
|
110 |
|
|
111 |
[see also:]
|
|
112 |
|
|
113 |
"
|
|
114 |
!
|
|
115 |
|
|
116 |
examples
|
|
117 |
"
|
|
118 |
|
|
119 |
more examples to be added:
|
|
120 |
[exBegin]
|
|
121 |
... add code fragment for
|
|
122 |
... executable example here ...
|
|
123 |
[exEnd]
|
|
124 |
"
|
|
125 |
!
|
|
126 |
|
|
127 |
history
|
|
128 |
"Created: / 20.5.2003 / 08:28:06 / james"
|
|
129 |
! !
|
|
130 |
|
|
131 |
!VersionHistory class methodsFor:'as yet unclassified'!
|
|
132 |
|
|
133 |
fromCollection: aCollection
|
|
134 |
"Note: this does not validate the continuity of version
|
|
135 |
numbers passed in aCollection...need to add continuity
|
|
136 |
checks in the future"
|
|
137 |
|
|
138 |
^self new
|
|
139 |
initializeVersionsFrom: aCollection;
|
|
140 |
yourself
|
|
141 |
!
|
|
142 |
|
|
143 |
startingAt1
|
|
144 |
|
|
145 |
^self startingAt: '1' asVersion
|
|
146 |
!
|
|
147 |
|
|
148 |
startingAt: aVersion
|
|
149 |
|
|
150 |
^self new
|
|
151 |
initializeVersionsAt: aVersion;
|
|
152 |
yourself
|
|
153 |
! !
|
|
154 |
|
|
155 |
!VersionHistory methodsFor:'accessing'!
|
|
156 |
|
|
157 |
allVersionsAfter: aVersion
|
|
158 |
"Answer all the versions based on aVersion."
|
|
159 |
|
|
160 |
| answer |
|
|
161 |
answer := Set new.
|
|
162 |
versions do: [ :ea |
|
|
163 |
((ea inSameBranchAs: aVersion) and:
|
|
164 |
[ea > aVersion]) ifTrue: [answer add: ea]].
|
|
165 |
^answer
|
|
166 |
!
|
|
167 |
|
|
168 |
allVersionsBefore: aVersion
|
|
169 |
"Answer all versions that came before aVersion"
|
|
170 |
|
|
171 |
| answer |
|
|
172 |
answer := Set new.
|
|
173 |
versions do: [ :ea |
|
|
174 |
((ea inSameBranchAs: aVersion) and:
|
|
175 |
[ea < aVersion]) ifTrue: [answer add: ea]].
|
|
176 |
^answer
|
|
177 |
!
|
|
178 |
|
|
179 |
firstVersion
|
|
180 |
"Answer the first version in the entire version history"
|
|
181 |
|
|
182 |
^versions inject: versions anyOne into: [ :x :ea |
|
|
183 |
(x inSameBranchAs: ea)
|
|
184 |
ifTrue: [(x < ea) ifTrue: [x] ifFalse: [ea]]
|
|
185 |
ifFalse: [ea]]
|
|
186 |
!
|
|
187 |
|
|
188 |
latestMainLineVersion
|
|
189 |
|
|
190 |
^(self mainLineStartingAt: self firstVersion) last
|
|
191 |
!
|
|
192 |
|
|
193 |
mainLineStartingAt: aVersion
|
|
194 |
"Answer all versions based on aVersion that are not branches (they have
|
|
195 |
the same number of digits with the same values, except the last value is
|
|
196 |
greater than the last value of aVersion)."
|
|
197 |
|
|
198 |
| answer tmp |
|
|
199 |
answer := OrderedCollection new.
|
|
200 |
tmp := aVersion.
|
|
201 |
[versions includes: tmp]
|
|
202 |
whileTrue:
|
|
203 |
[answer add: tmp.
|
|
204 |
tmp := tmp next].
|
|
205 |
^answer
|
|
206 |
!
|
|
207 |
|
|
208 |
versionBefore: aVersion
|
|
209 |
|
|
210 |
"Answer the version immediately preceeding aVersion."
|
|
211 |
|
|
212 |
| tmp |
|
|
213 |
(aVersion > '1' asVersion) ifFalse: [^nil].
|
|
214 |
(versions includes: (tmp := aVersion previous)) ifFalse: [^nil].
|
|
215 |
^tmp
|
|
216 |
!
|
|
217 |
|
|
218 |
versionsAfter: aVersion
|
|
219 |
"Answer all the versions immediately following aVersion."
|
|
220 |
|
|
221 |
| answer tmp |
|
|
222 |
answer := Set new.
|
|
223 |
tmp := aVersion next.
|
|
224 |
(versions includes: aVersion next) ifTrue: [answer add: tmp].
|
|
225 |
|
|
226 |
tmp := aVersion.
|
|
227 |
[versions includes: (tmp := tmp branchNext)] whileTrue:
|
|
228 |
[answer add: tmp].
|
|
229 |
^answer
|
|
230 |
! !
|
|
231 |
|
|
232 |
!VersionHistory methodsFor:'adding'!
|
|
233 |
|
|
234 |
addNewVersionBasedOn: aVersion
|
|
235 |
|
|
236 |
| tmp |
|
|
237 |
(versions includes: aVersion) ifFalse: [^self error: 'Version is not in this history'].
|
|
238 |
|
|
239 |
tmp := aVersion next.
|
|
240 |
(versions includes: tmp) ifFalse:
|
|
241 |
[versions add: tmp.
|
|
242 |
^tmp].
|
|
243 |
|
|
244 |
tmp := aVersion.
|
|
245 |
[versions includes: (tmp := tmp branchNext)] whileTrue.
|
|
246 |
versions add: tmp.
|
|
247 |
^tmp
|
|
248 |
|
|
249 |
! !
|
|
250 |
|
|
251 |
!VersionHistory methodsFor:'initialization'!
|
|
252 |
|
|
253 |
initializeVersionsAt: aVersion
|
|
254 |
|
|
255 |
versions := Set new.
|
|
256 |
versions add: aVersion.
|
|
257 |
!
|
|
258 |
|
|
259 |
initializeVersionsFrom: aCollection
|
|
260 |
|
|
261 |
versions := Set new.
|
|
262 |
aCollection do: [ :ea | versions add: ea ].
|
|
263 |
! !
|
|
264 |
|
|
265 |
!VersionHistory methodsFor:'printing'!
|
|
266 |
|
|
267 |
treeString
|
|
268 |
"Answer a string that show the entire version history with
|
|
269 |
each branch starting on a new line"
|
|
270 |
|
|
271 |
^self treeStringStartingAt: self firstVersion
|
|
272 |
!
|
|
273 |
|
|
274 |
treeStringOn: strm startingAt: aVersion
|
|
275 |
|
|
276 |
| tmp |
|
|
277 |
tmp := self mainLineStartingAt: aVersion.
|
|
278 |
tmp do: [ :ea | ea versionStringOn: strm. strm space; space ].
|
|
279 |
strm cr.
|
|
280 |
tmp do:
|
|
281 |
[ :ea |
|
|
282 |
(versions includes: ea branchNext)
|
|
283 |
ifTrue: [self treeStringOn: strm startingAt: ea branchNext]].
|
|
284 |
!
|
|
285 |
|
|
286 |
treeStringStartingAt: aVersion
|
|
287 |
|
|
288 |
| strm |
|
|
289 |
strm := WriteStream on: ''.
|
|
290 |
self treeStringOn: strm startingAt: aVersion.
|
|
291 |
^strm contents
|
|
292 |
! !
|
|
293 |
|
|
294 |
!VersionHistory methodsFor:'removing'!
|
|
295 |
|
|
296 |
remove: aVersion
|
|
297 |
"Remove aVersion from this version history."
|
|
298 |
|
|
299 |
^self remove: aVersion ifAbsent: [self error: 'version not found'].
|
|
300 |
!
|
|
301 |
|
|
302 |
remove: aVersion ifAbsent: aBlock
|
|
303 |
"Remove aVersion from this version history."
|
|
304 |
|
|
305 |
(versions includes: aVersion) ifFalse: [^aBlock value].
|
|
306 |
|
|
307 |
(self canRemove: aVersion) ifFalse:
|
|
308 |
[^self error: 'Only versions at the beginning or end with no more than one follower may be removed'].
|
|
309 |
|
|
310 |
versions remove: aVersion.
|
|
311 |
!
|
|
312 |
|
|
313 |
removeBranch: aVersion
|
|
314 |
"Remove aVersion and all of it's successors, providing that
|
|
315 |
aVersion is not the first version."
|
|
316 |
|
|
317 |
(self versionBefore: aVersion)
|
|
318 |
ifNil: [^self error: 'version is the first version in the history'].
|
|
319 |
|
|
320 |
versions removeAll: (self allVersionsAfter: aVersion).
|
|
321 |
versions remove: aVersion.
|
|
322 |
!
|
|
323 |
|
|
324 |
removeTrunk: aVersion
|
|
325 |
"Remove aVersion and all of it's predecessors, providing there
|
|
326 |
are no other branches stemming from the trunk. Note, a trunk is defined
|
|
327 |
as all versions, starting with the first version, that have only one successor."
|
|
328 |
|
|
329 |
| tmp |
|
|
330 |
(self versionsAfter: aVersion) size > 1
|
|
331 |
ifTrue: [^self error: 'version is at a fork'].
|
|
332 |
|
|
333 |
tmp := self allVersionsBefore: aVersion.
|
|
334 |
(tmp detect: [ :ea | (self versionsAfter: ea) size > 1 ] ifNone: [nil])
|
|
335 |
ifNotNil: [^self error: 'not a trunk, other branches detected'].
|
|
336 |
|
|
337 |
versions removeAll: tmp.
|
|
338 |
versions remove: aVersion.
|
|
339 |
! !
|
|
340 |
|
|
341 |
!VersionHistory methodsFor:'testing'!
|
|
342 |
|
|
343 |
canRemove: aVersion
|
|
344 |
|
|
345 |
| hasPriors followers |
|
|
346 |
(versions includes: aVersion) ifFalse: [^false].
|
|
347 |
hasPriors := (self versionBefore: aVersion) notNil.
|
|
348 |
followers := self versionsAfter: aVersion.
|
|
349 |
|
|
350 |
"Don't allow versions in the middle to be extracted"
|
|
351 |
(hasPriors and: [followers size > 0]) ifTrue: [^false].
|
|
352 |
|
|
353 |
"Don't allow versions with more than one follower to be extracted"
|
|
354 |
(hasPriors not and: [followers size > 1]) ifTrue: [^false].
|
|
355 |
^true
|
|
356 |
|
|
357 |
!
|
|
358 |
|
|
359 |
includesVersion: aVersion
|
|
360 |
|
|
361 |
^versions includes: aVersion
|
|
362 |
! !
|
|
363 |
|
|
364 |
!VersionHistory class methodsFor:'documentation'!
|
|
365 |
|
|
366 |
version
|
1445
|
367 |
^ '$Header: /cvs/stx/stx/libbasic3/packages/VersionHistory.st,v 1.2 2006-01-10 09:31:46 cg Exp $'
|
1282
|
368 |
! !
|