changeset 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 1a5d3e555c70
files mercurial/rewriteutil.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/rewriteutil.py	Mon Aug 24 12:43:53 2020 -0400
+++ b/mercurial/rewriteutil.py	Mon Aug 24 18:44:15 2020 -0400
@@ -79,12 +79,18 @@
         )
 
 
-def update_hash_refs(repo, commitmsg):
+def update_hash_refs(repo, commitmsg, pending=None):
     """Replace all obsolete commit hashes in the message with the current hash.
 
     If the obsolete commit was split or is divergent, the hash is not replaced
     as there's no way to know which successor to choose.
+
+    For commands that update a series of commits in the current transaction, the
+    new obsolete markers can be considered by setting ``pending`` to a mapping
+    of ``pending[oldnode] = [successor_node1, successor_node2,..]``.
     """
+    if not pending:
+        pending = {}
     cache = {}
     sha1s = re.findall(sha1re, commitmsg)
     unfi = repo.unfiltered()
@@ -94,9 +100,13 @@
             continue
         ctx = unfi[fullnode]
         if not ctx.obsolete():
-            continue
-
-        successors = obsutil.successorssets(repo, ctx.node(), cache=cache)
+            successors = pending.get(fullnode)
+            if successors is None:
+                continue
+            # obsutil.successorssets() returns a list of list of nodes
+            successors = [successors]
+        else:
+            successors = obsutil.successorssets(repo, ctx.node(), cache=cache)
 
         # We can't make any assumptions about how to update the hash if the
         # cset in question was split or diverged.