Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 3491:23cffef5d424
Split branchtags into two additional functions.
This makes it easier to override only parts of the cache saving process.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Mon, 23 Oct 2006 23:32:56 -0300 |
parents | 0e68608bd11d |
children | bd8339976504 |
comparison
equal
deleted
inserted
replaced
3489:c3345b0f2fcd | 3491:23cffef5d424 |
---|---|
293 if self.branchcache != None: | 293 if self.branchcache != None: |
294 return self.branchcache | 294 return self.branchcache |
295 | 295 |
296 self.branchcache = {} # avoid recursion in changectx | 296 self.branchcache = {} # avoid recursion in changectx |
297 | 297 |
298 partial, last, lrev = self._readbranchcache() | |
299 | |
300 tiprev = self.changelog.count() - 1 | |
301 if lrev != tiprev: | |
302 self._updatebranchcache(partial, lrev+1, tiprev+1) | |
303 self._writebranchcache(partial, self.changelog.tip(), tiprev) | |
304 | |
305 self.branchcache = partial | |
306 return self.branchcache | |
307 | |
308 def _readbranchcache(self): | |
309 partial = {} | |
298 try: | 310 try: |
299 f = self.opener("branches.cache") | 311 f = self.opener("branches.cache") |
300 last, lrev = f.readline().rstrip().split(" ", 1) | 312 last, lrev = f.readline().rstrip().split(" ", 1) |
301 last, lrev = bin(last), int(lrev) | 313 last, lrev = bin(last), int(lrev) |
302 if (lrev < self.changelog.count() and | 314 if (lrev < self.changelog.count() and |
303 self.changelog.node(lrev) == last): # sanity check | 315 self.changelog.node(lrev) == last): # sanity check |
304 for l in f: | 316 for l in f: |
305 node, label = l.rstrip().split(" ", 1) | 317 node, label = l.rstrip().split(" ", 1) |
306 self.branchcache[label] = bin(node) | 318 partial[label] = bin(node) |
307 else: # invalidate the cache | 319 else: # invalidate the cache |
308 last, lrev = nullid, -1 | 320 last, lrev = nullid, -1 |
309 f.close() | 321 f.close() |
310 except IOError: | 322 except IOError: |
311 last, lrev = nullid, -1 | 323 last, lrev = nullid, -1 |
312 | 324 return partial, last, lrev |
313 tip = self.changelog.count() - 1 | 325 |
314 if lrev != tip: | 326 def _writebranchcache(self, branches, tip, tiprev): |
315 for r in xrange(lrev + 1, tip + 1): | |
316 c = self.changectx(r) | |
317 b = c.branch() | |
318 if b: | |
319 self.branchcache[b] = c.node() | |
320 self._writebranchcache() | |
321 | |
322 return self.branchcache | |
323 | |
324 def _writebranchcache(self): | |
325 try: | 327 try: |
326 f = self.opener("branches.cache", "w") | 328 f = self.opener("branches.cache", "w") |
327 t = self.changelog.tip() | 329 f.write("%s %s\n" % (hex(tip), tiprev)) |
328 f.write("%s %s\n" % (hex(t), self.changelog.count() - 1)) | 330 for label, node in branches.iteritems(): |
329 for label, node in self.branchcache.iteritems(): | |
330 f.write("%s %s\n" % (hex(node), label)) | 331 f.write("%s %s\n" % (hex(node), label)) |
331 except IOError: | 332 except IOError: |
332 pass | 333 pass |
334 | |
335 def _updatebranchcache(self, partial, start, end): | |
336 for r in xrange(start, end): | |
337 c = self.changectx(r) | |
338 b = c.branch() | |
339 if b: | |
340 partial[b] = c.node() | |
333 | 341 |
334 def lookup(self, key): | 342 def lookup(self, key): |
335 if key == '.': | 343 if key == '.': |
336 key = self.dirstate.parents()[0] | 344 key = self.dirstate.parents()[0] |
337 if key == nullid: | 345 if key == nullid: |