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.
hg-reviewers |
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.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/scmutil.py (31 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Martin von Zweigbergk | Jun 11 2018, 5:37 PM |
Status | Author | Revision | |
---|---|---|---|
Abandoned | martinvonz | ||
Abandoned | martinvonz |
ambiguous nodeid prefix. | ambiguous nodeid prefix. | ||||
""" | """ | ||||
try: | try: | ||||
revsymbol(repo, symbol) | revsymbol(repo, symbol) | ||||
return True | return True | ||||
except error.RepoLookupError: | except error.RepoLookupError: | ||||
return False | return False | ||||
def revsymbol(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())". | |||||
""" | |||||
if not isinstance(symbol, bytes): | if not isinstance(symbol, bytes): | ||||
msg = ("symbol (%s of type %s) was not a string, did you mean " | msg = ("symbol (%s of type %s) was not a string, did you mean " | ||||
"repo[symbol]?" % (symbol, type(symbol))) | "repo[symbol]?" % (symbol, type(symbol))) | ||||
raise error.ProgrammingError(msg) | raise error.ProgrammingError(msg) | ||||
try: | try: | ||||
if symbol in ('.', 'tip', 'null'): | if symbol in ('.', 'tip', 'null'): | ||||
return repo[symbol] | return [repo[symbol]] | ||||
try: | try: | ||||
r = int(symbol) | r = int(symbol) | ||||
if '%d' % r != symbol: | if '%d' % r != symbol: | ||||
raise ValueError | raise ValueError | ||||
l = len(repo.changelog) | l = len(repo.changelog) | ||||
if r < 0: | if r < 0: | ||||
r += l | r += l | ||||
if r < 0 or r >= l and r != wdirrev: | if r < 0 or r >= l and r != wdirrev: | ||||
raise ValueError | raise ValueError | ||||
return repo[r] | return [repo[r]] | ||||
except error.FilteredIndexError: | except error.FilteredIndexError: | ||||
raise | raise | ||||
except (ValueError, OverflowError, IndexError): | except (ValueError, OverflowError, IndexError): | ||||
pass | pass | ||||
if len(symbol) == 40: | if len(symbol) == 40: | ||||
try: | try: | ||||
node = bin(symbol) | node = bin(symbol) | ||||
rev = repo.changelog.rev(node) | rev = repo.changelog.rev(node) | ||||
return repo[rev] | return [repo[rev]] | ||||
except error.FilteredLookupError: | except error.FilteredLookupError: | ||||
raise | raise | ||||
except (TypeError, LookupError): | except (TypeError, LookupError): | ||||
pass | pass | ||||
# look up bookmarks through the name interface | # look up bookmarks through the name interface | ||||
try: | try: | ||||
node = repo.names.singlenode(repo, symbol) | node = repo.names.singlenode(repo, symbol) | ||||
rev = repo.changelog.rev(node) | rev = repo.changelog.rev(node) | ||||
return repo[rev] | return [repo[rev]] | ||||
except KeyError: | except KeyError: | ||||
pass | pass | ||||
node = resolvehexnodeidprefix(repo, symbol) | node = resolvehexnodeidprefix(repo, symbol) | ||||
if node is not None: | if node is not None: | ||||
rev = repo.changelog.rev(node) | rev = repo.changelog.rev(node) | ||||
return repo[rev] | return [repo[rev]] | ||||
raise error.RepoLookupError(_("unknown revision '%s'") % symbol) | raise error.RepoLookupError(_("unknown revision '%s'") % symbol) | ||||
except error.WdirUnsupported: | except error.WdirUnsupported: | ||||
return repo[None] | return [repo[None]] | ||||
except (error.FilteredIndexError, error.FilteredLookupError, | except (error.FilteredIndexError, error.FilteredLookupError, | ||||
error.FilteredRepoLookupError): | error.FilteredRepoLookupError): | ||||
raise _filterederror(repo, symbol) | 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): | def _filterederror(repo, changeid): | ||||
"""build an exception to be raised about a filtered changeid | """build an exception to be raised about a filtered changeid | ||||
This is extracted in a function to help extensions (eg: evolve) to | This is extracted in a function to help extensions (eg: evolve) to | ||||
experiment with various message variants.""" | experiment with various message variants.""" | ||||
if repo.filtername.startswith('visible'): | if repo.filtername.startswith('visible'): | ||||
# Check if the changeset is obsolete | # Check if the changeset is obsolete |