Mercurial > public > mercurial-scm > hg
comparison mercurial/rewriteutil.py @ 45427:78861610ded8
rewriteutil: relax the sha1 hash references to handle future hash types
Per discussion with nbjoerg in IRC.
Differential Revision: https://phab.mercurial-scm.org/D8951
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 25 Aug 2020 23:18:42 -0400 |
parents | f7e293e0475f |
children | 3d68b47e461b |
comparison
equal
deleted
inserted
replaced
45426:1a5d3e555c70 | 45427:78861610ded8 |
---|---|
19 revset, | 19 revset, |
20 scmutil, | 20 scmutil, |
21 ) | 21 ) |
22 | 22 |
23 | 23 |
24 sha1re = re.compile(br'\b[0-9a-f]{6,40}\b') | 24 NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b') |
25 | 25 |
26 | 26 |
27 def precheck(repo, revs, action=b'rewrite'): | 27 def precheck(repo, revs, action=b'rewrite'): |
28 """check if revs can be rewritten | 28 """check if revs can be rewritten |
29 action is used to control the error message. | 29 action is used to control the error message. |
90 of ``pending[oldnode] = [successor_node1, successor_node2,..]``. | 90 of ``pending[oldnode] = [successor_node1, successor_node2,..]``. |
91 """ | 91 """ |
92 if not pending: | 92 if not pending: |
93 pending = {} | 93 pending = {} |
94 cache = {} | 94 cache = {} |
95 sha1s = re.findall(sha1re, commitmsg) | 95 hashes = re.findall(NODE_RE, commitmsg) |
96 unfi = repo.unfiltered() | 96 unfi = repo.unfiltered() |
97 for sha1 in sha1s: | 97 for h in hashes: |
98 fullnode = scmutil.resolvehexnodeidprefix(unfi, sha1) | 98 fullnode = scmutil.resolvehexnodeidprefix(unfi, h) |
99 if fullnode is None: | 99 if fullnode is None: |
100 continue | 100 continue |
101 ctx = unfi[fullnode] | 101 ctx = unfi[fullnode] |
102 if not ctx.obsolete(): | 102 if not ctx.obsolete(): |
103 successors = pending.get(fullnode) | 103 successors = pending.get(fullnode) |
109 successors = obsutil.successorssets(repo, ctx.node(), cache=cache) | 109 successors = obsutil.successorssets(repo, ctx.node(), cache=cache) |
110 | 110 |
111 # We can't make any assumptions about how to update the hash if the | 111 # We can't make any assumptions about how to update the hash if the |
112 # cset in question was split or diverged. | 112 # cset in question was split or diverged. |
113 if len(successors) == 1 and len(successors[0]) == 1: | 113 if len(successors) == 1 and len(successors[0]) == 1: |
114 newsha1 = node.hex(successors[0][0]) | 114 newhash = node.hex(successors[0][0]) |
115 commitmsg = commitmsg.replace(sha1, newsha1[: len(sha1)]) | 115 commitmsg = commitmsg.replace(h, newhash[: len(h)]) |
116 else: | 116 else: |
117 repo.ui.note( | 117 repo.ui.note( |
118 _( | 118 _( |
119 b'The stale commit message reference to %s could ' | 119 b'The stale commit message reference to %s could ' |
120 b'not be updated\n' | 120 b'not be updated\n' |
121 ) | 121 ) |
122 % sha1 | 122 % h |
123 ) | 123 ) |
124 | 124 |
125 return commitmsg | 125 return commitmsg |