commitextras.py
88 lines
| 2.3 KiB
| text/x-python
|
PythonLexer
/ hgext / commitextras.py
Pulkit Goyal
|
r33546 | # commitextras.py | ||
# | ||||
# Copyright 2013 Facebook, Inc. | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
Pulkit Goyal
|
r33562 | '''adds a new flag extras to commit (ADVANCED)''' | ||
Pulkit Goyal
|
r33546 | |||
Pulkit Goyal
|
r33603 | import re | ||
Pulkit Goyal
|
r33546 | from mercurial.i18n import _ | ||
from mercurial import ( | ||||
commands, | ||||
Pulkit Goyal
|
r33547 | error, | ||
Pulkit Goyal
|
r33546 | extensions, | ||
registrar, | ||||
Valentin Gatien-Baron
|
r39330 | util, | ||
Pulkit Goyal
|
r33546 | ) | ||
cmdtable = {} | ||||
command = registrar.command(cmdtable) | ||||
Augie Fackler
|
r43347 | testedwith = b'ships-with-hg-core' | ||
Pulkit Goyal
|
r33546 | |||
Pulkit Goyal
|
r33547 | usedinternally = { | ||
Augie Fackler
|
r43347 | b'amend_source', | ||
b'branch', | ||||
b'close', | ||||
b'histedit_source', | ||||
b'topic', | ||||
b'rebase_source', | ||||
b'intermediate-source', | ||||
b'__touch-noise__', | ||||
b'source', | ||||
b'transplant_source', | ||||
Pulkit Goyal
|
r33547 | } | ||
Augie Fackler
|
r43346 | |||
Pulkit Goyal
|
r33546 | def extsetup(ui): | ||
Augie Fackler
|
r43347 | entry = extensions.wrapcommand(commands.table, b'commit', _commit) | ||
Pulkit Goyal
|
r33546 | options = entry[1] | ||
Augie Fackler
|
r43346 | options.append( | ||
Augie Fackler
|
r43347 | ( | ||
b'', | ||||
b'extra', | ||||
[], | ||||
_(b'set a changeset\'s extra values'), | ||||
_(b"KEY=VALUE"), | ||||
) | ||||
Augie Fackler
|
r43346 | ) | ||
Pulkit Goyal
|
r33546 | |||
def _commit(orig, ui, repo, *pats, **opts): | ||||
Martin von Zweigbergk
|
r43385 | if util.safehasattr(repo, 'unfiltered'): | ||
Valentin Gatien-Baron
|
r39330 | repo = repo.unfiltered() | ||
Augie Fackler
|
r43346 | |||
Valentin Gatien-Baron
|
r39330 | class repoextra(repo.__class__): | ||
def commit(self, *innerpats, **inneropts): | ||||
Augie Fackler
|
r43906 | extras = opts.get('extra') | ||
Valentin Gatien-Baron
|
r39331 | for raw in extras: | ||
Augie Fackler
|
r43347 | if b'=' not in raw: | ||
Augie Fackler
|
r43346 | msg = _( | ||
Augie Fackler
|
r43347 | b"unable to parse '%s', should follow " | ||
b"KEY=VALUE format" | ||||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r49193 | raise error.InputError(msg % raw) | ||
Augie Fackler
|
r43347 | k, v = raw.split(b'=', 1) | ||
Valentin Gatien-Baron
|
r39331 | if not k: | ||
Augie Fackler
|
r43347 | msg = _(b"unable to parse '%s', keys can't be empty") | ||
Martin von Zweigbergk
|
r49193 | raise error.InputError(msg % raw) | ||
Gregory Szorc
|
r41673 | if re.search(br'[^\w-]', k): | ||
Augie Fackler
|
r43346 | msg = _( | ||
Augie Fackler
|
r43347 | b"keys can only contain ascii letters, digits," | ||
b" '_' and '-'" | ||||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r49193 | raise error.InputError(msg) | ||
Valentin Gatien-Baron
|
r39331 | if k in usedinternally: | ||
Augie Fackler
|
r43346 | msg = _( | ||
Augie Fackler
|
r43347 | b"key '%s' is used internally, can't be set " | ||
b"manually" | ||||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r49193 | raise error.InputError(msg % k) | ||
Augie Fackler
|
r43906 | inneropts['extra'][k] = v | ||
Valentin Gatien-Baron
|
r39330 | return super(repoextra, self).commit(*innerpats, **inneropts) | ||
Augie Fackler
|
r43346 | |||
Valentin Gatien-Baron
|
r39330 | repo.__class__ = repoextra | ||
return orig(ui, repo, *pats, **opts) | ||||