changeset 6492:e44d343b9ed2

evolve: retain extras when relocating a commit Building on 2cd959fe631a::82e5a9b1ef1e (submitted as https://foss.heptapod.net/mercurial/mercurial-devel/-/merge_requests/511) and cbcbf63b6dbf, this change addresses the regression introduced in b1d1f4ade142::53d63b608230 (from !458) when evolve stopped including extras added by downstream plugins when relocating commits for evolve. Mercurial now provides an extension point at mercurial.rewriteutil.preserve_extras_on_rebase; it's a list of extras to be retained, that Evolve uses, and that downstream users might extend.
author Jason R. Coombs <jaraco@jaraco.com>
date Thu, 08 Jun 2023 11:07:34 -0400
parents 173293415d1f
children e36883d88108
files hgext3rd/evolve/compat.py hgext3rd/evolve/evolvecmd.py
diffstat 2 files changed, 26 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/compat.py	Thu May 25 11:08:09 2023 -0300
+++ b/hgext3rd/evolve/compat.py	Thu Jun 08 11:07:34 2023 -0400
@@ -21,6 +21,7 @@
     node,
     obsolete,
     pycompat,
+    rewriteutil,
     scmutil,
     util,
 )
@@ -559,3 +560,26 @@
 else:
     # hg <= 5.6 (527ce85c2e60)
     StateError = error.Abort
+
+try:
+    retained_extras_on_rebase = rewriteutil.retained_extras_on_rebase
+    preserve_extras_on_rebase = rewriteutil.preserve_extras_on_rebase
+except AttributeError:
+    # hg <= 6.4 (cbcbf63b6dbf)
+    retained_extras_on_rebase = {
+        b'source',
+        b'intermediate-source',
+    }
+
+    def preserve_extras_on_rebase(old_ctx, new_extra):
+        """preserve the relevant `extra` entries from old_ctx on rebase-like operations
+        """
+        old_extra = old_ctx.extra()
+        for key in retained_extras_on_rebase:
+            value = old_extra.get(key)
+            if value is not None:
+                new_extra[key] = value
+
+    # give other extensions an opportunity to collaborate
+    rewriteutil.retained_extras_on_rebase = retained_extras_on_rebase
+    rewriteutil.preserve_extras_on_rebase = preserve_extras_on_rebase
--- a/hgext3rd/evolve/evolvecmd.py	Thu May 25 11:08:09 2023 -0300
+++ b/hgext3rd/evolve/evolvecmd.py	Thu Jun 08 11:07:34 2023 -0400
@@ -959,18 +959,9 @@
     _finalizerelocate(repo, orig, dest, nodenew, tr, category, evolvestate)
     return nodenew
 
-# This is copied from hgext.rebase._savegraft()
-def _savegraft(ctx, extra):
-    s = ctx.extra().get(b'source', None)
-    if s is not None:
-        extra[b'source'] = s
-    s = ctx.extra().get(b'intermediate-source', None)
-    if s is not None:
-        extra[b'intermediate-source'] = s
-
 def _relocatecommit(repo, orig, dest, pctx, keepbranch, commitmsg, update):
     extra = {}
-    _savegraft(orig, extra)
+    compat.preserve_extras_on_rebase(orig, extra)
     extra[b'rebase_source'] = orig.hex()
     targetphase = max(orig.phase(), phases.draft)
     configoverrides = {
@@ -2201,7 +2192,7 @@
     ctx = orig
 
     extra = {}
-    _savegraft(ctx, extra)
+    compat.preserve_extras_on_rebase(orig, extra)
     extra[b'rebase_source'] = orig.hex()
 
     user = ctx.user()