hgext/commitextras.py
changeset 39294 1cb7c9777852
parent 36419 75c76cee1b1b
child 39295 3a60416c4fd8
equal deleted inserted replaced
39293:278eb4541758 39294:1cb7c9777852
    15 from mercurial import (
    15 from mercurial import (
    16     commands,
    16     commands,
    17     error,
    17     error,
    18     extensions,
    18     extensions,
    19     registrar,
    19     registrar,
       
    20     util,
    20 )
    21 )
    21 
    22 
    22 cmdtable = {}
    23 cmdtable = {}
    23 command = registrar.command(cmdtable)
    24 command = registrar.command(cmdtable)
    24 testedwith = 'ships-with-hg-core'
    25 testedwith = 'ships-with-hg-core'
    41     options = entry[1]
    42     options = entry[1]
    42     options.append(('', 'extra', [],
    43     options.append(('', 'extra', [],
    43         _('set a changeset\'s extra values'), _("KEY=VALUE")))
    44         _('set a changeset\'s extra values'), _("KEY=VALUE")))
    44 
    45 
    45 def _commit(orig, ui, repo, *pats, **opts):
    46 def _commit(orig, ui, repo, *pats, **opts):
    46     origcommit = repo.commit
    47     if util.safehasattr(repo, 'unfiltered'):
    47     try:
    48         repo = repo.unfiltered()
    48         def _wrappedcommit(*innerpats, **inneropts):
    49     class repoextra(repo.__class__):
       
    50         def commit(self, *innerpats, **inneropts):
    49             extras = opts.get(r'extra')
    51             extras = opts.get(r'extra')
    50             if extras:
    52             if extras:
    51                 for raw in extras:
    53                 for raw in extras:
    52                     if '=' not in raw:
    54                     if '=' not in raw:
    53                         msg = _("unable to parse '%s', should follow "
    55                         msg = _("unable to parse '%s', should follow "
    64                     if k in usedinternally:
    66                     if k in usedinternally:
    65                         msg = _("key '%s' is used internally, can't be set "
    67                         msg = _("key '%s' is used internally, can't be set "
    66                                 "manually")
    68                                 "manually")
    67                         raise error.Abort(msg % k)
    69                         raise error.Abort(msg % k)
    68                     inneropts[r'extra'][k] = v
    70                     inneropts[r'extra'][k] = v
    69             return origcommit(*innerpats, **inneropts)
    71             return super(repoextra, self).commit(*innerpats, **inneropts)
    70 
    72     repo.__class__ = repoextra
    71         # This __dict__ logic is needed because the normal
    73     return orig(ui, repo, *pats, **opts)
    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']