Patchwork D6853: amend: add option to update to the current user

login
register
mail settings
Submitter phabricator
Date Sept. 16, 2019, 5:56 p.m.
Message ID <d12bf6ecba148684a4bfdbbd6949dcd6@localhost.localdomain>
Download mbox | patch
Permalink /patch/41685/
State Not Applicable
Headers show

Comments

phabricator - Sept. 16, 2019, 5:56 p.m.
Closed by commit rHGe4803231f538: amend: add option to update to the current user (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6853?vs=16546&id=16555

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6853/new/

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

AFFECTED FILES
  hgext/amend.py
  mercurial/cmdutil.py
  mercurial/help/config.txt
  relnotes/next

CHANGE DETAILS




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

Patch

diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -1,5 +1,8 @@ 
 == New Features ==
 
+ * The amend extension supports the `--currentuser` argument.
+
+ * The uncommit extension supports the `rewrite.update-timestamp` config option.
 
 == New Experimental Features ==
 
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1853,7 +1853,8 @@ 
 
 ``update-timestamp``
     If true, updates the date and time of the changeset to current. It is only
-    applicable for hg amend in current version.
+    applicable for `hg amend`, `hg commit --amend` and `hg uncommit` in the
+    current version.
 
 ``storage``
 -----------
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -184,6 +184,9 @@ 
 
 def resolvecommitoptions(ui, opts):
     """modify commit options dict to handle related options
+
+    The return value indicates that ``rewrite.update-timestamp`` is the reason
+    the ``date`` option is set.
     """
     if opts.get('date') and opts.get('currentdate'):
         raise error.Abort(_('--date and --currentdate are mutually '
@@ -192,12 +195,21 @@ 
         raise error.Abort(_('--user and --currentuser are mutually '
                             'exclusive'))
 
-    # N.B. this is extremely similar to setupheaderopts() in mq.py
+    datemaydiffer = False  # date-only change should be ignored?
+
     if opts.get(b'currentdate'):
         opts[b'date'] = b'%d %d' % dateutil.makedate()
+    elif (not opts.get('date')
+          and ui.configbool('rewrite', 'update-timestamp')
+          and opts.get('currentdate') is None):
+        opts[b'date'] = b'%d %d' % dateutil.makedate()
+        datemaydiffer = True
+
     if opts.get(b'currentuser'):
         opts[b'user'] = ui.username()
 
+    return datemaydiffer
+
 def ishunk(x):
     hunkclasses = (crecordmod.uihunk, patch.recordhunk)
     return isinstance(x, hunkclasses)
@@ -2470,22 +2482,13 @@ 
         # Also update it from the from the wctx
         extra.update(wctx.extra())
 
-        user = opts.get('user') or old.user()
-
-        datemaydiffer = False  # date-only change should be ignored?
-        if opts.get('date') and opts.get('currentdate'):
-            raise error.Abort(_('--date and --currentdate are mutually '
-                                'exclusive'))
+        # date-only change should be ignored?
+        datemaydiffer = resolvecommitoptions(ui, opts)
+
+        date = old.date()
         if opts.get('date'):
             date = dateutil.parsedate(opts.get('date'))
-        elif opts.get('currentdate'):
-            date = dateutil.makedate()
-        elif (ui.configbool('rewrite', 'update-timestamp')
-              and opts.get('currentdate') is None):
-            date = dateutil.makedate()
-            datemaydiffer = True
-        else:
-            date = old.date()
+        user = opts.get('user') or old.user()
 
         if len(old.parents()) > 1:
             # ctx.files() isn't reliable for merges, so fall back to the
diff --git a/hgext/amend.py b/hgext/amend.py
--- a/hgext/amend.py
+++ b/hgext/amend.py
@@ -36,9 +36,8 @@ 
      ('e', 'edit', None, _('invoke editor on commit messages')),
      ('i', 'interactive', None, _('use interactive mode')),
      ('n', 'note', '', _('store a note on the amend')),
-     ('D', 'currentdate', None,
-      _('record the current date as commit date')),
-    ] + cmdutil.walkopts + cmdutil.commitopts + cmdutil.commitopts2,
+    ] + cmdutil.walkopts + cmdutil.commitopts + cmdutil.commitopts2
+      + cmdutil.commitopts3,
     _('[OPTION]... [FILE]...'),
     helpcategory=command.CATEGORY_COMMITTING,
     inferrepo=True)