Show More
@@ -1,76 +1,73 | |||||
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 | util, | |||
20 | ) |
|
21 | ) | |
21 |
|
22 | |||
22 | cmdtable = {} |
|
23 | cmdtable = {} | |
23 | command = registrar.command(cmdtable) |
|
24 | command = registrar.command(cmdtable) | |
24 | testedwith = 'ships-with-hg-core' |
|
25 | testedwith = 'ships-with-hg-core' | |
25 |
|
26 | |||
26 | usedinternally = { |
|
27 | usedinternally = { | |
27 | 'amend_source', |
|
28 | 'amend_source', | |
28 | 'branch', |
|
29 | 'branch', | |
29 | 'close', |
|
30 | 'close', | |
30 | 'histedit_source', |
|
31 | 'histedit_source', | |
31 | 'topic', |
|
32 | 'topic', | |
32 | 'rebase_source', |
|
33 | 'rebase_source', | |
33 | 'intermediate-source', |
|
34 | 'intermediate-source', | |
34 | '__touch-noise__', |
|
35 | '__touch-noise__', | |
35 | 'source', |
|
36 | 'source', | |
36 | 'transplant_source', |
|
37 | 'transplant_source', | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | def extsetup(ui): |
|
40 | def extsetup(ui): | |
40 | entry = extensions.wrapcommand(commands.table, 'commit', _commit) |
|
41 | entry = extensions.wrapcommand(commands.table, 'commit', _commit) | |
41 | options = entry[1] |
|
42 | options = entry[1] | |
42 | options.append(('', 'extra', [], |
|
43 | options.append(('', 'extra', [], | |
43 | _('set a changeset\'s extra values'), _("KEY=VALUE"))) |
|
44 | _('set a changeset\'s extra values'), _("KEY=VALUE"))) | |
44 |
|
45 | |||
45 | def _commit(orig, ui, repo, *pats, **opts): |
|
46 | def _commit(orig, ui, repo, *pats, **opts): | |
46 | origcommit = repo.commit |
|
47 | if util.safehasattr(repo, 'unfiltered'): | |
47 | try: |
|
48 | repo = repo.unfiltered() | |
48 | def _wrappedcommit(*innerpats, **inneropts): |
|
49 | class repoextra(repo.__class__): | |
|
50 | def commit(self, *innerpats, **inneropts): | |||
49 | extras = opts.get(r'extra') |
|
51 | extras = opts.get(r'extra') | |
50 | if extras: |
|
52 | if extras: | |
51 | for raw in extras: |
|
53 | for raw in extras: | |
52 | if '=' not in raw: |
|
54 | if '=' not in raw: | |
53 | msg = _("unable to parse '%s', should follow " |
|
55 | msg = _("unable to parse '%s', should follow " | |
54 | "KEY=VALUE format") |
|
56 | "KEY=VALUE format") | |
55 | raise error.Abort(msg % raw) |
|
57 | raise error.Abort(msg % raw) | |
56 | k, v = raw.split('=', 1) |
|
58 | k, v = raw.split('=', 1) | |
57 | if not k: |
|
59 | if not k: | |
58 | msg = _("unable to parse '%s', keys can't be empty") |
|
60 | msg = _("unable to parse '%s', keys can't be empty") | |
59 | raise error.Abort(msg % raw) |
|
61 | raise error.Abort(msg % raw) | |
60 | if re.search('[^\w-]', k): |
|
62 | if re.search('[^\w-]', k): | |
61 | msg = _("keys can only contain ascii letters, digits," |
|
63 | msg = _("keys can only contain ascii letters, digits," | |
62 | " '_' and '-'") |
|
64 | " '_' and '-'") | |
63 | raise error.Abort(msg) |
|
65 | raise error.Abort(msg) | |
64 | if k in usedinternally: |
|
66 | if k in usedinternally: | |
65 | msg = _("key '%s' is used internally, can't be set " |
|
67 | msg = _("key '%s' is used internally, can't be set " | |
66 | "manually") |
|
68 | "manually") | |
67 | raise error.Abort(msg % k) |
|
69 | raise error.Abort(msg % k) | |
68 | inneropts[r'extra'][k] = v |
|
70 | inneropts[r'extra'][k] = v | |
69 |
return |
|
71 | return super(repoextra, self).commit(*innerpats, **inneropts) | |
70 |
|
72 | repo.__class__ = repoextra | ||
71 | # This __dict__ logic is needed because the normal |
|
|||
72 | # extension.wrapfunction doesn't seem to work. |
|
|||
73 | repo.__dict__[r'commit'] = _wrappedcommit |
|
|||
74 |
|
|
73 | return orig(ui, repo, *pats, **opts) | |
75 | finally: |
|
|||
76 | del repo.__dict__[r'commit'] |
|
General Comments 0
You need to be logged in to leave comments.
Login now