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