##// END OF EJS Templates
py3: handle keyword arguments in hgext/commitextras.py...
Pulkit Goyal -
r34976:901a18b0 default
parent child Browse files
Show More
@@ -1,76 +1,76 b''
1 # commitextras.py
1 # commitextras.py
2 #
2 #
3 # Copyright 2013 Facebook, Inc.
3 # Copyright 2013 Facebook, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
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.
6 # GNU General Public License version 2 or any later version.
7
7
8 '''adds a new flag extras to commit (ADVANCED)'''
8 '''adds a new flag extras to commit (ADVANCED)'''
9
9
10 from __future__ import absolute_import
10 from __future__ import absolute_import
11
11
12 import re
12 import re
13
13
14 from mercurial.i18n import _
14 from mercurial.i18n import _
15 from mercurial import (
15 from mercurial import (
16 commands,
16 commands,
17 error,
17 error,
18 extensions,
18 extensions,
19 registrar,
19 registrar,
20 )
20 )
21
21
22 cmdtable = {}
22 cmdtable = {}
23 command = registrar.command(cmdtable)
23 command = registrar.command(cmdtable)
24 testedwith = 'ships-with-hg-core'
24 testedwith = 'ships-with-hg-core'
25
25
26 usedinternally = {
26 usedinternally = {
27 'amend_source',
27 'amend_source',
28 'branch',
28 'branch',
29 'close',
29 'close',
30 'histedit_source',
30 'histedit_source',
31 'topic',
31 'topic',
32 'rebase_source',
32 'rebase_source',
33 'intermediate-source',
33 'intermediate-source',
34 '__touch-noise__',
34 '__touch-noise__',
35 'source',
35 'source',
36 'transplant_source',
36 'transplant_source',
37 }
37 }
38
38
39 def extsetup(ui):
39 def extsetup(ui):
40 entry = extensions.wrapcommand(commands.table, 'commit', _commit)
40 entry = extensions.wrapcommand(commands.table, 'commit', _commit)
41 options = entry[1]
41 options = entry[1]
42 options.append(('', 'extra', [],
42 options.append(('', 'extra', [],
43 _('set a changeset\'s extra values'), _("KEY=VALUE")))
43 _('set a changeset\'s extra values'), _("KEY=VALUE")))
44
44
45 def _commit(orig, ui, repo, *pats, **opts):
45 def _commit(orig, ui, repo, *pats, **opts):
46 origcommit = repo.commit
46 origcommit = repo.commit
47 try:
47 try:
48 def _wrappedcommit(*innerpats, **inneropts):
48 def _wrappedcommit(*innerpats, **inneropts):
49 extras = opts.get('extra')
49 extras = opts.get(r'extra')
50 if extras:
50 if extras:
51 for raw in extras:
51 for raw in extras:
52 if '=' not in raw:
52 if '=' not in raw:
53 msg = _("unable to parse '%s', should follow "
53 msg = _("unable to parse '%s', should follow "
54 "KEY=VALUE format")
54 "KEY=VALUE format")
55 raise error.Abort(msg % raw)
55 raise error.Abort(msg % raw)
56 k, v = raw.split('=', 1)
56 k, v = raw.split('=', 1)
57 if not k:
57 if not k:
58 msg = _("unable to parse '%s', keys can't be empty")
58 msg = _("unable to parse '%s', keys can't be empty")
59 raise error.Abort(msg % raw)
59 raise error.Abort(msg % raw)
60 if re.search('[^\w-]', k):
60 if re.search('[^\w-]', k):
61 msg = _("keys can only contain ascii letters, digits,"
61 msg = _("keys can only contain ascii letters, digits,"
62 " '_' and '-'")
62 " '_' and '-'")
63 raise error.Abort(msg)
63 raise error.Abort(msg)
64 if k in usedinternally:
64 if k in usedinternally:
65 msg = _("key '%s' is used internally, can't be set "
65 msg = _("key '%s' is used internally, can't be set "
66 "manually")
66 "manually")
67 raise error.Abort(msg % k)
67 raise error.Abort(msg % k)
68 inneropts['extra'][k] = v
68 inneropts[r'extra'][k] = v
69 return origcommit(*innerpats, **inneropts)
69 return origcommit(*innerpats, **inneropts)
70
70
71 # This __dict__ logic is needed because the normal
71 # This __dict__ logic is needed because the normal
72 # extension.wrapfunction doesn't seem to work.
72 # extension.wrapfunction doesn't seem to work.
73 repo.__dict__['commit'] = _wrappedcommit
73 repo.__dict__['commit'] = _wrappedcommit
74 return orig(ui, repo, *pats, **opts)
74 return orig(ui, repo, *pats, **opts)
75 finally:
75 finally:
76 del repo.__dict__['commit']
76 del repo.__dict__['commit']
General Comments 0
You need to be logged in to leave comments. Login now