##// END OF EJS Templates
obsolete: move obsolete markers read/write logic to obsstore object...
Pierre-Yves David -
r17124:f1b7683f default
parent child Browse files
Show More
@@ -193,10 +193,7 b' class localrepository(repo.repository):'
193
193
194 @storecache('obsstore')
194 @storecache('obsstore')
195 def obsstore(self):
195 def obsstore(self):
196 store = obsolete.obsstore()
196 store = obsolete.obsstore(self.sopener)
197 data = self.sopener.tryread('obsstore')
198 if data:
199 store.loadmarkers(data)
200 return store
197 return store
201
198
202 @storecache('00changelog.i')
199 @storecache('00changelog.i')
@@ -990,16 +987,8 b' class localrepository(repo.repository):'
990 self.store.write()
987 self.store.write()
991 if '_phasecache' in vars(self):
988 if '_phasecache' in vars(self):
992 self._phasecache.write()
989 self._phasecache.write()
993 if 'obsstore' in vars(self) and self.obsstore._new:
990 if 'obsstore' in vars(self):
994 # XXX: transaction logic should be used here. But for
991 self.obsstore.flushmarkers()
995 # now rewriting the whole file is good enough.
996 f = self.sopener('obsstore', 'wb', atomictemp=True)
997 try:
998 self.obsstore.flushmarkers(f)
999 f.close()
1000 except: # re-raises
1001 f.discard()
1002 raise
1003 for k, ce in self._filecache.items():
992 for k, ce in self._filecache.items():
1004 if k == 'dirstate':
993 if k == 'dirstate':
1005 continue
994 continue
@@ -156,12 +156,17 b' class obsstore(object):'
156 - successors: new -> set(old)
156 - successors: new -> set(old)
157 """
157 """
158
158
159 def __init__(self):
159 def __init__(self, sopener):
160 self._all = []
160 self._all = []
161 # new markers to serialize
161 # new markers to serialize
162 self._new = []
162 self._new = []
163 self.precursors = {}
163 self.precursors = {}
164 self.successors = {}
164 self.successors = {}
165 self.sopener = sopener
166 data = sopener.tryread('obsstore')
167 if data:
168 for marker in _readmarkers(data):
169 self._load(marker)
165
170
166 def __iter__(self):
171 def __iter__(self):
167 return iter(self._all)
172 return iter(self._all)
@@ -193,11 +198,6 b' class obsstore(object):'
193 self._new.append(marker)
198 self._new.append(marker)
194 self._load(marker)
199 self._load(marker)
195
200
196 def loadmarkers(self, data):
197 """Load all markers in data, mark them as known."""
198 for marker in _readmarkers(data):
199 self._load(marker)
200
201 def mergemarkers(self, data):
201 def mergemarkers(self, data):
202 other = set(_readmarkers(data))
202 other = set(_readmarkers(data))
203 local = set(self._all)
203 local = set(self._all)
@@ -205,12 +205,21 b' class obsstore(object):'
205 for marker in new:
205 for marker in new:
206 self.add(marker)
206 self.add(marker)
207
207
208 def flushmarkers(self, stream):
208 def flushmarkers(self):
209 """Write all markers to a stream
209 """Write all markers on disk
210
210
211 After this operation, "new" markers are considered "known"."""
211 After this operation, "new" markers are considered "known"."""
212 self._writemarkers(stream)
212 if self._new:
213 self._new[:] = []
213 # XXX: transaction logic should be used here. But for
214 # now rewriting the whole file is good enough.
215 f = self.sopener('obsstore', 'wb', atomictemp=True)
216 try:
217 self._writemarkers(f)
218 f.close()
219 self._new[:] = []
220 except: # re-raises
221 f.discard()
222 raise
214
223
215 def _load(self, marker):
224 def _load(self, marker):
216 self._all.append(marker)
225 self._all.append(marker)
General Comments 0
You need to be logged in to leave comments. Login now