comparison mercurial/localrepo.py @ 6121:7336aeff1a1d

automatically update the branch cache when tip changes
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 15 Feb 2008 16:06:36 -0200
parents f89878df40fe
children 516d8ffede7c
comparison
equal deleted inserted replaced
6120:f89878df40fe 6121:7336aeff1a1d
93 93
94 self.tagscache = None 94 self.tagscache = None
95 self._tagstypecache = None 95 self._tagstypecache = None
96 self.branchcache = None 96 self.branchcache = None
97 self._ubranchcache = None # UTF-8 version of branchcache 97 self._ubranchcache = None # UTF-8 version of branchcache
98 self._branchcachetip = None
98 self.nodetagscache = None 99 self.nodetagscache = None
99 self.filterpats = {} 100 self.filterpats = {}
100 self._datafilters = {} 101 self._datafilters = {}
101 self._transref = self._lockref = self._wlockref = None 102 self._transref = self._lockref = self._wlockref = None
102 103
352 self._writebranchcache(partial, self.changelog.tip(), tiprev) 353 self._writebranchcache(partial, self.changelog.tip(), tiprev)
353 354
354 return partial 355 return partial
355 356
356 def branchtags(self): 357 def branchtags(self):
357 if self.branchcache is not None: 358 tip = self.changelog.tip()
359 if self.branchcache is not None and self._branchcachetip == tip:
358 return self.branchcache 360 return self.branchcache
359 361
360 self.branchcache = {} # avoid recursion in changectx 362 oldtip = self._branchcachetip
361 partial, last, lrev = self._readbranchcache() 363 self._branchcachetip = tip
364 if self.branchcache is None:
365 self.branchcache = {} # avoid recursion in changectx
366 else:
367 self.branchcache.clear() # keep using the same dict
368 if oldtip is None or oldtip not in self.changelog.nodemap:
369 partial, last, lrev = self._readbranchcache()
370 else:
371 lrev = self.changelog.rev(oldtip)
372 partial = self._ubranchcache
373
362 self._branchtags(partial, lrev) 374 self._branchtags(partial, lrev)
363 375
364 # the branch cache is stored on disk as UTF-8, but in the local 376 # the branch cache is stored on disk as UTF-8, but in the local
365 # charset internally 377 # charset internally
366 for k, v in partial.items(): 378 for k, v in partial.items():
617 self.tagscache = None 629 self.tagscache = None
618 self._tagstypecache = None 630 self._tagstypecache = None
619 self.nodetagscache = None 631 self.nodetagscache = None
620 self.branchcache = None 632 self.branchcache = None
621 self._ubranchcache = None 633 self._ubranchcache = None
634 self._branchcachetip = None
622 635
623 def _lock(self, lockname, wait, releasefn, acquirefn, desc): 636 def _lock(self, lockname, wait, releasefn, acquirefn, desc):
624 try: 637 try:
625 l = lock.lock(lockname, 0, releasefn, desc=desc) 638 l = lock.lock(lockname, 0, releasefn, desc=desc)
626 except lock.LockHeld, inst: 639 except lock.LockHeld, inst:
883 user, date, extra) 896 user, date, extra)
884 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, 897 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
885 parent2=xp2) 898 parent2=xp2)
886 tr.close() 899 tr.close()
887 900
888 if self.branchcache and "branch" in extra: 901 if self.branchcache:
889 self.branchcache[util.tolocal(extra["branch"])] = n 902 self.branchtags()
890 903
891 if use_dirstate or update_dirstate: 904 if use_dirstate or update_dirstate:
892 self.dirstate.setparents(n) 905 self.dirstate.setparents(n)
893 if use_dirstate: 906 if use_dirstate:
894 for f in removed: 907 for f in removed:
2006 del tr 2019 del tr
2007 2020
2008 if changesets > 0: 2021 if changesets > 0:
2009 # forcefully update the on-disk branch cache 2022 # forcefully update the on-disk branch cache
2010 self.ui.debug(_("updating the branch cache\n")) 2023 self.ui.debug(_("updating the branch cache\n"))
2011 self.branchcache = None
2012 self.branchtags() 2024 self.branchtags()
2013 self.hook("changegroup", node=hex(self.changelog.node(cor+1)), 2025 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
2014 source=srctype, url=url) 2026 source=srctype, url=url)
2015 2027
2016 for i in xrange(cor + 1, cnr + 1): 2028 for i in xrange(cor + 1, cnr + 1):