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.
Details
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
+ $ 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 @@
- 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?
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 @@
- 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.
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.