joerg.sonnenberger created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
A common pattern is using a changeset context and obtaining the node to
compare against nullid. Change this to obtain the nullrev instead. In
the future, the nullid becomes a property of the repository and is no
longer a global constant, so using nullrev is much easier to reason
about. Python function call overhead makes the difference moot, but
future changes will result in more dictionary lookups otherwise, so
prefer the simpler pattern.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10290
AFFECTED FILES
hgext/extdiff.py
hgext/split.py
mercurial/context.py
mercurial/copies.py
mercurial/logcmdutil.py
mercurial/mergestate.py
mercurial/shelve.py
mercurial/simplemerge.py
CHANGE DETAILS
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -19,7 +19,7 @@
from __future__ import absolute_import
from .i18n import _
-from .node import nullid
+from .node import nullrev
from . import (
error,
mdiff,
@@ -427,7 +427,7 @@
def is_not_null(ctx):
if not util.safehasattr(ctx, "node"):
return False
-return ctx.node() != nullid
+return ctx.rev() != nullrev
def _mergediff(m3, name_a, name_b, name_base):
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -534,7 +534,7 @@
parent = parents[0]
origbranch = wctx.branch()
-if parent.node() != nullid:
+if parent.rev() != nullrev:
desc = b"changes to: %s" % parent.description().split(b'\n', 1)[0]
else:
desc = b'(changes in empty repository)'
diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -11,6 +11,7 @@
hex,
nullhex,
nullid,
+nullrev,
)
from . import (
error,
@@ -341,7 +342,7 @@
flo = fco.flags()
fla = fca.flags()
if b'x' in flags + flo + fla and b'l' not in flags + flo + fla:
-if fca.node() == nullid and flags != flo:
+if fca.rev() == nullrev and flags != flo:
if preresolve:
self._repo.ui.warn(
_(
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -14,6 +14,7 @@
from .i18n import _
from .node import (
nullid,
+nullrev,
wdirid,
wdirrev,
)
@@ -82,7 +83,7 @@
If diff.merge is enabled, an overlayworkingctx of the auto-merged parents
will be returned.
"""
repo = ctx.repo()
-if repo.ui.configbool(b"diff", b"merge") and ctx.p2().node() != nullid:
+if repo.ui.configbool(b"diff", b"merge") and ctx.p2().rev() != nullrev:
# avoid cycle context -> subrepo -> cmdutil -> logcmdutil
from . import context
diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -149,7 +149,7 @@
# optimization, since the ctx.files() for a merge commit is not correct for
# this comparison.
forwardmissingmatch = match
-if b.p1() == a and b.p2().node() == nullid:
+if b.p1() == a and b.p2().rev() == nullrev:
filesmatcher = matchmod.exact(b.files())
forwardmissingmatch = matchmod.intersectmatchers(match, filesmatcher)
if repo.ui.configbool(b'devel', b'copy-tracing.trace-all-files'):
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -2885,7 +2885,7 @@
# "1 < len(self._parents)" can't be used for checking
# existence of the 2nd parent, because "memctx._parents" is
# explicitly initialized by the list, of which length is 2.
-if p2.node() != nullid:
+if p2.rev() != nullrev:
man2 = p2.manifest()
managing = lambda f: f in man1 or f in man2
else:
@@ -2903,7 +2903,7 @@
return scmutil.status(modified, added, removed, [], [], [], [])
def parents(self):
-if self._parents[1].node() == nullid:
+if self._parents[1].rev() == nullrev:
return [self._parents[0]]
return self._parents
@@ -3052,7 +3052,7 @@
# "1 < len(self._parents)" can't be used for checking
# existence of the 2nd parent, because "metadataonlyctx._parents" is
# explicitly initialized by the list, of which length is 2.
-if p2.node() != nullid:
+if p2.rev() != nullrev:
man2 = p2.manifest()
managing = lambda f: f in man1 or f in man2
else:
diff --git a/hgext/split.py b/hgext/split.py
--- a/hgext/split.py
+++ b/hgext/split.py
@@ -12,7 +12,7 @@
from mercurial.i18n import _
from mercurial.node import (
-