Patchwork D3024: scmutil: add method for looking up a context given a revision symbol

login
register
mail settings
Submitter phabricator
Date April 3, 2018, 4 p.m.
Message ID <fc85a4dff82515914adda874434ba233@localhost.localdomain>
Download mbox | patch
Permalink /patch/30170/
State Not Applicable
Headers show

Comments

phabricator - April 3, 2018, 4 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG0194dac77c93: scmutil: add method for looking up a context given a revision symbol (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3024?vs=7525&id=7537

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

AFFECTED FILES
  mercurial/revset.py
  mercurial/scmutil.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -433,6 +433,19 @@ 
         hexfunc = short
     return '%d:%s' % (rev, hexfunc(node))
 
+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())".
+    """
+    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)
+    return repo[symbol]
+
 def revsingle(repo, revspec, default='.', localalias=None):
     if not revspec and revspec != 0:
         return repo[default]
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -118,7 +118,7 @@ 
 def stringset(repo, subset, x, order):
     if not x:
         raise error.ParseError(_("empty string is not a valid revision"))
-    x = scmutil.intrev(repo[x])
+    x = scmutil.intrev(scmutil.revsymbol(repo, x))
     if (x in subset
         or x == node.nullrev and isinstance(subset, fullreposet)):
         return baseset([x])