in eden/scm/edenscm/mercurial/context.py [0:0]
def __init__(self, repo, changeid=""):
"""changeid is a revision number or node"""
# since basectx.__new__ already took care of copying the object, we
# don't need to do anything in __init__, so we just exit here
if isinstance(changeid, basectx):
return
if changeid == "":
changeid = "."
self._repo = repo
try:
if isint(changeid):
changeid = scmutil.revf64decode(changeid)
self._node = repo.changelog.node(changeid)
return
if changeid == "null":
self._node = nullid
return
if changeid == "tip":
self._node = repo.changelog.tip()
return
try:
if changeid == "." or repo.local() and changeid == repo.dirstate.p1():
# this is a hack to delay/avoid loading obsmarkers
# when we know that '.' won't be hidden
self._node = repo.dirstate.p1()
return
except Exception:
if not getattr(self._repo, "_warnedworkdir", False):
self._repo.ui.warn(
_("warning: failed to inspect working copy parent\n")
)
self._repo._warnedworkdir = True
# we failed on our optimization pass
# this can happen when dirstate is broken
pass
if len(changeid) == 20 and isinstance(changeid, bytes):
try:
self._node = changeid
repo.changelog.rev(changeid)
return
except LookupError:
# The only valid bytes changeid is a node, and if the node was not
# found above, this is now considered an unknown changeid.
# let's convert, or go ahead and through.
if sys.version_info[0] >= 3 and isinstance(changeid, bytes):
# Hex the node so it prints pretty.
changeid = hex(changeid)
raise error.RepoLookupError(
_("unknown revision '%s'") % changeid
)
# The valid changeid types are str, bytes, and int. int and bytes
# are handled above, so only str should be present now.
assert isinstance(changeid, str)
# Try to resolve it as a rev number?
# - If changeid is an int (tested above).
# - If HGPLAIN is set (for compatibility).
# - Or if ui.ignorerevnum is false (changeid is a str).
if repo.ui.plain() or not repo.ui.configbool("ui", "ignorerevnum"):
try:
r = int(changeid)
if "%d" % r != changeid:
raise ValueError
if r < 0 and r != wdirrev:
if -r > len(repo):
raise ValueError
r = repo.revs("first(sort(_all(), -rev), %z)", -r).last()
if r is None:
raise ValueError
if r < 0 and r != wdirrev:
raise ValueError
r = scmutil.revf64decode(r)
node = repo.changelog.node(r)
self._node = node
return
except (
ValueError,
OverflowError,
IndexError,
TypeError,
error.RustError,
):
pass
if len(changeid) == 40:
try:
self._node = bin(changeid)
repo.changelog.rev(self._node)
return
except (TypeError, LookupError):
pass
# lookup bookmarks through the name interface
try:
self._node = repo.names.singlenode(repo, changeid)
repo.changelog.rev(self._node)
return
except KeyError:
pass
except error.RepoLookupError:
pass
self._node = repo.changelog._partialmatch(changeid)
if self._node is not None:
repo.changelog.rev(self._node)
return
# lookup failed
# check if it might have come from damaged dirstate
if repo.local() and changeid in repo.dirstate.parents():
msg = _("working directory has unknown parent '%s'!")
raise error.Abort(msg % short(changeid))
try:
if len(changeid) == 20 and nonascii(changeid):
changeid = hex(changeid)
except TypeError:
pass
except IndexError:
pass
raise error.RepoLookupError(_("unknown revision '%s'") % changeid)