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