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

login
register
mail settings
Submitter phabricator
Date Jan. 13, 2019, 7:49 a.m.
Message ID <7c3ac540c4e10bae85a0ffb0ec28380e@localhost.localdomain>
Download mbox | patch
Permalink /patch/37711/
State Not Applicable
Headers show

Comments

phabricator - Jan. 13, 2019, 7:49 a.m.
taapas1128 updated this revision to Diff 13201.
taapas1128 edited the summary of this revision.

REPOSITORY
  rHG Mercurial

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

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
Yuya Nishihara - Jan. 13, 2019, 12:08 p.m.
Queued with minor modifications, thanks.

> --- 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
>  

Inserted `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

and renamed `r` to `r2` to get around name conflicts.

> +++ b/tests/mockmakedate.py
> @@ -0,0 +1,19 @@
> +from __future__ import absolute_import
> +
> +# mock out util.makedate() to supply testable values
> +import os
> +from mercurial import pycompat, util
> +from mercurial.utils import dateutil

Removed unused import of `util`.
phabricator - Jan. 13, 2019, 12:14 p.m.
yuja added a comment.


  Queued with minor modifications, thanks.
  
  > - 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
  
  Inserted `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
  
  and renamed `r` to `r2` to get around name conflicts.
  
  > +++ b/tests/mockmakedate.py
  >  @@ -0,0 +1,19 @@
  >  +from __future__ import absolute_import
  >  +
  >  +# mock out util.makedate() to supply testable values
  >  +import os
  >  +from mercurial import pycompat, util
  >  +from mercurial.utils import dateutil
  
  Removed unused import of `util`.

REPOSITORY
  rHG Mercurial

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

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,105 @@ 
   o  8f0162e483d0 aa
   
 
+
+-==========================================
+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
+
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 ()
@@ -481,3 +482,48 @@ 
   #  f, fold = use commit, but combine it with the one above
   #  r, roll = like fold, but discard this commit's description and date
   #
+
+
+============================================
+Test update-timestamp config option in mess|
+============================================
+  $ 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 --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
+  
diff --git a/tests/mockmakedate.py b/tests/mockmakedate.py
new file mode 100644
--- /dev/null
+++ b/tests/mockmakedate.py
@@ -0,0 +1,19 @@ 
+from __future__ import absolute_import
+
+# 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
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."""
@@ -802,6 +806,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