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