Patchwork D5491: amend: added config option to update time to current in hg amend(issue5828)

login
register
mail settings
Submitter phabricator
Date Jan. 7, 2019, 11:18 a.m.
Message ID <20e820aa7db80554e50fd5bfef9ca2e0@localhost.localdomain>
Download mbox | patch
Permalink /patch/37522/
State Not Applicable
Headers show

Comments

phabricator - Jan. 7, 2019, 11:18 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGec51a430ec51: amend: added config option to update time to current in hg amend(issue5828) (authored by taapas1128, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D5491?vs=13013&id=13044#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5491?vs=13013&id=13044

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

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/configitems.py
  mercurial/help/config.txt
  tests/test-amend.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-amend.t b/tests/test-amend.t
--- a/tests/test-amend.t
+++ b/tests/test-amend.t
@@ -365,3 +365,128 @@ 
   $ hg amend
 
 #endif
+==========================================
+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]
+  > amend=
+  > testmocks=`pwd`/testmocks.py
+  > EOF
+
+  $ hg init $TESTTMP/repo5
+  $ cd $TESTTMP/repo5
+  $ echo a>a
+  $ hg ci -Am 'commit 1'
+  adding a
+#if obsstore-on
+
+When updatetimestamp is False
+
+  $ hg amend --date '1997-1-1 0:1'
+  $ hg log --limit 1
+  changeset:   1:036a159be19d
+  tag:         tip
+  parent:      -1:000000000000
+  user:        test
+  date:        Wed Jan 01 00:01:00 1997 +0000
+  summary:     commit 1
+  
+ When update-timestamp is True and no other change than the date
+
+  $ hg amend --config rewrite.update-timestamp=True
+  nothing changed
+  [1]
+  $ hg log --limit 1
+  changeset:   1:036a159be19d
+  tag:         tip
+  parent:      -1:000000000000
+  user:        test
+  date:        Wed Jan 01 00:01:00 1997 +0000
+  summary:     commit 1
+  
+When update-timestamp is True and there is other change than the date
+  $ hg amend --user foobar --config rewrite.update-timestamp=True
+  $ hg log --limit 1
+  changeset:   2:3ba48b892280
+  tag:         tip
+  parent:      -1:000000000000
+  user:        foobar
+  date:        Thu Jan 01 00:00:02 1970 +0000
+  summary:     commit 1
+  
+
+When date option is applicable and update-timestamp is True
+  $ hg amend  --date '1998-1-1 0:1' --config rewrite.update-timestamp=True
+  $ hg log --limit 1
+  changeset:   3:626aee031885
+  tag:         tip
+  parent:      -1:000000000000
+  user:        foobar
+  date:        Thu Jan 01 00:01:00 1998 +0000
+  summary:     commit 1
+  
+#else
+
+When updatetimestamp is False
+
+  $ hg amend --date '1997-1-1 0:1'
+  $ hg log --limit 1
+  changeset:   0:036a159be19d
+  tag:         tip
+  user:        test
+  date:        Wed Jan 01 00:01:00 1997 +0000
+  summary:     commit 1
+  
+ When update-timestamp is True and no other change than the date
+
+  $ hg amend --config rewrite.update-timestamp=True
+  nothing changed
+  [1]
+  $ hg log --limit 1
+  changeset:   0:036a159be19d
+  tag:         tip
+  user:        test
+  date:        Wed Jan 01 00:01:00 1997 +0000
+  summary:     commit 1
+  
+When update-timestamp is True and there is other change than the date
+  $ hg amend --user foobar --config rewrite.update-timestamp=True
+  $ hg log --limit 1
+  changeset:   0:3ba48b892280
+  tag:         tip
+  user:        foobar
+  date:        Thu Jan 01 00:00:02 1970 +0000
+  summary:     commit 1
+  
+
+When date option is applicable and update-timestamp is True
+  $ hg amend  --date '1998-1-1 0:1' --config rewrite.update-timestamp=True
+  $ hg log --limit 1
+  changeset:   0:626aee031885
+  tag:         tip
+  user:        foobar
+  date:        Thu Jan 01 00:01:00 1998 +0000
+  summary:     commit 1
+  
+#endif
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1806,6 +1806,13 @@ 
 
 Alias definitions for revsets. See :hg:`help revsets` for details.
 
+``rewrite``
+-----------
+
+``update-timestamp``
+    If true updates the date and time of the changeset to current.It is only
+    applicable for hg amend in current version.
+
 ``storage``
 -----------
 
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -991,6 +991,9 @@ 
     default='1MB',
     alias=[('experimental', 'mmapindexthreshold')],
 )
+coreconfigitem('rewrite', 'update-timestamp',
+    default=False,
+)
 coreconfigitem('storage', 'new-repo-backend',
     default='revlogv1',
 )
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2443,6 +2443,12 @@ 
         user = opts.get('user') or old.user()
         date = opts.get('date') or old.date()
 
+        if ui.configbool('rewrite','update-timestamp'):
+            if opts.get('date'):
+                pass
+            else:
+                date = dateutil.makedate()
+
         # Parse the date to allow comparison between date and old.date()
         date = dateutil.parsedate(date)
 
@@ -2558,13 +2564,15 @@ 
         if ((not changes)
             and newdesc == old.description()
             and user == old.user()
-            and date == old.date()
             and pureextra == old.extra()):
             # nothing changed. continuing here would create a new node
             # anyway because of the amend_source noise.
             #
             # This not what we expect from amend.
-            return old.node()
+            if (date == old.date() or
+                (ui.configbool('rewrite','update-timestamp') and
+                not opts.get('date'))):
+                return old.node()
 
         commitphase = None
         if opts.get('secret'):