changeset 6665:d2b90c9e5829 stable

uncommit: set uncommit_source extra consistently in interactive mode Previously, the uncommit_source extra was only explicitly set on the temporary changeset created during the uncommit command. Due to a contract mismatch because the extra() method returned a dict that might be reused for multiple callers and this call site expected a fresh dict, the resulting changeset produced by the uncommit command might or might not have had the correct extra nonetheless. This changeset ensures that it will be set consistently. There is a discussion whether the extra() method (in core) should always return a fresh dict. Independent of the outcome of the discussion, this fix should work. I checked that the tests work no matter whether extra() returns a fresh dict or a reused one (current core behavior).
author Manuel Jacob <me@manueljacob.de>
date Thu, 01 Feb 2024 19:13:24 +0100
parents e20841870e51
children a77b939c79e1
files hgext3rd/evolve/cmdrewrite.py tests/test-uncommit-interactive.t
diffstat 2 files changed, 63 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/cmdrewrite.py	Thu Feb 01 08:29:10 2024 +0100
+++ b/hgext3rd/evolve/cmdrewrite.py	Thu Feb 01 19:13:24 2024 +0100
@@ -540,10 +540,10 @@
     fp.seek(0)
     oldnode = node.short(old.node())
     message = b'temporary commit for uncommiting %s' % oldnode
-    tempnode = _patchtocommit(ui, repo, old, fp, message, oldnode)
+    tempnode = _patchtocommit(ui, repo, old, fp, message)
     return tempnode
 
