Patchwork D3193: scmutil: handle full hex nodeids in revsymbol()

login
register
mail settings
Submitter phabricator
Date April 8, 2018, 5:04 p.m.
Message ID <differential-rev-PHID-DREV-jgqcdk5a5l4ae23mfpla-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/30575/
State Superseded
Headers show

Comments

phabricator - April 8, 2018, 5:04 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is a bit unfortunate, but it enables moving other pieces out of
  changectx's constructor without affecting the order in which we
  look up things (e.g. hex nodeid before bookmark).
  
  We convert nodeid to revnum before calling repo.__getitem__, even
  though that will result in converting back to nodeid later. This is so
  we can handle the LookupError and attempt to interpret the string as
  something else (e.g. a bookmark).
  
  We also need to start handling WdirUnsupported now, since the full hex
  nodeid "ffff..." represents the working directory. The exception is
  raised by the revlog layer.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -18,6 +18,7 @@ 
 
 from .i18n import _
 from .node import (
+    bin,
     hex,
     nullid,
     short,
@@ -475,8 +476,20 @@ 
         except (ValueError, OverflowError, IndexError):
             pass
 
+        if len(symbol) == 40:
+            try:
+                node = bin(symbol)
+                rev = repo.changelog.rev(node)
+                return repo[rev]
+            except error.FilteredLookupError:
+                raise
+            except (TypeError, LookupError):
+                pass
+
         return repo[symbol]
 
+    except error.WdirUnsupported:
+        return repo[None]
     except (error.FilteredIndexError, error.FilteredLookupError,
             error.FilteredRepoLookupError):
         raise _filterederror(repo, symbol)