##// END OF EJS Templates
rewriteutil: extract evolve code used to replace obsolete hashes in commits...
Matt Harbison -
r45993:0a57ef4b default
parent child Browse files
Show More
@@ -7,16 +7,23 b''
7 7
8 8 from __future__ import absolute_import
9 9
10 import re
11
10 12 from .i18n import _
11 13
12 14 from . import (
13 15 error,
14 16 node,
15 17 obsolete,
18 obsutil,
16 19 revset,
20 scmutil,
17 21 )
18 22
19 23
24 sha1re = re.compile(br'\b[0-9a-f]{6,40}\b')
25
26
20 27 def precheck(repo, revs, action=b'rewrite'):
21 28 """check if revs can be rewritten
22 29 action is used to control the error message.
@@ -70,3 +77,39 b' def skip_empty_successor(ui, command):'
70 77 )
71 78 % (command, empty_successor)
72 79 )
80
81
82 def update_hash_refs(repo, commitmsg):
83 """Replace all obsolete commit hashes in the message with the current hash.
84
85 If the obsolete commit was split or is divergent, the hash is not replaced
86 as there's no way to know which successor to choose.
87 """
88 cache = {}
89 sha1s = re.findall(sha1re, commitmsg)
90 unfi = repo.unfiltered()
91 for sha1 in sha1s:
92 fullnode = scmutil.resolvehexnodeidprefix(unfi, sha1)
93 if fullnode is None:
94 continue
95 ctx = unfi[fullnode]
96 if not ctx.obsolete():
97 continue
98
99 successors = obsutil.successorssets(repo, ctx.node(), cache=cache)
100
101 # We can't make any assumptions about how to update the hash if the
102 # cset in question was split or diverged.
103 if len(successors) == 1 and len(successors[0]) == 1:
104 newsha1 = node.hex(successors[0][0])
105 commitmsg = commitmsg.replace(sha1, newsha1[: len(sha1)])
106 else:
107 repo.ui.note(
108 _(
109 b'The stale commit message reference to %s could '
110 b'not be updated\n'
111 )
112 % sha1
113 )
114
115 return commitmsg
General Comments 0
You need to be logged in to leave comments. Login now