diff mercurial/rewriteutil.py @ 50643:cbcbf63b6dbf

rewrite: simplify the `retained_extras` extra logic First, we move the definition of value outside of the rebase extensions, as this apply to all rebase-like operation and some live in other place (like evolve). Second we make it a simple set, so that it is easy for an extension to add a new value in it. Third, we move the associated logic in core too. That make it easily available to other extensions. Fourth we simplify it usage, as the verbose version of the filtering is just a handful on line long, we are just going to test all the value for updates, so the Projection overlay is not bringing much here. Note that, we make it a module level set, is a key is worth preserving it is probably worth preserving in all cases. This was already the behavior prior to this change.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 25 May 2023 00:23:05 +0200
parents ea98850a136e
children d718eddf01d9
line wrap: on
line diff
--- a/mercurial/rewriteutil.py	Mon May 29 18:41:58 2023 +0200
+++ b/mercurial/rewriteutil.py	Thu May 25 00:23:05 2023 +0200
@@ -27,6 +27,21 @@
 
 NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b')
 
+# set of extra entry that should survive a rebase-like operation, extensible by extensions
+retained_extras_on_rebase = {
+    b'source',
+    b'intermediate-source',
+}
+
+
+def preserve_extras_on_rebase(old_ctx, new_extra):
+    """preserve the relevant `extra` entry from old_ctx on rebase-like operation"""
+    new_extra.update(
+        (key, value)
+        for key, value in old_ctx.extra().items()
+        if key in retained_extras_on_rebase
+    )
+
 
 def _formatrevs(repo, revs, maxrevs=4):
     """returns a string summarizing revisions in a decent size