changeset 31056:37ab9e20991c

histedit: modify rollup to discard date from the rollup commit (issue4820) This change adjusts and documents the new behaviour of 'roll'. It now fits nicely with the behaviour of 'commit --amend' and the 'edit' action, by discarding the date as well as the commit message of the second commit. Previously it used the later date, like 'fold', but this often wasn't desirable, for example, in the common use case of using 'roll' to add forgotten changes to a changeset (because 'hg add' was previously forgotten or not all changes were identified while using 'hg record').
author Ben Schmidt <insightfuls@users.noreply.github.com>
date Sat, 18 Feb 2017 21:30:28 +1100
parents f1b63ec4b987
children 16d7db8f752c
files hgext/histedit.py tests/test-histedit-arguments.t tests/test-histedit-bookmark-motion.t tests/test-histedit-commute.t tests/test-histedit-edit.t tests/test-histedit-fold-non-commute.t tests/test-histedit-fold.t tests/test-histedit-obsolete.t tests/test-histedit-outgoing.t
diffstat 9 files changed, 48 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Sat Feb 18 21:30:28 2017 +1100
+++ b/hgext/histedit.py	Sat Feb 18 21:30:28 2017 +1100
@@ -36,7 +36,7 @@
  #  p, pick = use commit
  #  e, edit = use commit, but stop for amending
  #  f, fold = use commit, but combine it with the one above
- #  r, roll = like fold, but discard this commit's description
+ #  r, roll = like fold, but discard this commit's description and date
  #  d, drop = remove commit from history
  #  m, mess = edit commit message without changing commit content
  #
@@ -58,7 +58,7 @@
  #  p, pick = use commit
  #  e, edit = use commit, but stop for amending
  #  f, fold = use commit, but combine it with the one above
- #  r, roll = like fold, but discard this commit's description
+ #  r, roll = like fold, but discard this commit's description and date
  #  d, drop = remove commit from history
  #  m, mess = edit commit message without changing commit content
  #
