comparison mercurial/rewriteutil.py @ 45425:f7e293e0475f

rewriteutil: also consider pending obsoletes when updating hashes in messages Phabricator builds up the replacement commits and mapping in a single transaction, and then finalizes everything once the commits have been rewritten. That's too late when trying to update the messages for those commits. I'm a little concerned that this isn't a generic enough interface, since it doesn't mimic the list of list return of `obsutil.successorssets()`. But this is the type of mapping that phabricator maintains, and I don't think the methods that would be interested in calling this need to worry about split and divergence. We can fix that later if the need arises. Differential Revision: https://phab.mercurial-scm.org/D8949
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 24 Aug 2020 18:44:15 -0400
parents 0a57ef4b3bdb
children 78861610ded8
comparison
equal deleted inserted replaced
45424:0a57ef4b3bdb 45425:f7e293e0475f
77 ) 77 )
78 % (command, empty_successor) 78 % (command, empty_successor)
79 ) 79 )
80 80
81 81
82 def update_hash_refs(repo, commitmsg): 82 def update_hash_refs(repo, commitmsg, pending=None):
83 """Replace all obsolete commit hashes in the message with the current hash. 83 """Replace all obsolete commit hashes in the message with the current hash.
84 84
85 If the obsolete commit was split or is divergent, the hash is not replaced 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. 86 as there's no way to know which successor to choose.
87
88 For commands that update a series of commits in the current transaction, the
89 new obsolete markers can be considered by setting ``pending`` to a mapping
90 of ``pending[oldnode] = [successor_node1, successor_node2,..]``.
87 """ 91 """
92 if not pending:
93 pending = {}
88 cache = {} 94 cache = {}
89 sha1s = re.findall(sha1re, commitmsg) 95 sha1s = re.findall(sha1re, commitmsg)
90 unfi = repo.unfiltered() 96 unfi = repo.unfiltered()
91 for sha1 in sha1s: 97 for sha1 in sha1s:
92 fullnode = scmutil.resolvehexnodeidprefix(unfi, sha1) 98 fullnode = scmutil.resolvehexnodeidprefix(unfi, sha1)
93 if fullnode is None: 99 if fullnode is None:
94 continue 100 continue
95 ctx = unfi[fullnode] 101 ctx = unfi[fullnode]
96 if not ctx.obsolete(): 102 if not ctx.obsolete():
97 continue 103 successors = pending.get(fullnode)
98 104 if successors is None:
99 successors = obsutil.successorssets(repo, ctx.node(), cache=cache) 105 continue
106 # obsutil.successorssets() returns a list of list of nodes
107 successors = [successors]
108 else:
109 successors = obsutil.successorssets(repo, ctx.node(), cache=cache)
100 110
101 # 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
102 # cset in question was split or diverged. 112 # cset in question was split or diverged.
103 if len(successors) == 1 and len(successors[0]) == 1: 113 if len(successors) == 1 and len(successors[0]) == 1:
104 newsha1 = node.hex(successors[0][0]) 114 newsha1 = node.hex(successors[0][0])