diff --git a/hgext/commitextras.py b/hgext/commitextras.py --- a/hgext/commitextras.py +++ b/hgext/commitextras.py @@ -17,7 +17,6 @@ error, extensions, registrar, - util, ) cmdtable = {} @@ -38,35 +37,34 @@ } def extsetup(ui): - entry = extensions.wrapcommand(commands.table, 'commit', _commit) + entry = extensions.wrapcommand(commands.table, 'commit', wrapcommit) options = entry[1] options.append(('', 'extra', [], _('set a changeset\'s extra values'), _("KEY=VALUE"))) -def _commit(orig, ui, repo, *pats, **opts): - if util.safehasattr(repo, 'unfiltered'): - repo = repo.unfiltered() - class repoextra(repo.__class__): - def commit(self, *innerpats, **inneropts): - extras = opts.get(r'extra') - for raw in extras: - if '=' not in raw: - msg = _("unable to parse '%s', should follow " - "KEY=VALUE format") - raise error.Abort(msg % raw) - k, v = raw.split('=', 1) - if not k: - msg = _("unable to parse '%s', keys can't be empty") - raise error.Abort(msg % raw) - if re.search(br'[^\w-]', k): - msg = _("keys can only contain ascii letters, digits," - " '_' and '-'") - raise error.Abort(msg) - if k in usedinternally: - msg = _("key '%s' is used internally, can't be set " - "manually") - raise error.Abort(msg % k) - inneropts[r'extra'][k] = v - return super(repoextra, self).commit(*innerpats, **inneropts) - repo.__class__ = repoextra +def wrapcommit(orig, ui, repo, *pats, **opts): + extdict = opts.get(r'extras', {}) + extras = opts.get(r'extra') + for raw in extras: + if '=' not in raw: + msg = _("unable to parse '%s', should follow " + "KEY=VALUE format") + raise error.Abort(msg % raw) + k, v = raw.split('=', 1) + if not k: + msg = _("unable to parse '%s', keys can't be empty") + raise error.Abort(msg % raw) + if re.search(br'[^\w-]', k): + msg = _("keys can only contain ascii letters, digits," + " '_' and '-'") + raise error.Abort(msg) + if k in usedinternally: + msg = _("key '%s' is used internally, can't be set " + "manually") + raise error.Abort(msg % k) + extdict[k] = v + + # assign opts['extras'] to the dict before passing into + # commands.commit + opts['extras'] = extdict return orig(ui, repo, *pats, **opts) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1669,7 +1669,10 @@ branch = repo[None].branch() bheads = repo.branchheads(branch) - extra = {} + # extensions can wrap commands.commit and pass extras in opts + # 'extras' is used instead of 'extra' because the latter is taken by + # commitextras extension as a flag + extra = opts.get('extras', {}) if opts.get('close_branch'): extra['close'] = '1'