[PATCH V2] branchmap: check node against changelog instead of repo

Durham Goode durham at fb.com
Tue Mar 8 01:27:59 UTC 2016


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1457400407 28800
#      Mon Mar 07 17:26:47 2016 -0800
# Node ID 55f8aee2d2df0ad0d7f879277ba5d6ed29fd30b1
# Parent  549ff28a345f595cad7e06fb08c2ac6973e2f030
branchmap: check node against changelog instead of repo

Testing 'node in repo' requires constructing a changectx, which is a little
expensive.  Testing 'repo.changelog.hasnode(node)' is notably faster. This
saves 10-20ms off of every command, when testing a few thousand nodes from the
branch cache.

I considered changing the implementation of localrepository.__contains__ so
every place would benefit from the change, but since
localrepository.__contains__ uses changectx to check if the commit exists, it
means it supports a wider range of possible inputs (like revs, hashes, '.',
etc), so it seemed unnecessarily risky.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -55,6 +55,7 @@ def read(repo):
         if not partial.validfor(repo):
             # invalidate the cache
             raise ValueError('tip differs')
+        cl = repo.changelog
         for l in lines:
             if not l:
                 continue
@@ -62,9 +63,9 @@ def read(repo):
             if state not in 'oc':
                 raise ValueError('invalid branch state')
             label = encoding.tolocal(label.strip())
-            if not node in repo:
-                raise ValueError('node %s does not exist' % node)
             node = bin(node)
+            if not cl.hasnode(node):
+                raise ValueError('node %s does not exist' % hex(node))
             partial.setdefault(label, []).append(node)
             if state == 'c':
                 partial._closednodes.add(node)


More information about the Mercurial-devel mailing list