Patchwork [evolve-ext,v2] amend: add -D/--current-date option, just like mq's qrefresh has

login
register
mail settings
Submitter Greg Ward
Date June 6, 2014, 9:46 p.m.
Message ID <55120667dfbf503623c2.1402091208@lucifer.gerg.ca>
Download mbox | patch
Permalink /patch/4945/
State Accepted
Headers show

Comments

Greg Ward - June 6, 2014, 9:46 p.m.
# HG changeset patch
# User Greg Ward <greg@gerg.ca>
# Date 1402091025 14400
#      Fri Jun 06 17:43:45 2014 -0400
# Node ID 55120667dfbf503623c25e65030535b32e56e150
# Parent  09d6036ad59685a8713d1a9e3435f3e0fd286d72
amend: add -D/--current-date option, just like mq's qrefresh has

Carefully designed so we can easily add -D to other changeset-creating
commands (probably anything that takes -d), and so that we can add
-U/--current-user as well. When that's done, the date and user options
should be very similar to those in MQ.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -325,6 +325,21 @@ 
 ### experimental behavior                                         ###
 #####################################################################
 
+commitopts3 = [
+    ('D', 'current-date', None,
+     _('record the current date as commit date')),
+]
+
+def _resolveoptions(opts):
+    """modify commit options dict to handle related options
+
+    For now, all it does is figure out the commit date: respect -D unless
+    -d was supplied.
+    """
+    # N.B. this is extremely similar to setupheaderopts() in mq.py
+    if not opts.get('date') and opts.get('current_date'):
+        opts['date'] = '%d %d' % util.makedate()
+
 @eh.wrapfunction(mercurial.obsolete, 'createmarkers')
 def _createmarkers(orig, repo, relations, *args, **kwargs):
     """register parent information at prune time"""
@@ -1795,7 +1810,7 @@ 
     ('', 'close-branch', None,
      _('mark a branch as closed, hiding it from the branch list')),
     ('s', 'secret', None, _('use the secret phase for committing')),
-    ] + walkopts + commitopts + commitopts2,
+    ] + walkopts + commitopts + commitopts2 + commitopts3,
     _('[OPTION]... [FILE]...'))
 def amend(ui, repo, *pats, **opts):
     """combine a changeset with updates and replace it with a new one
@@ -1820,6 +1835,7 @@ 
     opts['amend'] = True
     if not (edit or opts['message']):
         opts['message'] = repo['.'].description()
+    _resolveoptions(opts)
     _alias, commitcmd = cmdutil.findcmd('commit', commands.table)
     return commitcmd[0](ui, repo, *pats, **opts)
 
diff --git a/tests/test-amend.t b/tests/test-amend.t
--- a/tests/test-amend.t
+++ b/tests/test-amend.t
@@ -83,3 +83,12 @@ 
   $ hg parents --template '{rev}  {date|date}\n'
   5  Sat Feb 03 04:05:06 2001 +0700
 
+Specify "now" as commit date with -D
+  $ before=`date +%s`
+  $ hg amend -D
+  $ commit=`hg parents --template '{date|hgdate} rev{rev}\n'`
+  $ after=`date +%s`
+  $ (echo $before ; echo $commit; echo $after) | sort -k1 -n -s
+  \d+ (re)
+  \d+ 0 rev6 (re)
+  \d+ (re)