Patchwork [evolve-ext] inhibit: fix inhibit working with non-inhibit repos

login
register
mail settings
Submitter Durham Goode
Date Aug. 12, 2015, 6:01 p.m.
Message ID <218f933966d4686d7d8e.1439402485@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/10196/
State Accepted
Headers show

Comments

Durham Goode - Aug. 12, 2015, 6:01 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1439401880 25200
#      Wed Aug 12 10:51:20 2015 -0700
# Node ID 218f933966d4686d7d8ebcc8bb922cb0e55fa4bb
# Parent  3dec62fc266eff7c7aa20e3229ffbede1c33d208
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).
Pierre-Yves David - Aug. 12, 2015, 6:48 p.m.
On 08/12/2015 11:01 AM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1439401880 25200
> #      Wed Aug 12 10:51:20 2015 -0700
> # Node ID 218f933966d4686d7d8ebcc8bb922cb0e55fa4bb
> # Parent  3dec62fc266eff7c7aa20e3229ffbede1c33d208
> inhibit: fix inhibit working with non-inhibit repos

Pushed to main, thanks.

I remember that laurent mentioned an issue with bundle repo too and I do 
not tink it got fixed.

Patch

diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -23,11 +23,15 @@  from mercurial import scmutil
 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 @@  def _inhibitmarkers(repo, nodes):
     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 @@  def _deinhibitmarkers(repo, nodes):
     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 @@  def transactioncallback(orig, repo, desc
         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 @@  def extsetup(ui):
 
         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')
diff --git a/tests/test-inhibit.t b/tests/test-inhibit.t
--- a/tests/test-inhibit.t
+++ b/tests/test-inhibit.t
@@ -763,3 +763,21 @@  Visible commits can still be pushed
   adding file changes
   added 1 changesets with 1 changes to 1 files
   2 new obsolescence markers
+
+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