# HG changeset patch # User Valentin Gatien-Baron # Date 2018-08-27 20:01:55 # Node ID 1cb7c97778524d6f3c3c536836a6192c10d1d88d # Parent 278eb454175843acb78e8f927a08c5aff3a2dfaf commitextras: work nicely with other extensions Before this change, it doesn't add these extra fields when loaded alongside another extension that does a bunch of things, including wrapping commit. I did not investigate exactly why, but - the documentation of extensions.wrapfunction says to use subclassing to play nicely with other extensions - using subclassing does make commitextras work when loaded alongside my other extension Differential Revision: https://phab.mercurial-scm.org/D4404 diff --git a/hgext/commitextras.py b/hgext/commitextras.py --- a/hgext/commitextras.py +++ b/hgext/commitextras.py @@ -17,6 +17,7 @@ from mercurial import ( error, extensions, registrar, + util, ) cmdtable = {} @@ -43,9 +44,10 @@ def extsetup(ui): _('set a changeset\'s extra values'), _("KEY=VALUE"))) def _commit(orig, ui, repo, *pats, **opts): - origcommit = repo.commit - try: - def _wrappedcommit(*innerpats, **inneropts): + if util.safehasattr(repo, 'unfiltered'): + repo = repo.unfiltered() + class repoextra(repo.__class__): + def commit(self, *innerpats, **inneropts): extras = opts.get(r'extra') if extras: for raw in extras: @@ -66,11 +68,6 @@ def _commit(orig, ui, repo, *pats, **opt "manually") raise error.Abort(msg % k) inneropts[r'extra'][k] = v - return origcommit(*innerpats, **inneropts) - - # This __dict__ logic is needed because the normal - # extension.wrapfunction doesn't seem to work. - repo.__dict__[r'commit'] = _wrappedcommit - return orig(ui, repo, *pats, **opts) - finally: - del repo.__dict__[r'commit'] + return super(repoextra, self).commit(*innerpats, **inneropts) + repo.__class__ = repoextra + return orig(ui, repo, *pats, **opts)