D3714: scmutil: from revsymbol(), extract helper for resolving multiple nodes
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon Jun 11 23:10:49 UTC 2018
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
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
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list