D4404: commitextras: work nicely with other extensions

valentin.gatienbaron (Valentin Gatien-Baron) phabricator at mercurial-scm.org
Tue Aug 28 10:44:31 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1cb7c9777852: commitextras: work nicely with other extensions (authored by valentin.gatienbaron, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4404?vs=10610&id=10617

REVISION DETAIL
  https://phab.mercurial-scm.org/D4404

AFFECTED FILES
  hgext/commitextras.py

CHANGE DETAILS

diff --git a/hgext/commitextras.py b/hgext/commitextras.py
--- a/hgext/commitextras.py
+++ b/hgext/commitextras.py
@@ -17,6 +17,7 @@
     error,
     extensions,
     registrar,
+    util,
 )
 
 cmdtable = {}
@@ -43,9 +44,10 @@
         _('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 @@
                                 "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)



To: valentin.gatienbaron, #hg-reviewers, pulkit
Cc: mercurial-devel


More information about the Mercurial-devel mailing list