Patchwork D8951: rewriteutil: relax the sha1 hash references to handle future hash types

login
register
mail settings
Submitter phabricator
Date Aug. 26, 2020, 3:21 a.m.
Message ID <differential-rev-PHID-DREV-def5ftnjjdzy6y4qmu7u-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47051/
State Superseded
Headers show

Comments

phabricator - Aug. 26, 2020, 3:21 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Per discussion with nbjoerg in IRC.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8951

AFFECTED FILES
  mercurial/utils/rewriteutil.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/utils/rewriteutil.py b/mercurial/utils/rewriteutil.py
--- a/mercurial/utils/rewriteutil.py
+++ b/mercurial/utils/rewriteutil.py
@@ -28,7 +28,7 @@ 
 
     assert any((Dict, List, Optional,))
 
-sha1re = re.compile(br'\b[0-9a-f]{6,40}\b')
+NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b')
 
 
 def update_hash_refs(repo, commitmsg, pending=None):
@@ -41,10 +41,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]
@@ -61,14 +61,14 @@ 
         # cset in question was split or diverged.
         if len(successors) == 1 and len(successors[0]) == 1:
             newsha1 = nodemod.hex(successors[0][0])
-            commitmsg = commitmsg.replace(sha1, newsha1[: len(sha1)])
+            commitmsg = commitmsg.replace(h, newsha1[: len(h)])
         else:
             repo.ui.note(
                 _(
                     b'The stale commit message reference to %s could '
                     b'not be updated\n'
                 )
-                % sha1
+                % h
             )
 
     return commitmsg