changeset 6655:81fe0a498447 stable

topic: internal config option to fix hg pick behavior (issue6406) After some consideration, hg pick was made to always use current topic (and topic namespace), even if it's not set, in which case the resulting changeset will not have any topic. Previously the intended behavior was to only update topic if there was an active topic, and not touch commit extras at all otherwise. That wasn't ideal, since pick doesn't change active topic, and amending the just-picked commit would unset its topic without clear user's intent to do so and to their surprise.
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 27 Jan 2024 17:36:39 -0300
parents 968b9651b1f7
children d3668c704d40
files hgext3rd/evolve/cmdrewrite.py hgext3rd/topic/__init__.py tests/test-pick.t tests/test-topic-issue6406.t
diffstat 4 files changed, 39 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/cmdrewrite.py	Wed Dec 13 15:44:30 2023 -0300
+++ b/hgext3rd/evolve/cmdrewrite.py	Sat Jan 27 17:36:39 2024 -0300
@@ -1354,7 +1354,8 @@
 def cmdpick(ui, repo, *revs, **opts):
     """move a commit onto the working directory parent and update to it.
 
-    If there is an active topic, it will be used for the resulting changeset.
+    The resulting changeset will have the current active topic. If there's no
+    active topic set, the resulting changeset will also not have any topic.
     """
 
     cont = opts.get('continue')
@@ -1416,7 +1417,10 @@
 
 def _dopick(ui, repo, pickstate, origctx):
     """shared logic for performing or continuing a pick"""
-    overrides = {(b'phases', b'new-commit'): origctx.phase()}
+    overrides = {
+        (b'phases', b'new-commit'): origctx.phase(),
+        (b'_internal', b'topic-source'): b'local',
+    }
     new_desc = evolvecmd._rewrite_commit_message_hashes(repo,
                                                         origctx.description())
     with repo.ui.configoverride(overrides, b'pick'):
--- a/hgext3rd/topic/__init__.py	Wed Dec 13 15:44:30 2023 -0300
+++ b/hgext3rd/topic/__init__.py	Sat Jan 27 17:36:39 2024 -0300
@@ -277,6 +277,12 @@
 configitem(b'_internal', b'tns-explicit-target',
            default=False,
 )
+# used for selecting what topic and topic namespace values take priority during
+# some history rewriting operations: 'local' prefers active topic and tns,
+# 'other' prefers values in commit extras, if there are any
+configitem(b'_internal', b'topic-source',
+           default=b'other',
+)
 configitem(b'devel', b'tns-report-transactions',
            default=lambda: [],
 )
@@ -671,15 +677,26 @@
                 # bypass the core "nothing changed" logic
                 configoverride = self.ui.configoverride({
                     (b'ui', b'allowemptycommit'): True
-                })
+                }, b'topic-extension')
             with configoverride:
                 return super(topicrepo, self).commit(*args, **kwargs)
 
         def commitctx(self, ctx, *args, **kwargs):
             if isinstance(ctx, context.workingcommitctx):
-                current = self.currenttopic
-                if current and constants.extrakey not in ctx.extra():
-                    ctx.extra()[constants.extrakey] = current
+                tns = self.currenttns
+                topic = self.currenttopic
+                # topic source:
+                # - 'local': we need to put currently active tns and topic into
+                #   commit extras in any case
+                # - 'other': we could use active tns and topic, but only if
+                #   commit extras don't already have them
+                ts = self.ui.config(b'_internal', b'topic-source')
+                if ts == b'local' or (tns != b'none' and b'topic-namespace' not in ctx.extra()):
+                    # default value will be dropped from extra later on
+                    ctx.extra()[b'topic-namespace'] = tns
+                if ts == b'local' or (topic and constants.extrakey not in ctx.extra()):
+                    # empty value will be dropped from extra later on
+                    ctx.extra()[constants.extrakey] = topic
             return super(topicrepo, self).commitctx(ctx, *args, **kwargs)
 
         @util.propertycache
--- a/tests/test-pick.t	Wed Dec 13 15:44:30 2023 -0300
+++ b/tests/test-pick.t	Sat Jan 27 17:36:39 2024 -0300
@@ -32,7 +32,8 @@
   
   move a commit onto the working directory parent and update to it.
   
-      If there is an active topic, it will be used for the resulting changeset.
+      The resulting changeset will have the current active topic. If there's no
+      active topic set, the resulting changeset will also not have any topic.
   
   options:
   
--- a/tests/test-topic-issue6406.t	Wed Dec 13 15:44:30 2023 -0300
+++ b/tests/test-topic-issue6406.t	Sat Jan 27 17:36:39 2024 -0300
@@ -54,7 +54,8 @@
 This is what the help text says about this issue
 
   $ hg help pick | grep 'active topic'
-      If there is an active topic, it will be used for the resulting changeset.
+      The resulting changeset will have the current active topic. If there's no
+      active topic set, the resulting changeset will also not have any topic.
 
 wdir has no active topic: pick should clear topic of the resulting cset
 
@@ -64,8 +65,7 @@
   picking 2:fcda3d8dafd2 "banana"
   1 new orphan changesets
   $ hg log -r . -T '{rev}: {desc} ({fqbn})\n'
-  4: banana (default//bbb/b-things) (known-bad-output !)
-  4: banana (default) (missing-correct-output !)
+  4: banana (default)
   $ hg debug-topic-namespace
   none
   $ hg topic --current
@@ -80,26 +80,21 @@
   marked working directory as topic: all-things
   $ hg pick 'desc("blackberry")'
   picking 3:48bbfbece8fa "blackberry"
-  active topic 'all-things' grew its first changeset (missing-correct-output !)
-  (see 'hg help topics' for more information) (missing-correct-output !)
+  active topic 'all-things' grew its first changeset
+  (see 'hg help topics' for more information)
   $ hg log -r . -T '{rev}: {desc} ({fqbn})\n'
-  5: blackberry (default//bbb/b-things) (known-bad-output !)
-  5: blackberry (default//everything/all-things) (missing-correct-output !)
+  5: blackberry (default//everything/all-things)
   $ hg debug-topic-namespace
   everything
   $ hg topic --current
   all-things
 
   $ hg log -GT '{rev}: {desc} ({fqbn})\n{join(extras, " ")}\n\n'
-  @  5: blackberry (default//bbb/b-things) (known-bad-output !)
-  |  branch=default topic=b-things topic-namespace=bbb (known-bad-output !)
-  @  5: blackberry (default//everything/all-things) (missing-correct-output !)
-  |  branch=default topic=all-things topic-namespace=everything (missing-correct-output !)
+  @  5: blackberry (default//everything/all-things)
+  |  branch=default topic=all-things topic-namespace=everything
   |
-  o  4: banana (default//bbb/b-things) (known-bad-output !)
-  |  branch=default topic=b-things topic-namespace=bbb (known-bad-output !)
-  o  4: banana (default) (missing-correct-output !)
-  |  branch=default (missing-correct-output !)
+  o  4: banana (default)
+  |  branch=default
   |
   o  1: apple (default//aaa/a-things)
   |  branch=default topic=a-things topic-namespace=aaa