-def _patchtocommit(ui, repo, old, fp, message=None, extras=None):
+def _patchtocommit(ui, repo, old, fp, message=None):
     """ A function which will apply the patch to the working directory and
     make a commit whose parents are same as that of old argument. The message
     argument tells us whether to use the message of the old commit or a
@@ -555,8 +555,8 @@
     branch = old.branch()
     user = old.user()
     extra = old.extra()
-    if extras:
-        extra[b'uncommit_source'] = extras
+    extra[b'uncommit_source'] = node.short(old.node())
+
     if not message:
         message = old.description()
     store = patch.filestore()
--- a/tests/test-uncommit-interactive.t	Thu Feb 01 08:29:10 2024 +0100
+++ b/tests/test-uncommit-interactive.t	Thu Feb 01 19:13:24 2024 +0100
@@ -272,7 +272,7 @@
   Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
 
   $ hg diff
-  diff -r 46e35360be47 a
+  diff -r ef651ea03f87 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,3 +1,6 @@
@@ -289,18 +289,18 @@
   +babar
 
   $ hg exp -T '{extras|json}\n'
-  {"branch": "default", "uncommit_source": "f70fb463d5bf"}
+  {"branch": "default", "uncommit_source": "678a59e5ff90"}
 
   $ hg exp
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 46e35360be473bf761bedf3d05de4a68ffd9d9f8
+  # Node ID ef651ea03f873a6d70aeeb9ac351d4f65c84fb3b
   # Parent  7733902a8d94c789ca81d866bea1893d79442db6
   another one
   
-  diff -r 7733902a8d94 -r 46e35360be47 a
+  diff -r 7733902a8d94 -r ef651ea03f87 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,5 +1,7 @@
@@ -318,9 +318,9 @@
   e9635f4beaf11f64a07ccc74684092b144c53d89 0 {7733902a8d94c789ca81d866bea1893d79442db6} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'uncommit', 'user': 'test'}
   f70fb463d5bf9f0ffd38f105521d96e9f2591bc1 678a59e5ff90754d5e94719bd82ad169be773c21 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'note': 'note on amend --extract', 'operation': 'uncommit', 'user': 'test'}
   7ca9935a62f11b39b60c7fb8861377c7d45b3e99 0 {7733902a8d94c789ca81d866bea1893d79442db6} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'uncommit', 'user': 'test'}
-  678a59e5ff90754d5e94719bd82ad169be773c21 46e35360be473bf761bedf3d05de4a68ffd9d9f8 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'note': 'testing uncommit on dirty wdir', 'operation': 'uncommit', 'user': 'test'}
+  678a59e5ff90754d5e94719bd82ad169be773c21 ef651ea03f873a6d70aeeb9ac351d4f65c84fb3b 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'note': 'testing uncommit on dirty wdir', 'operation': 'uncommit', 'user': 'test'}
   $ hg obslog
-  @  46e35360be47 (5) another one
+  @  ef651ea03f87 (5) another one
   |    amended(content) from 678a59e5ff90 using uncommit by test (Thu Jan 01 00:00:00 1970 +0000)
   |      note: testing uncommit on dirty wdir
   |
@@ -335,9 +335,9 @@
 
   $ hg amend
   $ hg exp -T '{extras|json}\n'
-  {"amend_source": "46e35360be473bf761bedf3d05de4a68ffd9d9f8", "branch": "default", "uncommit_source": "f70fb463d5bf"}
+  {"amend_source": "ef651ea03f873a6d70aeeb9ac351d4f65c84fb3b", "branch": "default", "uncommit_source": "678a59e5ff90"}
   $ glog
-  @  6:905eb2a23ea2@default(draft) another one
+  @  6:f4c93db9c5cd@default(draft) another one
   |
   o  0:7733902a8d94@default(draft) The base commit
   
@@ -369,22 +369,22 @@
   $ hg status
   A foo
   $ hg diff
-  diff -r 857367499298 foo
+  diff -r 665843692be0 foo
   --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
   @@ -0,0 +1,1 @@
   +hey
 
   $ hg exp -T '{extras|json}\n'
-  {"branch": "default", "uncommit_source": "feb6bcb52f6f"}
+  {"branch": "default", "uncommit_source": "6316d2de2cc6"}
 
   $ hg exp
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 857367499298e999b5841bb01df65f73088b5d3b
-  # Parent  905eb2a23ea2d92073419d0e19165b90d36ea223
+  # Node ID 665843692be04cb0619d8ad1f81ec31c7b33f366
+  # Parent  f4c93db9c5cde0d4ab20badcb9c514cfbf7b9e38
   Added foo
   
   $ hg amend
@@ -401,11 +401,11 @@
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 219cfe20964e93f8bb9bd82ceaa54d3b776046db
-  # Parent  42cc15efbec26c14d96d805dee2766ba91d1fd31
+  # Node ID 24fcae345f93a1161b224f849c3a9ab362f76f44
+  # Parent  3f44e16f88daf37e5798606082ae9895eb90fc4d
   Removed a
   
-  diff -r 42cc15efbec2 -r 219cfe20964e a
+  diff -r 3f44e16f88da -r 24fcae345f93 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,11 +0,0 @@
@@ -454,7 +454,7 @@
   (use 'hg prune .' to remove it)
 
   $ hg diff
-  diff -r 737487f1e5f8 a
+  diff -r 3778ffc6315b a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,11 +0,0 @@
@@ -472,28 +472,28 @@
   $ hg status
   R a
   $ hg exp -T '{extras|json}\n'
-  {"branch": "default", "uncommit_source": "219cfe20964e"}
+  {"branch": "default", "uncommit_source": "24fcae345f93"}
   $ hg exp
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 737487f1e5f853e55decb73ea31522c63e7f5980
-  # Parent  42cc15efbec26c14d96d805dee2766ba91d1fd31
+  # Node ID 3778ffc6315b9cefdb01c218413677c23bf5bc9f
+  # Parent  3f44e16f88daf37e5798606082ae9895eb90fc4d
   Removed a
   
 
   $ hg prune .
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  working directory is now at 42cc15efbec2
+  working directory is now at 3f44e16f88da
   1 changesets pruned
   $ hg revert --all
   undeleting a
 
   $ glog
-  @  10:42cc15efbec2@default(draft) Added foo
+  @  10:3f44e16f88da@default(draft) Added foo
   |
-  o  6:905eb2a23ea2@default(draft) another one
+  o  6:f4c93db9c5cd@default(draft) another one
   |
   o  0:7733902a8d94@default(draft) The base commit
   
@@ -535,25 +535,25 @@
   
 
   $ hg exp -T '{extras|json}\n'
-  {"branch": "default", "uncommit_source": "0ff0d9a6d4be"}
+  {"branch": "default", "uncommit_source": "9260adff7488"}
 
   $ hg exp
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 25a080d13cb23dbd014839f54d99a96e57ba7e9b
-  # Parent  42cc15efbec26c14d96d805dee2766ba91d1fd31
+  # Node ID 5fcbf1c538b13186c920c63ca6a7dab443ad6663
+  # Parent  3f44e16f88daf37e5798606082ae9895eb90fc4d
   Added x
   
-  diff -r 42cc15efbec2 -r 25a080d13cb2 x
+  diff -r 3f44e16f88da -r 5fcbf1c538b1 x
   --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   +++ b/x	Thu Jan 01 00:00:00 1970 +0000
   @@ -0,0 +1,1 @@
   +abcd
 
   $ hg diff
-  diff -r 25a080d13cb2 foo
+  diff -r 5fcbf1c538b1 foo
   --- a/foo	Thu Jan 01 00:00:00 1970 +0000
   +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,1 +1,2 @@
@@ -570,15 +570,15 @@
 =====================================================
 
   $ glog
-  @  16:25a080d13cb2@default(draft) Added x
+  @  16:5fcbf1c538b1@default(draft) Added x
   |
-  o  10:42cc15efbec2@default(draft) Added foo
+  o  10:3f44e16f88da@default(draft) Added foo
   |
-  o  6:905eb2a23ea2@default(draft) another one
+  o  6:f4c93db9c5cd@default(draft) another one
   |
   o  0:7733902a8d94@default(draft) The base commit
   
-  $ hg up 905eb2a23ea2
+  $ hg up f4c93db9c5cd
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
 
   $ touch bar
@@ -589,18 +589,18 @@
   ? foo.orig
 
   $ hg exp -T '{extras|json}\n'
-  {"amend_source": "46e35360be473bf761bedf3d05de4a68ffd9d9f8", "branch": "default", "uncommit_source": "f70fb463d5bf"}
+  {"amend_source": "ef651ea03f873a6d70aeeb9ac351d4f65c84fb3b", "branch": "default", "uncommit_source": "678a59e5ff90"}
 
   $ hg exp
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 905eb2a23ea2d92073419d0e19165b90d36ea223
+  # Node ID f4c93db9c5cde0d4ab20badcb9c514cfbf7b9e38
   # Parent  7733902a8d94c789ca81d866bea1893d79442db6
   another one
   
-  diff -r 7733902a8d94 -r 905eb2a23ea2 a
+  diff -r 7733902a8d94 -r f4c93db9c5cd a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,5 +1,11 @@
@@ -660,7 +660,7 @@
   2 new orphan changesets
 
   $ hg diff
-  diff -r 676366511f95 a
+  diff -r 98a3d38b1b81 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -8,3 +8,4 @@
@@ -668,25 +668,25 @@
    4
    5
   +babar
-  diff -r 676366511f95 bar
+  diff -r 98a3d38b1b81 bar
   --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   +++ b/bar	Thu Jan 01 00:00:00 1970 +0000
   @@ -0,0 +1,1 @@
   +foo
 
   $ hg exp -T '{extras|json}\n'
-  {"amend_source": "46e35360be473bf761bedf3d05de4a68ffd9d9f8", "branch": "default", "uncommit_source": "f70fb463d5bf"}
+  {"amend_source": "ef651ea03f873a6d70aeeb9ac351d4f65c84fb3b", "branch": "default", "uncommit_source": "f4c93db9c5cd"}
 
   $ hg exp
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 676366511f95ca4122413dcf79b45eaab61fb387
+  # Node ID 98a3d38b1b812aeca00a61a5554dfa228d632b9e
   # Parent  7733902a8d94c789ca81d866bea1893d79442db6
   another one
   
-  diff -r 7733902a8d94 -r 676366511f95 a
+  diff -r 7733902a8d94 -r 98a3d38b1b81 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,5 +1,10 @@
@@ -741,18 +741,18 @@
   
 
   $ hg exp -T '{extras|json}\n'
-  {"amend_source": "46e35360be473bf761bedf3d05de4a68ffd9d9f8", "branch": "default", "uncommit_source": "f70fb463d5bf"}
+  {"amend_source": "ef651ea03f873a6d70aeeb9ac351d4f65c84fb3b", "branch": "default", "uncommit_source": "98a3d38b1b81"}
 
   $ hg exp
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 62d907d0c4fa13b4b8bfeed05f13751035daf963
+  # Node ID 9c6818648d9e694d2decfde377c6821191c5bfd5
   # Parent  7733902a8d94c789ca81d866bea1893d79442db6
   another one
   
-  diff -r 7733902a8d94 -r 62d907d0c4fa a
+  diff -r 7733902a8d94 -r 9c6818648d9e a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,5 +1,7 @@
@@ -765,7 +765,7 @@
    5
 
   $ hg diff
-  diff -r 62d907d0c4fa a
+  diff -r 9c6818648d9e a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,3 +1,6 @@
@@ -780,7 +780,7 @@
    4
    5
   +babar
-  diff -r 62d907d0c4fa bar
+  diff -r 9c6818648d9e bar
   --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   +++ b/bar	Thu Jan 01 00:00:00 1970 +0000
   @@ -0,0 +1,1 @@
@@ -818,11 +818,11 @@
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID be5c67225e80b050867862bbd9f4755c4e9207c5
-  # Parent  c280a907fddcef2ffe9fadcc2d87f29998e22b2f
+  # Node ID bbdfefb59fb08650a9a663367ab18a3c2d072691
+  # Parent  4f15d398b049b07eb4f4c98d3466a7f708e61735
   some more changes
   
-  diff -r c280a907fddc -r be5c67225e80 a
+  diff -r 4f15d398b049 -r bbdfefb59fb0 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -9,3 +9,4 @@
@@ -830,7 +830,7 @@
    5
    babar
   +celeste
-  diff -r c280a907fddc -r be5c67225e80 b
+  diff -r 4f15d398b049 -r bbdfefb59fb0 b
   --- a/b	Thu Jan 01 00:00:00 1970 +0000
   +++ b/b	Thu Jan 01 00:00:00 1970 +0000
   @@ -5,3 +5,4 @@
@@ -856,7 +856,7 @@
   M a
   ? foo.orig
   $ hg diff
-  diff -r c701d7c8d18b a
+  diff -r 0873ba67273f a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -9,3 +9,4 @@
@@ -865,17 +865,17 @@
    babar
   +celeste
   $ hg exp -T '{extras|json}\n'
-  {"branch": "default", "uncommit_source": "be5c67225e80"}
+  {"branch": "default", "uncommit_source": "bbdfefb59fb0"}
   $ hg export
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID c701d7c8d18be55a92688f4458c26bd74fb1f525
-  # Parent  c280a907fddcef2ffe9fadcc2d87f29998e22b2f
+  # Node ID 0873ba67273ff5654e032c98df89be8cf431cb63
+  # Parent  4f15d398b049b07eb4f4c98d3466a7f708e61735
   some more changes
   
-  diff -r c280a907fddc -r c701d7c8d18b b
+  diff -r 4f15d398b049 -r 0873ba67273f b
   --- a/b	Thu Jan 01 00:00:00 1970 +0000
   +++ b/b	Thu Jan 01 00:00:00 1970 +0000
   @@ -5,3 +5,4 @@
@@ -932,7 +932,7 @@
   ? foo.orig
 
   $ hg diff
-  diff -r 28d5de12b225 a
+  diff -r 72c07d186be7 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,3 +1,4 @@
@@ -942,18 +942,18 @@
    0
 
   $ hg exp -T '{extras|json}\n'
-  {"amend_source": "c701d7c8d18be55a92688f4458c26bd74fb1f525", "branch": "default", "uncommit_source": "be5c67225e80"}
+  {"amend_source": "0873ba67273ff5654e032c98df89be8cf431cb63", "branch": "default", "uncommit_source": "14428547a95c"}
 
   $ hg export
   # HG changeset patch
   # User test
   # Date 0 0
   #      Thu Jan 01 00:00:00 1970 +0000
-  # Node ID 28d5de12b225d1e0951110cced8d8994227be026
-  # Parent  c280a907fddcef2ffe9fadcc2d87f29998e22b2f
+  # Node ID 72c07d186be791e6fa80bfdaf85f493dca503df2
+  # Parent  4f15d398b049b07eb4f4c98d3466a7f708e61735
   some more changes
   
-  diff -r c280a907fddc -r 28d5de12b225 a
+  diff -r 4f15d398b049 -r 72c07d186be7 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -9,3 +9,4 @@
@@ -961,7 +961,7 @@
    5
    babar
   +celeste
-  diff -r c280a907fddc -r 28d5de12b225 b
+  diff -r 4f15d398b049 -r 72c07d186be7 b
   --- a/b	Thu Jan 01 00:00:00 1970 +0000
   +++ b/b	Thu Jan 01 00:00:00 1970 +0000
   @@ -5,3 +5,4 @@