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

taapas1128 (Taapas Agrawal) phabricator at mercurial-scm.org
Thu Jan 10 15:39:54 UTC 2019


taapas1128 created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS

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
@@ -597,3 +597,131 @@
   o  8f0162e483d0 aa
   
 
+
+-==========================================
+Test update-timestamp config option|
+==========================================
+  $ cat >> testmocks.py << EOF
+  > # mock out util.makedate() to supply testable values
+  > import os
+  > from mercurial import pycompat, util
+  > 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
+  > EOF
+
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > histedit=
+  > testmocks=`pwd`/testmocks.py
+  > EOF
+
+  $ 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
+
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -210,6 +210,7 @@
     util,
 )
 from mercurial.utils import (
+    dateutil,
     stringutil,
 )
 
@@ -519,9 +520,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."""
@@ -800,6 +804,8 @@
         # date
         if self.firstdate():
             commitopts['date'] = ctx.date()
+        elif ui.configbool('rewrite','update-timestamp'):
+            commitopts['date'] = dateutil.makedate()
         else:
             commitopts['date'] = max(ctx.date(), oldctx.date())
         extra = ctx.extra().copy()



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


More information about the Mercurial-devel mailing list