D3450: context: only bother looking for broken dirstate for 20-byte changeid

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sun May 6 00:50:58 EDT 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  If we fail to look up a changeid in changectx.__init__, we check if it
  exactly matches any of the dirstate parents, and if it does, we print
  a more specific message ("working directory has unknown parent '...'!"
  instead of "unknown revision '...'"). The dirstate parents are always
  20 bytes, so there's no need to check for a match when the given
  changeid is not 20 bytes. (And now that all the other allowed forms of
  changeid have been moved out of the constructor, there's no risk that
  a changeid that did match a dirstate parent was actually a valid
  bookmark.)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3450

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -412,7 +412,14 @@
                 except error.FilteredLookupError:
                     raise
                 except LookupError:
-                    pass
+                    # check if it might have come from damaged dirstate
+                    #
+                    # XXX we could avoid the unfiltered if we had a recognizable
+                    # exception for filtered changeset access
+                    if (repo.local()
+                        and changeid in repo.unfiltered().dirstate.parents()):
+                        msg = _("working directory has unknown parent '%s'!")
+                        raise error.Abort(msg % short(changeid))
 
             if len(changeid) == 40:
                 try:
@@ -425,14 +432,6 @@
                     pass
 
             # lookup failed
-            # check if it might have come from damaged dirstate
-            #
-            # XXX we could avoid the unfiltered if we had a recognizable
-            # exception for filtered changeset access
-            if (repo.local()
-                and changeid in repo.unfiltered().dirstate.parents()):
-                msg = _("working directory has unknown parent '%s'!")
-                raise error.Abort(msg % short(changeid))
             try:
                 if len(changeid) == 20 and nonascii(changeid):
                     changeid = hex(changeid)



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list