Patchwork D3146: context: move handling of stringified ints to revsymbol (API)

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

Comments

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

REVISION SUMMARY
  Now there seem to be no more cases where we pass a stringified int
  into repo.__getitem__, so now can finally move that out of changectx's
  constructor and into revsymbol().

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/context.py
  mercurial/scmutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - April 6, 2018, 4:47 a.m.
martinvonz planned changes to this revision.
martinvonz added a comment.


  I should decide what to do about the `changeid == repo.dirstate.p1()` case before this patch. Also, I may find more cases that should be fixed when I move out other parts (I just found one case in hgweb), so please hold off reviewing this.

REPOSITORY
  rHG Mercurial

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

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
@@ -452,7 +452,28 @@ 
                "repo[symbol]?" % (symbol, type(symbol)))
         raise error.ProgrammingError(msg)
     try:
+        # TODO: We ideally should resolve these three here instead of
+        # delegating to repo.__getitem__
+        if symbol in ('.', 'tip', 'null'):
+            return repo[symbol]
+
+        try:
+            r = int(symbol)
+            if '%d' % r != symbol:
+                raise ValueError
+            l = len(repo.changelog)
+            if r < 0:
+                r += l
+            if r < 0 or r >= l and r != wdirrev:
+                raise ValueError
+            return repo[r]
+        except error.FilteredIndexError:
+            raise
+        except (ValueError, OverflowError, IndexError):
+            pass
+
         return repo[symbol]
+
     except (error.FilteredIndexError, error.FilteredLookupError,
             error.FilteredRepoLookupError):
         raise _filterederror(repo, symbol)
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -24,7 +24,6 @@ 
     short,
     wdirid,
     wdirnodes,
-    wdirrev,
 )
 from . import (
     dagop,
@@ -415,23 +414,6 @@ 
                 except LookupError:
                     pass
 
-            try:
-                r = int(changeid)
-                if '%d' % r != changeid:
-                    raise ValueError
-                l = len(repo.changelog)
-                if r < 0:
-                    r += l
-                if r < 0 or r >= l and r != wdirrev:
-                    raise ValueError
-                self._rev = r
-                self._node = repo.changelog.node(r)
-                return
-            except error.FilteredIndexError:
-                raise
-            except (ValueError, OverflowError, IndexError):
-                pass
-
             if len(changeid) == 40:
                 try:
                     self._node = bin(changeid)