Patchwork commit: add --extra argument to set extra user fields

login
register
mail settings
Submitter Angel Ezquerra
Date March 5, 2014, 10:32 p.m.
Message ID <1658e55e8c9e2518236a.1394058723@ubuntu>
Download mbox | patch
Permalink /patch/3866/
State Rejected
Headers show

Comments

Angel Ezquerra - March 5, 2014, 10:32 p.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1394000996 -3600
#      Wed Mar 05 07:29:56 2014 +0100
# Node ID 1658e55e8c9e2518236aeb8e7d1d89a1714b6f37
# Parent  779ceb84f4f782d32dfe47f6684107c08d2f6142
commit: add --extra argument to set extra user fields

This lets the user set a key/value pair on the extra commit field dictionary.
The user can use this new parameter more than once to set more than one
key/value pair.

Extra entries added this way are added in the "user" namespace within the extra
field. This is done to avoid the possibility of a clash between a user defined
field and a field used by mercurial or one of its extensions.

This is useful to "mark" revisions at commit time, or to add extra information
related to the commit in a more structured manner than adding them to the
commit message.
Matt Mackall - March 6, 2014, 4:06 a.m.
On Wed, 2014-03-05 at 23:32 +0100, Angel Ezquerra wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra@gmail.com>
> # Date 1394000996 -3600
> #      Wed Mar 05 07:29:56 2014 +0100
> # Node ID 1658e55e8c9e2518236aeb8e7d1d89a1714b6f37
> # Parent  779ceb84f4f782d32dfe47f6684107c08d2f6142
> commit: add --extra argument to set extra user fields

Perhaps the most positive thing I can say about this feature is that I
can't stop you from doing this in a third-party extension. I'm
definitely opposed to giving users access to putting arbitrary things in
extra, or doing anything that's even suggestive of functionality like
svn props. We already have enough problems managing our internal extra
fields.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1318,6 +1318,7 @@ 
      _('mark a branch as closed, hiding it from the branch list')),
     ('', 'amend', None, _('amend the parent of the working dir')),
     ('s', 'secret', None, _('use the secret phase for committing')),
+    ('', 'extra', [], _('set a user extra value')),
     ] + walkopts + commitopts + commitopts2 + subrepoopts,
     _('[OPTION]... [FILE]...'))
 def commit(ui, repo, *pats, **opts):
@@ -1371,6 +1372,15 @@ 
     bheads = repo.branchheads(branch)
 
     extra = {}
+    userextra = opts.get('extra', [])
+    for el in userextra:
+        try:
+            key, value = el.split('=', 1)
+        except ValueError:
+            raise util.Abort(_('malformed --extra option: %r '
+                               '(use --extra name=value)') % el)
+        extra['user.%s' % key.strip()] = value.strip()
+
     if opts.get('close_branch'):
         extra['close'] = 1
 
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -306,4 +306,48 @@ 
        0         0       6  .....       0 26d3ca0dfd18 000000000000 000000000000 (re)
        1         6       7  .....       1 d267bddd54f7 26d3ca0dfd18 000000000000 (re)
 
+commit extra fields
+
+  $ echo dubidu > foobar
+  $ hg add foobar
+  $ hg ci -m 'add foobar' --extra field1
+  abort: malformed --extra option: 'field1' (use --extra name=value)
+  [255]
+  $ hg ci -m 'add foobar' --extra field1=value1 --extra 'second field=value 2'
+  $ hg log -r 'extra(user.field1)' --debug
+  changeset:   2:6a90106531466bd139db022a63bb6a03cc0a68fd
+  tag:         tip
+  phase:       draft
+  parent:      1:3c23404d6e68f029181eb82dae39c93aa3e6aee0
+  parent:      -1:0000000000000000000000000000000000000000
+  manifest:    2:585686d55b420d059a2442798b83f80f0b871f93
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  files+:      foobar
+  extra:       branch=default
+  extra:       user.field1=value1
+  extra:       user.second field=value 2
+  description:
+  add foobar
+  
+  
+
+  $ hg log -r 'extra("user.second field", "value 2")' --debug
+  changeset:   2:6a90106531466bd139db022a63bb6a03cc0a68fd
+  tag:         tip
+  phase:       draft
+  parent:      1:3c23404d6e68f029181eb82dae39c93aa3e6aee0
+  parent:      -1:0000000000000000000000000000000000000000
+  manifest:    2:585686d55b420d059a2442798b83f80f0b871f93
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  files+:      foobar
+  extra:       branch=default
+  extra:       user.field1=value1
+  extra:       user.second field=value 2
+  description:
+  add foobar
+  
+  
+
   $ cd ..
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -199,7 +199,7 @@ 
   add: include, exclude, subrepos, dry-run
   annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude
   clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
-  commit: addremove, close-branch, amend, secret, include, exclude, message, logfile, date, user, subrepos
+  commit: addremove, close-branch, amend, secret, extra, include, exclude, message, logfile, date, user, subrepos
   diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
   export: output, switch-parent, rev, text, git, nodates
   forget: include, exclude
diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t
--- a/tests/test-qrecord.t
+++ b/tests/test-qrecord.t
@@ -62,6 +62,7 @@ 
                             list
       --amend               amend the parent of the working dir
    -s --secret              use the secret phase for committing
+      --extra VALUE [+]     set a user extra value
    -I --include PATTERN [+] include names matching the given patterns
    -X --exclude PATTERN [+] exclude names matching the given patterns
    -m --message TEXT        use text as commit message