inhibit: fix inhibit working with non-inhibit repos stable
authorDurham Goode <durham@fb.com>
Wed, 12 Aug 2015 10:51:20 -0700
branchstable
changeset 1490 bc7eec65dfcf
parent 1489 2f8a4d496585
child 1491 8f469f81129c
child 1501 5c962163f77a
inhibit: fix inhibit working with non-inhibit repos Inhibit was breaking when two repos were in memory, but one was not an inhibit repo (like when doing a local pull between two repos). The fix is to add inhibitenabled checks to all the places where inhibit does global wrapping of commands (every code path from the extsetup wrappers).
hgext/inhibit.py
tests/test-inhibit.t
--- a/hgext/inhibit.py	Wed Aug 12 16:08:05 2015 -0700
+++ b/hgext/inhibit.py	Wed Aug 12 10:51:20 2015 -0700
@@ -23,11 +23,15 @@
 from mercurial import commands
 from mercurial import lock as lockmod
 from mercurial import bookmarks
+from mercurial import util
 from mercurial.i18n import _
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
+def _inhibitenabled(repo):
+    return util.safehasattr(repo, '_obsinhibit')
+
 def reposetup(ui, repo):
 
     class obsinhibitedrepo(repo.__class__):
@@ -122,6 +126,9 @@
     Content of <nodes> and all mutable ancestors are considered. Marker for
     obsolete revision only are created.
     """
+    if not _inhibitenabled(repo):
+        return
+
     newinhibit = repo.set('::%ln and obsolete()', nodes)
     if newinhibit:
         lock = tr = None
@@ -141,6 +148,9 @@
     This will be triggered when inhibited nodes received new obsolescence
     markers. Otherwise the new obsolescence markers would also be inhibited.
     """
+    if not _inhibitenabled(repo):
+        return
+
     deinhibited = repo._obsinhibit & set(nodes)
     if deinhibited:
         tr = repo.transaction('obsinhibit')
@@ -177,7 +187,7 @@
         if visibleobsolete:
             _inhibitmarkers(repo, [repo[r].node() for r in visibleobsolete])
     transaction = orig(repo, desc, *args, **kwargs)
-    if desc != 'strip':
+    if desc != 'strip' and _inhibitenabled(repo):
         transaction.addpostclose('inhibitposttransaction', inhibitposttransaction)
     return transaction
 
@@ -190,9 +200,10 @@
 
         This will trickle down to other part of mercurial (hidden, log, etc)"""
         obs = obsfunc(repo)
-        getrev = repo.changelog.nodemap.get
-        for n in repo._obsinhibit:
-            obs.discard(getrev(n))
+        if _inhibitenabled(repo):
+            getrev = repo.changelog.nodemap.get
+            for n in repo._obsinhibit:
+                obs.discard(getrev(n))
         return obs
     try:
         extensions.find('directaccess')
--- a/tests/test-inhibit.t	Wed Aug 12 16:08:05 2015 -0700
+++ b/tests/test-inhibit.t	Wed Aug 12 10:51:20 2015 -0700
@@ -760,3 +760,21 @@
   added 1 changesets with 1 changes to 1 files
   pushing 33 obsolescence markers (*) (glob)
   2 obsolescence markers added
+
+Pulling from a inhibit repo to a non-inhibit repo should work
+
+  $ cd ..
+  $ hg clone -q inhibit not-inhibit
+  $ cat >> not-inhibit/.hg/hgrc <<EOF
+  > [extensions]
+  > inhibit=!
+  > directaccess=!
+  > evolve=!
+  > EOF
+  $ cd not-inhibit
+  $ hg book -d foo
+  $ hg pull
+  pulling from $TESTTMP/inhibit
+  searching for changes
+  no changes found
+  adding remote bookmark foo