# HG changeset patch # User Mads Kiilerich # Date 1423187530 -3600 # Node ID 5b4ed033390bf6e2879c8f5c28c84e1ee3b87231 # Parent d414c28db84d592f9f27c683414bc02d18a5e344 revisionbranchcache: fall back to slow path if starting readonly (issue4531) Transitioning to Mercurial versions with revision branch cache could be slow as long as all operations were readonly (revset queries) and the cache would be populated but not written back. Instead, fall back to using the consistently slow path when readonly and the cache doesn't exist yet. That avoids the overhead of populating the cache without writing it back. If not readonly, it will still populate all missing entries initially. That avoids repeated writing of the cache file with small updates, and it also makes sure a fully populated cache available for the readonly operations. diff -r d414c28db84d -r 5b4ed033390b mercurial/branchmap.py --- a/mercurial/branchmap.py Thu Feb 26 06:03:39 2015 +0900 +++ b/mercurial/branchmap.py Fri Feb 06 02:52:10 2015 +0100 @@ -330,7 +330,7 @@ and will grow with it but be 1/8th of its size. """ - def __init__(self, repo): + def __init__(self, repo, readonly=True): assert repo.filtername is None self._names = [] # branch names in local encoding with static index self._rbcrevs = array('c') # structs of type _rbcrecfmt @@ -342,6 +342,10 @@ except (IOError, OSError), inst: repo.ui.debug("couldn't read revision branch cache names: %s\n" % inst) + if readonly: + # don't try to use cache - fall back to the slow path + self.branchinfo = self._branchinfo + if self._names: try: data = repo.vfs.read(_rbcrevs) diff -r d414c28db84d -r 5b4ed033390b mercurial/revset.py --- a/mercurial/revset.py Thu Feb 26 06:03:39 2015 +0900 +++ b/mercurial/revset.py Fri Feb 06 02:52:10 2015 +0100 @@ -527,7 +527,7 @@ import branchmap urepo = repo.unfiltered() ucl = urepo.changelog - getbi = branchmap.revbranchcache(urepo).branchinfo + getbi = branchmap.revbranchcache(urepo, readonly=True).branchinfo try: b = getstring(x, '')