Mercurial > hg
comparison hgext/commitextras.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | bd3f03d8cc9f |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
35 '__touch-noise__', | 35 '__touch-noise__', |
36 'source', | 36 'source', |
37 'transplant_source', | 37 'transplant_source', |
38 } | 38 } |
39 | 39 |
40 | |
40 def extsetup(ui): | 41 def extsetup(ui): |
41 entry = extensions.wrapcommand(commands.table, 'commit', _commit) | 42 entry = extensions.wrapcommand(commands.table, 'commit', _commit) |
42 options = entry[1] | 43 options = entry[1] |
43 options.append(('', 'extra', [], | 44 options.append( |
44 _('set a changeset\'s extra values'), _("KEY=VALUE"))) | 45 ('', 'extra', [], _('set a changeset\'s extra values'), _("KEY=VALUE")) |
46 ) | |
47 | |
45 | 48 |
46 def _commit(orig, ui, repo, *pats, **opts): | 49 def _commit(orig, ui, repo, *pats, **opts): |
47 if util.safehasattr(repo, 'unfiltered'): | 50 if util.safehasattr(repo, 'unfiltered'): |
48 repo = repo.unfiltered() | 51 repo = repo.unfiltered() |
52 | |
49 class repoextra(repo.__class__): | 53 class repoextra(repo.__class__): |
50 def commit(self, *innerpats, **inneropts): | 54 def commit(self, *innerpats, **inneropts): |
51 extras = opts.get(r'extra') | 55 extras = opts.get(r'extra') |
52 for raw in extras: | 56 for raw in extras: |
53 if '=' not in raw: | 57 if '=' not in raw: |
54 msg = _("unable to parse '%s', should follow " | 58 msg = _( |
55 "KEY=VALUE format") | 59 "unable to parse '%s', should follow " |
60 "KEY=VALUE format" | |
61 ) | |
56 raise error.Abort(msg % raw) | 62 raise error.Abort(msg % raw) |
57 k, v = raw.split('=', 1) | 63 k, v = raw.split('=', 1) |
58 if not k: | 64 if not k: |
59 msg = _("unable to parse '%s', keys can't be empty") | 65 msg = _("unable to parse '%s', keys can't be empty") |
60 raise error.Abort(msg % raw) | 66 raise error.Abort(msg % raw) |
61 if re.search(br'[^\w-]', k): | 67 if re.search(br'[^\w-]', k): |
62 msg = _("keys can only contain ascii letters, digits," | 68 msg = _( |
63 " '_' and '-'") | 69 "keys can only contain ascii letters, digits," |
70 " '_' and '-'" | |
71 ) | |
64 raise error.Abort(msg) | 72 raise error.Abort(msg) |
65 if k in usedinternally: | 73 if k in usedinternally: |
66 msg = _("key '%s' is used internally, can't be set " | 74 msg = _( |
67 "manually") | 75 "key '%s' is used internally, can't be set " "manually" |
76 ) | |
68 raise error.Abort(msg % k) | 77 raise error.Abort(msg % k) |
69 inneropts[r'extra'][k] = v | 78 inneropts[r'extra'][k] = v |
70 return super(repoextra, self).commit(*innerpats, **inneropts) | 79 return super(repoextra, self).commit(*innerpats, **inneropts) |
80 | |
71 repo.__class__ = repoextra | 81 repo.__class__ = repoextra |
72 return orig(ui, repo, *pats, **opts) | 82 return orig(ui, repo, *pats, **opts) |