Patchwork [07,of,10] branchmap: factorise changelog access in update

mail settings
Submitter Pierre-Yves David
Date Dec. 22, 2012, 1:48 a.m.
Message ID <3264d3ce53a0fe45c7b4.1356140934@yamac.lan>
Download mbox | patch
Permalink /patch/270/
State Superseded, archived
Commit 3264d3ce53a0fe45c7b484509fbd380bbe82a805
Headers show


Pierre-Yves David - Dec. 22, 2012, 1:48 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at>
# Date 1356138672 -3600
# Node ID 3264d3ce53a0fe45c7b484509fbd380bbe82a805
# Parent  f0d56efaa35af94289119820179508e9546984a1
branchmap: factorise changelog access in update

This both improves readability and performance. Access to changelog of filtered
repository currently have a minor overhead.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -45,10 +45,11 @@  def read(repo):
 def update(repo, partial, ctxgen):
     """Given a branchhead cache, partial, that may have extra nodes or be
     missing heads, and a generator of nodes that are at least a superset of
     heads missing, this function updates partial to be correct.
+    cl = repo.changelog
     # collect new branch entries
     newbranches = {}
     for c in ctxgen:
         newbranches.setdefault(c.branch(), []).append(c.node())
     # if older branchheads are reachable from new ones, they aren't
@@ -58,14 +59,14 @@  def update(repo, partial, ctxgen):
         bheads = partial.setdefault(branch, [])
         # Remove candidate heads that no longer are in the repo (e.g., as
         # the result of a strip that just happened).  Avoid using 'node in
         # self' here because that dives down into branchcache code somewhat
         # recursively.
-        bheadrevs = [repo.changelog.rev(node) for node in bheads
-                     if repo.changelog.hasnode(node)]
-        newheadrevs = [repo.changelog.rev(node) for node in newnodes
-                       if repo.changelog.hasnode(node)]
+        bheadrevs = [cl.rev(node) for node in bheads
+                     if cl.hasnode(node)]
+        newheadrevs = [cl.rev(node) for node in newnodes
+                       if cl.hasnode(node)]
         ctxisnew = bheadrevs and min(newheadrevs) > max(bheadrevs)
         # Remove duplicates - nodes that are in newheadrevs and are already
         # in bheadrevs.  This can happen if you strip a node whose parent
         # was already a head (because they're on different branches).
         bheadrevs = sorted(set(bheadrevs).union(newheadrevs))
@@ -83,24 +84,24 @@  def update(repo, partial, ctxgen):
         # heads because an existing head is their descendant.
         while iterrevs:
             latest = iterrevs.pop()
             if latest not in bheadrevs:
-            ancestors = set(repo.changelog.ancestors([latest],
+            ancestors = set(cl.ancestors([latest],
             if ancestors:
                 bheadrevs = [b for b in bheadrevs if b not in ancestors]
-        partial[branch] = [repo.changelog.node(rev) for rev in bheadrevs]
+        partial[branch] = [cl.node(rev) for rev in bheadrevs]
     # There may be branches that cease to exist when the last commit in the
     # branch was stripped.  This code filters them out.  Note that the
     # branch that ceased to exist may not be in newbranches because
     # newbranches is the set of candidate heads, which when you strip the
     # last commit in a branch will be the parent branch.
     for branch in partial.keys():
         nodes = [head for head in partial[branch]
-                 if repo.changelog.hasnode(head)]
+                 if cl.hasnode(head)]
         if not nodes:
             del partial[branch]
 def updatecache(repo):
     repo = repo.unfiltered()  # Until we get a smarter cache management