@@ -725,6 +725,15 @@
         """
         return True
 
+    def firstdate(self):
+        """Returns true if the rule should preserve the date of the first
+        change.
+
+        This exists mainly so that 'rollup' rules can be a subclass of
+        'fold'.
+        """
+        return False
+
     def finishfold(self, ui, repo, ctx, oldctx, newnode, internalchanges):
         parent = ctx.parents()[0].node()
         repo.ui.pushbuffer()
@@ -743,7 +752,10 @@
                 [oldctx.description()]) + '\n'
         commitopts['message'] = newmessage
         # date
-        commitopts['date'] = max(ctx.date(), oldctx.date())
+        if self.firstdate():
+            commitopts['date'] = ctx.date()
+        else:
+            commitopts['date'] = max(ctx.date(), oldctx.date())
         extra = ctx.extra().copy()
         # histedit_source
         # note: ctx is likely a temporary commit but that the best we can do
@@ -810,7 +822,7 @@
         return True
 
 @action(["roll", "r"],
-        _("like fold, but discard this commit's description"))
+        _("like fold, but discard this commit's description and date"))
 class rollup(fold):
     def mergedescs(self):
         return False
@@ -818,6 +830,9 @@
     def skipprompt(self):
         return True
 
+    def firstdate(self):
+        return True
+
 @action(["drop", "d"],
         _('remove commit from history'))
 class drop(histeditaction):
@@ -887,7 +902,7 @@
 
     - `fold` to combine it with the preceding changeset (using the later date)
 
-    - `roll` like fold, but discarding this commit's description
+    - `roll` like fold, but discarding this commit's description and date
 
     - `edit` to edit this changeset (preserving date)
 
--- a/tests/test-histedit-arguments.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-arguments.t	Sat Feb 18 21:30:28 2017 +1100
@@ -72,7 +72,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
 
 Run on a revision not ancestors of the current working directory.
@@ -308,7 +308,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
 
 Test --continue with --keep
@@ -544,7 +544,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
 
   $ cd ..
--- a/tests/test-histedit-bookmark-motion.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-bookmark-motion.t	Sat Feb 18 21:30:28 2017 +1100
@@ -78,7 +78,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
   $ hg histedit 1 --commands - --verbose << EOF | grep histedit
   > pick 177f92b77385 2 c
@@ -141,7 +141,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
   $ hg histedit 1 --commands - --verbose << EOF | grep histedit
   > pick b346ab9a313d 1 c
--- a/tests/test-histedit-commute.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-commute.t	Sat Feb 18 21:30:28 2017 +1100
@@ -72,7 +72,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
 
 edit the history
@@ -350,7 +350,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
 
 should also work if a commit message is missing
--- a/tests/test-histedit-edit.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-edit.t	Sat Feb 18 21:30:28 2017 +1100
@@ -478,5 +478,5 @@
   #  p, fold = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
--- a/tests/test-histedit-fold-non-commute.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-fold-non-commute.t	Sat Feb 18 21:30:28 2017 +1100
@@ -183,7 +183,7 @@
 
   $ cd ..
 
-Repeat test using "roll", not "fold". "roll" folds in changes but drops message
+Repeat test using "roll", not "fold". "roll" folds in changes but drops message and date
 
   $ initrepo r2
   $ cd r2
@@ -276,15 +276,15 @@
 
 log after edit
   $ hg log --graph
-  @  changeset:   5:162978f027fb
+  @  changeset:   5:b538bcb461be
   |  tag:         tip
   |  user:        test
   |  date:        Thu Jan 01 00:00:06 1970 +0000
   |  summary:     f
   |
-  o  changeset:   4:74e5e6c6c32f
+  o  changeset:   4:317e37cb6d66
   |  user:        test
-  |  date:        Thu Jan 01 00:00:07 1970 +0000
+  |  date:        Thu Jan 01 00:00:04 1970 +0000
   |  summary:     d
   |
   o  changeset:   3:092e4ce14829
@@ -324,13 +324,13 @@
 description is taken from rollup target commit
 
   $ hg log --debug --rev 4
-  changeset:   4:74e5e6c6c32fa39f0eeed43302fd48633ea5926f
+  changeset:   4:317e37cb6d66c1c84628c00e5bf4c8c292831951
   phase:       draft
   parent:      3:092e4ce14829f4974399ce4316d59f64ef0b6725
   parent:      -1:0000000000000000000000000000000000000000
   manifest:    4:b068a323d969f22af1296ec6a5ea9384cef437ac
   user:        test
-  date:        Thu Jan 01 00:00:07 1970 +0000
+  date:        Thu Jan 01 00:00:04 1970 +0000
   files:       d e
   extra:       branch=default
   extra:       histedit_source=ae78f4c9d74ffa4b6cb5045001c303fe9204e890,42abbb61bede6f4366fa1e74a664343e5d558a70
--- a/tests/test-histedit-fold.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-fold.t	Sat Feb 18 21:30:28 2017 +1100
@@ -106,7 +106,7 @@
   
   
 
-rollup will fold without preserving the folded commit's message
+rollup will fold without preserving the folded commit's message or date
 
   $ OLDHGEDITOR=$HGEDITOR
   $ HGEDITOR=false
@@ -121,11 +121,11 @@
 
 log after edit
   $ hg logt --graph
-  @  3:fb13f1f49340 d
+  @  3:bab801520cec d
   |
-  o  2:6d4bc3727566 f
+  o  2:58c8f2bfc151 f
   |
-  o  1:563995ddbe65 b
+  o  1:5d939c56c72e b
   |
   o  0:8580ff50825a a
   
@@ -133,13 +133,13 @@
 description is taken from rollup target commit
 
   $ hg log --debug --rev 1
-  changeset:   1:563995ddbe650c0e6b0e1c1d75f0a197b61cec50
+  changeset:   1:5d939c56c72e77e29f5167696218e2131a40f5cf
   phase:       draft
   parent:      0:8580ff50825a50c8f716709acdf8de0deddcd6ab
   parent:      -1:0000000000000000000000000000000000000000
   manifest:    1:b5e112a3a8354e269b1524729f0918662d847c38
   user:        test
-  date:        Thu Jan 01 00:00:05 1970 +0000
+  date:        Thu Jan 01 00:00:02 1970 +0000
   files+:      b e
   extra:       branch=default
   extra:       histedit_source=97d72e5f12c7e84f85064aa72e5a297142c36ed9,505a591af19eed18f560af827b9e03d2076773dc
@@ -171,13 +171,13 @@
   > EOF
 
   $ rm -f .hg/last-message.txt
-  $ hg status --rev '6d4bc3727566^1::fb13f1f49340'
+  $ hg status --rev '58c8f2bfc151^1::bab801520cec'
   A c
   A d
   A f
-  $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit 6d4bc3727566 --commands - 2>&1 <<EOF
-  > pick 6d4bc3727566 f
-  > fold fb13f1f49340 d
+  $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit 58c8f2bfc151 --commands - 2>&1 <<EOF
+  > pick 58c8f2bfc151 f
+  > fold bab801520cec d
   > EOF
   allow non-folding commit
   ==== before editing
--- a/tests/test-histedit-obsolete.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-obsolete.t	Sat Feb 18 21:30:28 2017 +1100
@@ -136,7 +136,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
   $ hg histedit 1 --commands - --verbose <<EOF | grep histedit
   > pick 177f92b77385 2 c
--- a/tests/test-histedit-outgoing.t	Sat Feb 18 21:30:28 2017 +1100
+++ b/tests/test-histedit-outgoing.t	Sat Feb 18 21:30:28 2017 +1100
@@ -54,7 +54,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
   $ cd ..
 
@@ -88,7 +88,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
   $ cd ..
 
@@ -114,7 +114,7 @@
   #  p, pick = use commit
   #  d, drop = remove commit from history
   #  f, fold = use commit, but combine it with the one above
-  #  r, roll = like fold, but discard this commit's description
+  #  r, roll = like fold, but discard this commit's description and date
   #
 
 test to check number of roots in outgoing revisions