Patchwork D5554: histedit: added rewrite.update-timestamp to fold and mess

login
register
mail settings
Submitter phabricator
Date Jan. 13, 2019, 12:14 p.m.
Message ID <ef40af1cc4679ba686d1b954de5ff5d9@localhost.localdomain>
Download mbox | patch
Permalink /patch/37713/
State Not Applicable
Headers show

Comments

phabricator - Jan. 13, 2019, 12:14 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG6459797090ea: histedit: add rewrite.update-timestamp support to fold and mess (authored by taapas1128, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D5554?vs=13201&id=13202#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5554?vs=13201&id=13202

REVISION DETAIL
  https://phab.mercurial-scm.org/D5554

AFFECTED FILES
  hgext/histedit.py
  tests/mockmakedate.py
  tests/test-histedit-edit.t
  tests/test-histedit-fold.t

CHANGE DETAILS




To: taapas1128, durin42, #hg-reviewers
Cc: yuja, pulkit, mercurial-devel

Patch

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
@@ -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 ..
diff --git a/tests/test-histedit-edit.t b/tests/test-histedit-edit.t
--- a/tests/test-histedit-edit.t
+++ b/tests/test-histedit-edit.t
@@ -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
diff --git a/tests/mockmakedate.py b/tests/mockmakedate.py
new file mode 100644
--- /dev/null
+++ b/tests/mockmakedate.py
@@ -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
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -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