histedit: add rewrite.update-timestamp support to fold and mess
authorTaapas Agrawal <taapas2897@gmail.com>
Thu, 10 Jan 2019 20:11:19 +0530
changeset 41213 704a3aa3dc0a
parent 41212 240f8e49a7bd
child 41214 8633c716f908
histedit: add rewrite.update-timestamp support to fold and mess This adds the config option to update time to current in histedit fold and mess options. Setting rewrite.update-timestamp option to `True` will update the timestamp to current time. This also adds `tests/mockmakedate.py` for supplying testable values in case current time is invoked in the tests. Differential Revision: https://phab.mercurial-scm.org/D5554
hgext/histedit.py
tests/mockmakedate.py
tests/test-histedit-edit.t
tests/test-histedit-fold.t
--- a/hgext/histedit.py	Sun Jan 13 14:46:15 2019 +0900
+++ b/hgext/histedit.py	Thu Jan 10 20:11:19 2019 +0530
@@ -220,6 +220,7 @@
     util,
 )
 from mercurial.utils import (
+    dateutil,
     stringutil,
 )
 
@@ -527,9 +528,12 @@
 
         editor = self.commiteditor()
         commit = commitfuncfor(repo, rulectx)
-
+        if repo.ui.configbool('rewrite', 'update-timestamp'):
+            date = dateutil.makedate()
+        else:
+            date = rulectx.date()
         commit(text=rulectx.description(), user=rulectx.user(),
-               date=rulectx.date(), extra=rulectx.extra(), editor=editor)
+               date=date, extra=rulectx.extra(), editor=editor)
 
     def commiteditor(self):
         """The editor to be used to edit the commit message."""
@@ -810,6 +814,10 @@
             commitopts['date'] = ctx.date()
         else:
             commitopts['date'] = max(ctx.date(), oldctx.date())
+        # if date is to be updated to current
+        if ui.configbool('rewrite', 'update-timestamp'):
+            commitopts['date'] = dateutil.makedate()
+
         extra = ctx.extra().copy()
         # histedit_source
         # note: ctx is likely a temporary commit but that the best we can do
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mockmakedate.py	Thu Jan 10 20:11:19 2019 +0530
@@ -0,0 +1,21 @@
+# mock out util.makedate() to supply testable values
+
+from __future__ import absolute_import
+
+import os
+
+from mercurial import pycompat
+from mercurial.utils import dateutil
+
+def mockmakedate():
+    filename = os.path.join(os.environ['TESTTMP'], 'testtime')
+    try:
+        with open(filename, 'rb') as timef:
+            time = float(timef.read()) + 1
+    except IOError:
+        time = 0.0
+    with open(filename, 'wb') as timef:
+        timef.write(pycompat.bytestr(time))
+    return (time, 0)
+
+dateutil.makedate = mockmakedate
--- a/tests/test-histedit-edit.t	Sun Jan 13 14:46:15 2019 +0900
+++ b/tests/test-histedit-edit.t	Thu Jan 10 20:11:19 2019 +0530
@@ -4,6 +4,7 @@
   > [extensions]
   > histedit=
   > strip=
+  > mockmakedate = $TESTDIR/mockmakedate.py
   > EOF
 
   $ initrepo ()
@@ -484,6 +485,56 @@
 
   $ cd ..
 
+============================================
+Test update-timestamp config option in mess|
+============================================
+
+  $ addwithdate ()
+  > {
+  >     echo $1 > $1
+  >     hg add $1
+  >     hg ci -m $1 -d "$2 0"
+  > }
+
+  $ initrepo ()
+  > {
+  >     hg init r2
+  >     cd r2
+  >     addwithdate a 1
+  >     addwithdate b 2
+  >     addwithdate c 3
+  >     addwithdate d 4
+  >     addwithdate e 5
+  >     addwithdate f 6
+  > }
+
+  $ initrepo
+
+log before edit
+
+  $ hg log --limit 1
+  changeset:   5:178e35e0ce73
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:06 1970 +0000
+  summary:     f
+  
+  $ hg histedit tip --commands - 2>&1 --config rewrite.update-timestamp=True << EOF | fixbundle
+  > mess 178e35e0ce73 f
+  > EOF
+
+log after edit
+
+  $ hg log --limit 1
+  changeset:   5:98bf456d476b
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     f
+  
+
+  $ cd ..
+
 warn the user on editing tagged commits
 
   $ hg init issue4017
--- a/tests/test-histedit-fold.t	Sun Jan 13 14:46:15 2019 +0900
+++ b/tests/test-histedit-fold.t	Thu Jan 10 20:11:19 2019 +0530
@@ -15,6 +15,7 @@
   > logt = log --template '{rev}:{node|short} {desc|firstline}\n'
   > [extensions]
   > histedit=
+  > mockmakedate = $TESTDIR/mockmakedate.py
   > EOF
 
 
@@ -597,3 +598,110 @@
   o  8f0162e483d0 aa
   
 
+  $ cd ..
+
+====================================
+Test update-timestamp config option|
+====================================
+
+  $ addwithdate ()
+  > {
+  >     echo $1 > $1
+  >     hg add $1
+  >     hg ci -m $1 -d "$2 0"
+  > }
+
+  $ initrepo ()
+  > {
+  >     hg init r
+  >     cd r
+  >     addwithdate a 1
+  >     addwithdate b 2
+  >     addwithdate c 3
+  >     addwithdate d 4
+  >     addwithdate e 5
+  >     addwithdate f 6
+  > }
+
+  $ initrepo
+
+log before edit
+
+  $ hg log
+  changeset:   5:178e35e0ce73
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:06 1970 +0000
+  summary:     f
+  
+  changeset:   4:1ddb6c90f2ee
+  user:        test
+  date:        Thu Jan 01 00:00:05 1970 +0000
+  summary:     e
+  
+  changeset:   3:532247a8969b
+  user:        test
+  date:        Thu Jan 01 00:00:04 1970 +0000
+  summary:     d
+  
+  changeset:   2:ff2c9fa2018b
+  user:        test
+  date:        Thu Jan 01 00:00:03 1970 +0000
+  summary:     c
+  
+  changeset:   1:97d72e5f12c7
+  user:        test
+  date:        Thu Jan 01 00:00:02 1970 +0000
+  summary:     b
+  
+  changeset:   0:8580ff50825a
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     a
+  
+
+  $ hg histedit 1ddb6c90f2ee --commands - 2>&1 --config rewrite.update-timestamp=True <<EOF | fixbundle
+  > pick 178e35e0ce73 f
+  > fold 1ddb6c90f2ee e
+  > EOF
+
+log after edit
+observe time from f is updated
+
+  $ hg log
+  changeset:   4:f7909b1863a2
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     f
+  
+  changeset:   3:532247a8969b
+  user:        test
+  date:        Thu Jan 01 00:00:04 1970 +0000
+  summary:     d
+  
+  changeset:   2:ff2c9fa2018b
+  user:        test
+  date:        Thu Jan 01 00:00:03 1970 +0000
+  summary:     c
+  
+  changeset:   1:97d72e5f12c7
+  user:        test
+  date:        Thu Jan 01 00:00:02 1970 +0000
+  summary:     b
+  
+  changeset:   0:8580ff50825a
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     a
+  
+post-fold manifest
+  $ hg manifest
+  a
+  b
+  c
+  d
+  e
+  f
+
+  $ cd ..