Mercurial > public > mercurial-scm > hg-stable
diff mercurial/branchmap.py @ 29615:a2a380e2750f stable
rbc: fix superfluous rebuilding from scratch - don't abuse self._rbcnamescount
The code used self._rbcnamescount as if it was the length of self._names ...
but actually it is just the number of good entries on disk. This caused the
cache to be populated inefficiently. In some cases very inefficiently.
Instead of checking the length before lookup, just try a lookup in self._names
- that is also in most cases faster.
Comments and debug messages are tweaked to help understanding the issue
and the fix.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 18 Jul 2016 22:25:09 +0200 |
parents | db0095c83344 |
children | 9f3c49ee4486 |
line wrap: on
line diff
--- a/mercurial/branchmap.py Mon Jul 18 22:23:44 2016 +0200 +++ b/mercurial/branchmap.py Mon Jul 18 22:25:09 2016 +0200 @@ -358,7 +358,7 @@ self._repo = repo self._names = [] # branch names in local encoding with static index self._rbcrevs = array('c') # structs of type _rbcrecfmt - self._rbcsnameslen = 0 + self._rbcsnameslen = 0 # length of names read at _rbcsnameslen try: bndata = repo.vfs.read(_rbcnames) self._rbcsnameslen = len(bndata) # for verification before writing @@ -380,7 +380,8 @@ len(repo.changelog)) if self._rbcrevslen == 0: self._names = [] - self._rbcnamescount = len(self._names) # number of good names on disk + self._rbcnamescount = len(self._names) # number of names read at + # _rbcsnameslen self._namesreverse = dict((b, r) for r, b in enumerate(self._names)) def _clear(self): @@ -416,13 +417,17 @@ if cachenode == '\0\0\0\0': pass elif cachenode == reponode: - if branchidx < self._rbcnamescount: + try: return self._names[branchidx], close - # referenced branch doesn't exist - rebuild is expensive but needed - self._repo.ui.debug("rebuilding corrupted revision branch cache\n") - self._clear() + except IndexError: + # recover from invalid reference to unknown branch + self._repo.ui.debug("referenced branch names not found" + " - rebuilding revision branch cache from scratch\n") + self._clear() else: # rev/node map has changed, invalidate the cache from here up + self._repo.ui.debug("history modification detected - truncating " + "revision branch cache to revision %s\n" % rev) truncate = rbcrevidx + _rbcrecsize del self._rbcrevs[truncate:] self._rbcrevslen = min(self._rbcrevslen, truncate)