rewriteutil: relax the sha1 hash references to handle future hash types
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 25 Aug 2020 23:18:42 -0400
changeset 45427 78861610ded8
parent 45426 1a5d3e555c70
child 45428 9b9071fabcd3
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
mercurial/rewriteutil.py
--- a/mercurial/rewriteutil.py	Mon Aug 24 18:51:25 2020 -0400
+++ b/mercurial/rewriteutil.py	Tue Aug 25 23:18:42 2020 -0400
@@ -21,7 +21,7 @@
 )
 
 
-sha1re = re.compile(br'\b[0-9a-f]{6,40}\b')
+NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b')
 
 
 def precheck(repo, revs, action=b'rewrite'):
@@ -92,10 +92,10 @@
     if not pending:
         pending = {}
     cache = {}
-    sha1s = re.findall(sha1re, commitmsg)
+    hashes = re.findall(NODE_RE, commitmsg)
     unfi = repo.unfiltered()
-    for sha1 in sha1s:
-        fullnode = scmutil.resolvehexnodeidprefix(unfi, sha1)
+    for h in hashes:
+        fullnode = scmutil.resolvehexnodeidprefix(unfi, h)
         if fullnode is None:
             continue
         ctx = unfi[fullnode]
@@ -111,15 +111,15 @@
         # We can't make any assumptions about how to update the hash if the
         # cset in question was split or diverged.
         if len(successors) == 1 and len(successors[0]) == 1:
-            newsha1 = node.hex(successors[0][0])
-            commitmsg = commitmsg.replace(sha1, newsha1[: len(sha1)])
+            newhash = node.hex(successors[0][0])
+            commitmsg = commitmsg.replace(h, newhash[: len(h)])
         else:
             repo.ui.note(
                 _(
                     b'The stale commit message reference to %s could '
                     b'not be updated\n'
                 )
-                % sha1
+                % h
             )
 
     return commitmsg