Page MenuHomePhabricator

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

Authored by taapas1128 on Jan 10 2019, 10:39 AM.

Details

Summary

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.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

taapas1128 created this revision.Jan 10 2019, 10:39 AM
taapas1128 edited the summary of this revision. (Show Details)EditedJan 10 2019, 10:43 AM
taapas1128 added a subscriber: pulkit.

@pulkit please review.

yuja added a subscriber: yuja.Jan 12 2019, 8:55 PM

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

Perhaps, it's time to extract the mockmakedate extension to
tests/mockmakedate.py.

@@ -519,9 +520,12 @@

editor = self.commiteditor()
commit = commitfuncfor(repo, rulectx)

+ if repo.ui.configbool('rewrite','update-timestamp'):

Style nit: insert space after comma.

+ date = dateutil.makedate()
+ else :

and no space after else.

def commiteditor(self):
    """The editor to be used to edit the commit message."""

@@ -800,6 +804,8 @@

  1. 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())

I'm not pretty sure, but shouldn't we always update the date if update-timestamp
is on?

taapas1128 updated this revision to Diff 13197.Jan 13 2019, 1:47 AM
taapas1128 updated this revision to Diff 13198.Jan 13 2019, 1:51 AM
taapas1128 updated this revision to Diff 13199.Jan 13 2019, 2:10 AM
taapas1128 updated this revision to Diff 13200.Jan 13 2019, 2:34 AM
taapas1128 added a comment.EditedJan 13 2019, 2:38 AM

I have extracted mockdate function as tests/mockdate.py and dealt with the commas and spaces.

def commiteditor(self):
    """The editor to be used to edit the commit message."""

@@ -800,6 +804,8 @@

  1. 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())

Yes this is not right time should be updated everytime update-timestamp is True . I have corrected it. @yuja please review.

taapas1128 edited the summary of this revision. (Show Details)Jan 13 2019, 2:42 AM
taapas1128 edited the summary of this revision. (Show Details)Jan 13 2019, 2:46 AM
taapas1128 edited the summary of this revision. (Show Details)Jan 13 2019, 2:49 AM
taapas1128 updated this revision to Diff 13201.
taapas1128 edited the summary of this revision. (Show Details)Jan 13 2019, 2:52 AM
yuja added a comment.Jan 13 2019, 7:14 AM

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.

This revision was automatically updated to reflect the committed changes.

@yuja thanks for the edits and queuing .