110
|
1 |
"{ Package: 'stx:goodies/monticello' }"
|
|
2 |
|
971
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
110
|
5 |
MCRepository subclass:#MCFileBasedRepository
|
|
6 |
instanceVariableNames:'cache allFileNames'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
627
|
9 |
category:'SCM-Monticello-Repositories'
|
110
|
10 |
!
|
|
11 |
|
|
12 |
|
903
|
13 |
!MCFileBasedRepository class methodsFor:'misc'!
|
110
|
14 |
|
|
15 |
flushAllCaches
|
|
16 |
self allSubInstancesDo: [:ea | ea flushCache]
|
|
17 |
! !
|
|
18 |
|
|
19 |
!MCFileBasedRepository methodsFor:'as yet unclassified'!
|
|
20 |
|
|
21 |
cache
|
235
|
22 |
^ cache ifNil: [cache := Dictionary new]
|
110
|
23 |
!
|
|
24 |
|
|
25 |
cacheAllFileNamesDuring: aBlock
|
235
|
26 |
allFileNames := self allFileNames.
|
|
27 |
^ aBlock ensure: [allFileNames := nil]
|
110
|
28 |
!
|
|
29 |
|
|
30 |
cachedFileNames
|
|
31 |
^cache == nil
|
|
32 |
ifTrue: [#()]
|
|
33 |
ifFalse: [cache keys]
|
|
34 |
!
|
|
35 |
|
|
36 |
canReadFileNamed: aString
|
|
37 |
| reader |
|
235
|
38 |
reader := MCVersionReader readerClassForFileNamed: aString.
|
110
|
39 |
^ reader notNil
|
|
40 |
!
|
|
41 |
|
|
42 |
filterFileNames: aCollection forVersionNamed: aString
|
|
43 |
^ aCollection select: [:ea | (self versionNameFromFileName: ea) = aString]
|
|
44 |
!
|
|
45 |
|
|
46 |
flushCache
|
235
|
47 |
cache := nil
|
110
|
48 |
!
|
|
49 |
|
|
50 |
loadVersionFromFileNamed: aString
|
|
51 |
^ self versionReaderForFileNamed: aString do: [:r | r version]
|
|
52 |
!
|
|
53 |
|
|
54 |
loadVersionInfoFromFileNamed: aString
|
|
55 |
^ self versionReaderForFileNamed: aString do: [:r | r info]
|
|
56 |
|
|
57 |
!
|
|
58 |
|
|
59 |
maxCacheSize
|
|
60 |
^ 8
|
|
61 |
!
|
|
62 |
|
235
|
63 |
notifyList
|
|
64 |
(self allFileNames includes: 'notify') ifFalse: [^ #()].
|
|
65 |
^ self readStreamForFileNamed: 'notify' do:
|
|
66 |
[:s |
|
|
67 |
s upToEnd asStringWithSqueakLineEndings findTokens: (String with: Character cr)]
|
|
68 |
|
|
69 |
"Modified: / 12-09-2010 / 16:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
110
|
70 |
!
|
|
71 |
|
235
|
72 |
packageNameFromFileName: aString
|
|
73 |
^ (aString copyUpToLast: $-)
|
|
74 |
|
|
75 |
"Created: / 16-09-2010 / 16:10:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
76 |
"Modified: / 16-09-2010 / 18:45:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
110
|
77 |
!
|
|
78 |
|
942
|
79 |
readStreamForFileNamed: aString do: aBlock
|
|
80 |
self subclassResponsibility
|
|
81 |
!
|
|
82 |
|
903
|
83 |
resizeCache: aDictionary
|
|
84 |
[aDictionary size <= self maxCacheSize] whileFalse:
|
|
85 |
[aDictionary removeKey: aDictionary keys asArray atRandom]
|
|
86 |
|
|
87 |
"Modified: / 15-09-2010 / 13:15:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
88 |
!
|
|
89 |
|
|
90 |
versionReaderForFileNamed: aString do: aBlock
|
|
91 |
^ self
|
|
92 |
readStreamForFileNamed: aString
|
|
93 |
do: [:s | | class |
|
|
94 |
(class := MCVersionReader readerClassForFileNamed: aString) ifNotNil:
|
|
95 |
[ aBlock value: (class on: s fileName: aString)]]
|
|
96 |
|
|
97 |
"Modified: / 12-09-2010 / 19:40:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
98 |
!
|
|
99 |
|
|
100 |
versionWithInfo: aVersionInfo ifAbsent: errorBlock
|
|
101 |
| version |
|
|
102 |
(self allFileNamesForVersionNamed: aVersionInfo name) do:
|
|
103 |
[:fileName |
|
|
104 |
version := self versionFromFileNamed: fileName.
|
|
105 |
version info = aVersionInfo ifTrue: [^ version]].
|
|
106 |
^ errorBlock value
|
|
107 |
!
|
|
108 |
|
|
109 |
writeStreamForFileNamed: aString do: aBlock
|
|
110 |
^ self writeStreamForFileNamed: aString replace: false do: aBlock
|
|
111 |
! !
|
|
112 |
|
|
113 |
!MCFileBasedRepository methodsFor:'printing & storing'!
|
|
114 |
|
|
115 |
basicStoreVersion: aVersion
|
|
116 |
self
|
|
117 |
writeStreamForFileNamed: aVersion fileName
|
|
118 |
do: [:s | aVersion fileOutOn: s].
|
|
119 |
aVersion isCacheable ifTrue: [
|
|
120 |
cache ifNil: [cache := Dictionary new].
|
|
121 |
cache at: aVersion fileName put: aVersion].
|
|
122 |
|
|
123 |
! !
|
|
124 |
|
|
125 |
!MCFileBasedRepository methodsFor:'queries'!
|
|
126 |
|
|
127 |
allFileNames
|
|
128 |
self subclassResponsibility
|
|
129 |
!
|
|
130 |
|
|
131 |
allFileNamesForVersionNamed: aString
|
|
132 |
^ self filterFileNames: self readableFileNames forVersionNamed: aString
|
|
133 |
!
|
|
134 |
|
|
135 |
allFileNamesOrCache
|
|
136 |
^ allFileNames ifNil: [self allFileNames]
|
|
137 |
!
|
|
138 |
|
|
139 |
allPackageNames
|
|
140 |
^ (self readableFileNames collect: [:ea | self packageNameFromFileName: ea])
|
|
141 |
asSet asOrderedCollection
|
|
142 |
|
|
143 |
"Created: / 16-09-2010 / 16:10:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
144 |
"Modified: / 16-09-2010 / 18:44:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
145 |
!
|
|
146 |
|
|
147 |
allVersionNames
|
|
148 |
^ self readableFileNames collect: [:ea | self versionNameFromFileName: ea]
|
|
149 |
!
|
|
150 |
|
|
151 |
closestAncestorVersionFor: anAncestry ifNone: errorBlock
|
|
152 |
^ self cacheAllFileNamesDuring:
|
|
153 |
[super closestAncestorVersionFor: anAncestry ifNone: errorBlock]
|
|
154 |
!
|
|
155 |
|
|
156 |
includesVersionNamed: aString
|
|
157 |
^ self allVersionNames includes: aString
|
|
158 |
!
|
|
159 |
|
110
|
160 |
possiblyNewerVersionsOfAnyOf: someVersions
|
971
|
161 |
| pkgs |
|
|
162 |
pkgs := Dictionary new.
|
110
|
163 |
|
971
|
164 |
someVersions do: [:aVersionInfo |
|
|
165 |
pkgs at: (aVersionInfo name copyUpToLast: $-)
|
|
166 |
put: (aVersionInfo name copyAfterLast: $.) asNumber].
|
110
|
167 |
|
971
|
168 |
^[
|
|
169 |
self allVersionNames select: [:each |
|
|
170 |
(pkgs at: (each copyUpToLast: $-) ifPresent: [:verNumber |
|
|
171 |
verNumber < (each copyAfterLast: $.) asNumber
|
|
172 |
or: [verNumber = (each copyAfterLast: $.) asNumber
|
|
173 |
and: [someVersions noneSatisfy: [:v | v name = each]]]]) == true]
|
|
174 |
] on: Error do: [:ex |
|
|
175 |
ex return: #()
|
|
176 |
]
|
110
|
177 |
!
|
|
178 |
|
|
179 |
readableFileNames
|
|
180 |
| all cached new |
|
|
181 |
all := self allFileNamesOrCache. "from repository"
|
|
182 |
cached := self cachedFileNames. "in memory"
|
|
183 |
new := all difference: cached.
|
|
184 |
^ (cached asArray, new)
|
|
185 |
select: [:ea | self canReadFileNamed: ea]
|
|
186 |
!
|
|
187 |
|
|
188 |
versionFromFileNamed: aString
|
|
189 |
| v |
|
|
190 |
v := self cache at: aString ifAbsent: [self loadVersionFromFileNamed: aString].
|
|
191 |
self resizeCache: cache.
|
|
192 |
(v notNil and: [v isCacheable]) ifTrue: [cache at: aString put: v].
|
|
193 |
^ v
|
|
194 |
!
|
|
195 |
|
|
196 |
versionInfoFromFileNamed: aString
|
|
197 |
self cache at: aString ifPresent: [:v | ^ v info].
|
|
198 |
^ self loadVersionInfoFromFileNamed: aString
|
|
199 |
!
|
|
200 |
|
|
201 |
versionNameFromFileName: aString
|
|
202 |
^ (aString copyUpToLast: $.) copyUpTo: $(
|
|
203 |
! !
|
|
204 |
|
|
205 |
!MCFileBasedRepository class methodsFor:'documentation'!
|
|
206 |
|
|
207 |
version
|
971
|
208 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCFileBasedRepository.st,v 1.7 2015-02-09 13:57:21 cg Exp $'
|
235
|
209 |
!
|
|
210 |
|
|
211 |
version_CVS
|
971
|
212 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCFileBasedRepository.st,v 1.7 2015-02-09 13:57:21 cg Exp $'
|
235
|
213 |
!
|
|
214 |
|
|
215 |
version_SVN
|
971
|
216 |
^ '$Id: MCFileBasedRepository.st,v 1.7 2015-02-09 13:57:21 cg Exp $'
|
110
|
217 |
! !
|
903
|
218 |
|