|
1 # commitextras.py |
|
2 # |
|
3 # Copyright 2013 Facebook, Inc. |
|
4 # |
|
5 # This software may be used and distributed according to the terms of the |
|
6 # GNU General Public License version 2 or any later version. |
|
7 |
|
8 '''adds a new flag extras to commit''' |
|
9 |
|
10 from __future__ import absolute_import |
|
11 |
|
12 from mercurial.i18n import _ |
|
13 from mercurial import ( |
|
14 commands, |
|
15 extensions, |
|
16 registrar, |
|
17 ) |
|
18 |
|
19 cmdtable = {} |
|
20 command = registrar.command(cmdtable) |
|
21 testedwith = 'ships-with-hg-core' |
|
22 |
|
23 def extsetup(ui): |
|
24 entry = extensions.wrapcommand(commands.table, 'commit', _commit) |
|
25 options = entry[1] |
|
26 options.append(('', 'extra', [], |
|
27 _('set a changeset\'s extra values'), _("KEY=VALUE"))) |
|
28 |
|
29 def _commit(orig, ui, repo, *pats, **opts): |
|
30 origcommit = repo.commit |
|
31 try: |
|
32 def _wrappedcommit(*innerpats, **inneropts): |
|
33 extras = opts.get('extra') |
|
34 if extras: |
|
35 for raw in extras: |
|
36 k, v = raw.split('=', 1) |
|
37 inneropts['extra'][k] = v |
|
38 return origcommit(*innerpats, **inneropts) |
|
39 |
|
40 # This __dict__ logic is needed because the normal |
|
41 # extension.wrapfunction doesn't seem to work. |
|
42 repo.__dict__['commit'] = _wrappedcommit |
|
43 return orig(ui, repo, *pats, **opts) |
|
44 finally: |
|
45 del repo.__dict__['commit'] |