[PATCH] histedit: preserve initial author on fold (issue4296)

Martin von Zweigbergk martinvonz at gmail.com
Wed Aug 13 18:19:34 CDT 2014


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at gmail.com>
# Date 1407955813 25200
#      Wed Aug 13 11:50:13 2014 -0700
# Node ID 0aef7208369ce43569a1795e1e437dedf11276d1
# Parent  44d6818b9cd9db2c209a09dd162ef2fd745271e8
histedit: preserve initial author on fold (issue4296)

When the authorship of the changeset folded in does not match that of
the base changeset, we currently use the configured ui.username
instead. This is especially surprising when the user is not the author
of either of the changesets. In such cases, the resulting authorship
(the user's) is clearly incorrect. Even when the user is folding in a
patch they authored themselves, it's not clear whether they should
take over the authorship. Let's instead keep it simple and always
preserve the base changeset's authorship. This is also how
"git rebase -i" handles folding/squashing.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -353,12 +353,7 @@
     hg.update(repo, parent)
     ### prepare new commit data
     commitopts = opts.copy()
-    # username
-    if ctx.user() == oldctx.user():
-        username = ctx.user()
-    else:
-        username = ui.username()
-    commitopts['user'] = username
+    commitopts['user'] = ctx.user()
     # commit message
     newmessage = '\n***\n'.join(
         [ctx.description()] +
diff --git a/tests/test-histedit-fold.t b/tests/test-histedit-fold.t
--- a/tests/test-histedit-fold.t
+++ b/tests/test-histedit-fold.t
@@ -169,6 +169,44 @@
   check saving last-message.txt
 
   $ cd ..
+  $ rm -r r
+
+folding preserves initial author
+--------------------------------
+
+  $ initrepo
+
+  $ hg ci --user "someone else" --amend --quiet
+
+tip before edit
+  $ hg log --rev .
+  changeset:   5:a00ad806cb55
+  tag:         tip
+  user:        someone else
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     f
+  
+
+  $ hg histedit e860deea161a --commands - 2>&1 <<EOF | fixbundle
+  > pick e860deea161a e
+  > fold a00ad806cb55 f
+  > EOF
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+tip after edit
+  $ hg log --rev .
+  changeset:   4:698d4e8040a1
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     e
+  
+
+  $ cd ..
+  $ rm -r r
 
 folding and creating no new change doesn't break:
 -------------------------------------------------


More information about the Mercurial-devel mailing list