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

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Apr 3 12:00:56 EDT 2018


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

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])



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


More information about the Mercurial-devel mailing list