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