Patchwork [10,of,10] branchmap: extract updatebranchcache from repo

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 19, 2012, 1:53 p.m.
Message ID <760a35f81d363c74dac9.1355925206@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/198/
State Superseded, archived
Commit f8a13f061a8a4a278c7029c2cac7417dbcb08808
Headers show

Comments

Pierre-Yves David - Dec. 19, 2012, 1:53 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1355850154 -3600
# Node ID 760a35f81d363c74dac9500c907f2dacb19a6d9d
# Parent  1c56e4b62ca025e169576277d6719f9de2e4cb08
branchmap: extract updatebranchcache from repo
Kevin Bullock - Dec. 20, 2012, 4:38 a.m.
On 19 Dec 2012, at 7:53 AM, pierre-yves.david at logilab.fr wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at logilab.fr>
> # Date 1355850154 -3600
> # Node ID 760a35f81d363c74dac9500c907f2dacb19a6d9d
> # Parent  1c56e4b62ca025e169576277d6719f9de2e4cb08
> branchmap: extract updatebranchcache from repo

[...]

> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -644,49 +644,19 @@ class localrepository(object):
>         """
>         cl = self.changelog
>         return cl.rev(cl.tip())
> 
>     @unfilteredmethod # Until we get a smarter cache management
> -    def updatebranchcache(self):
> -        self = self.unfiltered()  # Until we get a smarter cache management
> -        cl = self.changelog
> -        tip = cl.tip()
> -        if self._branchcache is not None and self._branchcachetip == tip:
> -            return
> -
> -        oldtip = self._branchcachetip
> -        if oldtip is None or oldtip not in cl.nodemap:
> -            partial, last, lrev = branchmap.read(self)
> -        else:
> -            lrev = cl.rev(oldtip)
> -            partial = self._branchcache
> -
> -        catip = self._cachabletip()
> -        # if lrev == catip: cache is already up to date
> -        # if lrev >  catip: we have uncachable element in `partial` can't write
> -        #                   on disk
> -        if lrev < catip:
> -            ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
> -            branchmap.update(self, partial, ctxgen)
> -            branchmap.write(self, partial, cl.node(catip), catip)
> -        # update cache up to current tip
> -        tiprev = len(self) - 1
> -        if lrev < tiprev:
> -            ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev))
> -            branchmap.update(self, partial, ctxgen)
> -        self._branchcache = partial
> -        self._branchcachetip = tip
> -
>     def branchmap(self):

Looks like .branchmap() just became an unfilteredmethod. Guessing that shouldn't be the case, since it explicitly checks changelog.filteredrevs.

pacem in terris / ??? / ?????? / ????????? / ??
Kevin R. Bullock

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -109,5 +109,34 @@  def update(repo, partial, ctxgen):
         nodes = [head for head in partial[branch]
                  if repo.changelog.hasnode(head)]
         if not nodes:
             del partial[branch]
 
+def updatecache(repo):
+    repo = repo.unfiltered()  # Until we get a smarter cache management
+    cl = repo.changelog
+    tip = cl.tip()
+    if repo._branchcache is not None and repo._branchcachetip == tip:
+        return
+
+    oldtip = repo._branchcachetip
+    if oldtip is None or oldtip not in cl.nodemap:
+        partial, last, lrev = read(repo)
+    else:
+        lrev = cl.rev(oldtip)
+        partial = repo._branchcache
+
+    catip = repo._cachabletip()
+    # if lrev == catip: cache is already up to date
+    # if lrev >  catip: we have uncachable element in `partial` can't write
+    #                   on disk
+    if lrev < catip:
+        ctxgen = (repo[r] for r in cl.revs(lrev + 1, catip))
+        update(repo, partial, ctxgen)
+        write(repo, partial, cl.node(catip), catip)
+    # update cache up to current tip
+    tiprev = len(repo) - 1
+    if lrev < tiprev:
+        ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev))
+        update(repo, partial, ctxgen)
+    repo._branchcache = partial
+    repo._branchcachetip = tip
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -644,49 +644,19 @@  class localrepository(object):
         """
         cl = self.changelog
         return cl.rev(cl.tip())
 
     @unfilteredmethod # Until we get a smarter cache management
-    def updatebranchcache(self):
-        self = self.unfiltered()  # Until we get a smarter cache management
-        cl = self.changelog
-        tip = cl.tip()
-        if self._branchcache is not None and self._branchcachetip == tip:
-            return
-
-        oldtip = self._branchcachetip
-        if oldtip is None or oldtip not in cl.nodemap:
-            partial, last, lrev = branchmap.read(self)
-        else:
-            lrev = cl.rev(oldtip)
-            partial = self._branchcache
-
-        catip = self._cachabletip()
-        # if lrev == catip: cache is already up to date
-        # if lrev >  catip: we have uncachable element in `partial` can't write
-        #                   on disk
-        if lrev < catip:
-            ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
-            branchmap.update(self, partial, ctxgen)
-            branchmap.write(self, partial, cl.node(catip), catip)
-        # update cache up to current tip
-        tiprev = len(self) - 1
-        if lrev < tiprev:
-            ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev))
-            branchmap.update(self, partial, ctxgen)
-        self._branchcache = partial
-        self._branchcachetip = tip
-
     def branchmap(self):
         '''returns a dictionary {branch: [branchheads]}'''
         if self.changelog.filteredrevs:
             # some changeset are excluded we can't use the cache
             bmap = {}
             branchmap.update(self, bmap, (self[r] for r in self))
             return bmap
         else:
-            self.updatebranchcache()
+            branchmap.updatecache(self)
             return self._branchcache
 
 
     def _branchtip(self, heads):
         '''return the tipmost branch head in heads'''
@@ -1419,11 +1389,11 @@  class localrepository(object):
                 # be compliant anyway
                 #
                 # if minimal phase was 0 we don't need to retract anything
                 phases.retractboundary(self, targetphase, [n])
             tr.close()
-            self.updatebranchcache()
+            branchmap.updatecache(self)
             return n
         finally:
             if tr:
                 tr.release()
             lock.release()
@@ -2403,11 +2373,11 @@  class localrepository(object):
             cl.finalize(trp)
 
             tr.close()
 
             if changesets > 0:
-                self.updatebranchcache()
+                branchmap.updatecache(self)
                 def runhooks():
                     # forcefully update the on-disk branch cache
                     self.ui.debug("updating the branch cache\n")
                     self.hook("changegroup", node=hex(cl.node(clstart)),
                               source=srctype, url=url)
diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -4,11 +4,11 @@ 
 # Copyright 2007 Matt Mackall
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-from mercurial import changegroup
+from mercurial import changegroup, branchmap
 from mercurial.node import short
 from mercurial.i18n import _
 import os
 import errno
 
@@ -58,11 +58,11 @@  def _collectbrokencsets(repo, files, str
 def strip(ui, repo, nodelist, backup="all", topic='backup'):
     repo = repo.unfiltered()
     # It simplifies the logic around updating the branchheads cache if we only
     # have to consider the effect of the stripped revisions and not revisions
     # missing because the cache is out-of-date.
-    repo.updatebranchcache()
+    branchmap.updatecache(repo)
 
     cl = repo.changelog
     # TODO handle undo of merge sets
     if isinstance(nodelist, str):
         nodelist = [nodelist]