Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 46842:ad878e3f282b
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
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Tue, 30 Mar 2021 02:33:12 +0200 |
parents | d4ba4d51f85f |
children | d9531094cf8e |
comparison
equal
deleted
inserted
replaced
46841:e7b4607d52e3 | 46842:ad878e3f282b |
---|---|
14 | 14 |
15 from .i18n import _ | 15 from .i18n import _ |
16 from .node import ( | 16 from .node import ( |
17 hex, | 17 hex, |
18 nullid, | 18 nullid, |
19 nullrev, | |
19 short, | 20 short, |
20 ) | 21 ) |
21 from .pycompat import ( | 22 from .pycompat import ( |
22 getattr, | 23 getattr, |
23 open, | 24 open, |
1934 # launch the editor | 1935 # launch the editor |
1935 message = None | 1936 message = None |
1936 ui.debug(b'message:\n%s\n' % (message or b'')) | 1937 ui.debug(b'message:\n%s\n' % (message or b'')) |
1937 | 1938 |
1938 if len(parents) == 1: | 1939 if len(parents) == 1: |
1939 parents.append(repo[nullid]) | 1940 parents.append(repo[nullrev]) |
1940 if opts.get(b'exact'): | 1941 if opts.get(b'exact'): |
1941 if not nodeid or not p1: | 1942 if not nodeid or not p1: |
1942 raise error.InputError(_(b'not a Mercurial patch')) | 1943 raise error.InputError(_(b'not a Mercurial patch')) |
1943 p1 = repo[p1] | 1944 p1 = repo[p1] |
1944 p2 = repo[p2 or nullid] | 1945 p2 = repo[p2 or nullrev] |
1945 elif p2: | 1946 elif p2: |
1946 try: | 1947 try: |
1947 p1 = repo[p1] | 1948 p1 = repo[p1] |
1948 p2 = repo[p2] | 1949 p2 = repo[p2] |
1949 # Without any options, consider p2 only if the | 1950 # Without any options, consider p2 only if the |
1950 # patch is being applied on top of the recorded | 1951 # patch is being applied on top of the recorded |
1951 # first parent. | 1952 # first parent. |
1952 if p1 != parents[0]: | 1953 if p1 != parents[0]: |
1953 p1 = parents[0] | 1954 p1 = parents[0] |
1954 p2 = repo[nullid] | 1955 p2 = repo[nullrev] |
1955 except error.RepoError: | 1956 except error.RepoError: |
1956 p1, p2 = parents | 1957 p1, p2 = parents |
1957 if p2.node() == nullid: | 1958 if p2.rev() == nullrev: |
1958 ui.warn( | 1959 ui.warn( |
1959 _( | 1960 _( |
1960 b"warning: import the patch as a normal revision\n" | 1961 b"warning: import the patch as a normal revision\n" |
1961 b"(use --exact to import the patch as a merge)\n" | 1962 b"(use --exact to import the patch as a merge)\n" |
1962 ) | 1963 ) |