refactor: prefer lookup by revision, even for null
authorJoerg Sonnenberger <joerg@bec.de>
Tue, 30 Mar 2021 02:33:12 +0200
changeset 46842 ad878e3f282b
parent 46841 e7b4607d52e3
child 46843 728d89f6f9b1
refactor: prefer lookup by revision, even for null While the nullid lookup is a special case, it is still more complicated. The common pattern is to lookup via nullrev so be consistent here. Differential Revision: https://phab.mercurial-scm.org/D10280
mercurial/cmdutil.py
mercurial/context.py
--- a/mercurial/cmdutil.py	Mon Mar 29 01:35:54 2021 +0200
+++ b/mercurial/cmdutil.py	Tue Mar 30 02:33:12 2021 +0200
@@ -16,6 +16,7 @@
 from .node import (
     hex,
     nullid,
+    nullrev,
     short,
 )
 from .pycompat import (
@@ -1936,12 +1937,12 @@
     ui.debug(b'message:\n%s\n' % (message or b''))
 
     if len(parents) == 1:
-        parents.append(repo[nullid])
+        parents.append(repo[nullrev])
     if opts.get(b'exact'):
         if not nodeid or not p1:
             raise error.InputError(_(b'not a Mercurial patch'))
         p1 = repo[p1]
-        p2 = repo[p2 or nullid]
+        p2 = repo[p2 or nullrev]
     elif p2:
         try:
             p1 = repo[p1]
@@ -1951,10 +1952,10 @@
             # first parent.
             if p1 != parents[0]:
                 p1 = parents[0]
-                p2 = repo[nullid]
+                p2 = repo[nullrev]
         except error.RepoError:
             p1, p2 = parents
-        if p2.node() == nullid:
+        if p2.rev() == nullrev:
             ui.warn(
                 _(
                     b"warning: import the patch as a normal revision\n"
--- a/mercurial/context.py	Mon Mar 29 01:35:54 2021 +0200
+++ b/mercurial/context.py	Tue Mar 30 02:33:12 2021 +0200
@@ -3000,7 +3000,7 @@
             parents = [repo[p] for p in parents if p is not None]
         parents = parents[:]
         while len(parents) < 2:
-            parents.append(repo[nullid])
+            parents.append(repo[nullrev])
         p1, p2 = self._parents = parents
 
         # sanity check to ensure that the reused manifest parents are