Patchwork D3714: scmutil: from revsymbol(), extract helper for resolving multiple nodes

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

Comments

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

REVISION SUMMARY
  See next commit for motivation. This is just a simple refactoring to
  prepare for that.
  
  I'm not particularly happy with how this code is reused (after the
  next commit). I'm happy to improve it if someone has a good idea.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - July 9, 2018, 4:59 p.m.
martinvonz abandoned this revision.
martinvonz added a comment.


  Abandoning since I abandoned its descendant, https://phab.mercurial-scm.org/D3715.

REPOSITORY
  rHG Mercurial

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

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
@@ -488,20 +488,14 @@ 
     except error.RepoLookupError:
         return False
 
-def revsymbol(repo, symbol):
-    """Returns a context given a single revision symbol (as string).
-
-    This is similar to revsingle(), but accepts only a single revision symbol,
-    i.e. things like ".", "tip", "1234", "deadbeef", "my-bookmark" work, but
-    not "max(public())".
-    """
+def _revsymbol(repo, symbol):
     if not isinstance(symbol, bytes):
         msg = ("symbol (%s of type %s) was not a string, did you mean "
                "repo[symbol]?" % (symbol, type(symbol)))
         raise error.ProgrammingError(msg)
     try:
         if symbol in ('.', 'tip', 'null'):
-            return repo[symbol]
+            return [repo[symbol]]
 
         try:
             r = int(symbol)
@@ -512,7 +506,7 @@ 
                 r += l
             if r < 0 or r >= l and r != wdirrev:
                 raise ValueError
-            return repo[r]
+            return [repo[r]]
         except error.FilteredIndexError:
             raise
         except (ValueError, OverflowError, IndexError):
@@ -522,7 +516,7 @@ 
             try:
                 node = bin(symbol)
                 rev = repo.changelog.rev(node)
-                return repo[rev]
+                return [repo[rev]]
             except error.FilteredLookupError:
                 raise
             except (TypeError, LookupError):
@@ -532,23 +526,34 @@ 
         try:
             node = repo.names.singlenode(repo, symbol)
             rev = repo.changelog.rev(node)
-            return repo[rev]
+            return [repo[rev]]
         except KeyError:
             pass
 
         node = resolvehexnodeidprefix(repo, symbol)
         if node is not None:
             rev = repo.changelog.rev(node)
-            return repo[rev]
+            return [repo[rev]]
 
         raise error.RepoLookupError(_("unknown revision '%s'") % symbol)
 
     except error.WdirUnsupported:
-        return repo[None]
+        return [repo[None]]
     except (error.FilteredIndexError, error.FilteredLookupError,
             error.FilteredRepoLookupError):
         raise _filterederror(repo, symbol)
 
+def revsymbol(repo, symbol):
+    """Returns a context given a single revision symbol (as string).
+
+    This is similar to revsingle(), but accepts only a single revision symbol,
+    i.e. things like ".", "tip", "1234", "deadbeef", "my-bookmark" work, but
+    not "max(public())".
+    """
+    ctxs = _revsymbol(repo, symbol)
+    assert len(ctxs) == 1
+    return ctxs[0]
+
 def _filterederror(repo, changeid):
     """build an exception to be raised about a filtered changeid