[PATCH STABLE] bookmarks: use try/except for accessing a node

Sean Farley sean.michael.farley at gmail.com
Tue Mar 18 19:23:56 CDT 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1395182192 18000
#      Tue Mar 18 17:36:32 2014 -0500
# Branch stable
# Node ID 8d3d12401c38524417f1151b817fd210645a0602
# Parent  03774a2b6991b451bde7095238fde9ce98380d28
bookmarks: use try/except for accessing a node

Previously, in bookmarks.compare a changeset node would be tested via 'node in
repo' but this is tricky. A value of 'True' could be returned even if the node
is hidden and accessing it will throw a 'RepoLookupError'. This happens when a
remote bookmark points to changeset that has been obsoleted locally. Therefore,
we wrap the block in a try/except which handles catching the error.

Writing a test is also tricky because I only observed this in extension land,
so I put a comment to explain why we use try/except.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -303,11 +303,13 @@ def compare(repo, srcmarks, dstmarks,
         elif b not in dstmarks:
             addsrc((b, srchex(srcmarks[b]), None))
         else:
             scid = srchex(srcmarks[b])
             dcid = dsthex(dstmarks[b])
-            if scid in repo and dcid in repo:
+            # we use try/except because testing for membership is tricky and
+            # sometimes gives True when a revision is hidden
+            try:
                 sctx = repo[scid]
                 dctx = repo[dcid]
                 if sctx.rev() < dctx.rev():
                     if validdest(repo, sctx, dctx):
                         advdst((b, scid, dcid))
@@ -316,11 +318,11 @@ def compare(repo, srcmarks, dstmarks,
                 else:
                     if validdest(repo, dctx, sctx):
                         advsrc((b, scid, dcid))
                     else:
                         diverge((b, scid, dcid))
-            else:
+            except error.RepoLookupError:
                 # it is too expensive to examine in detail, in this case
                 differ((b, scid, dcid))
 
     return results
 


More information about the Mercurial-devel mailing list