D768: blackbox: do not prevent 'chg init' from working

quark (Jun Wu) phabricator at mercurial-scm.org
Thu Sep 21 18:13:07 UTC 2017


quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Previously, blackbox always appends to blackbox.log and creates the
  directory for that file on demand. That could be an issue if:
  
  1. chg starts from `$REPO` directory, so `ui._bbrepo` is set.
  2. `rm -rf $REPO`.
  3. `chg init $REPO`, blackbox writes something and `init` will fail because `$REPO` directory is non-empty.
  
  This patch fixes that by verifying whether vfs exists before re-using it.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/blackbox.py
  tests/test-blackbox.t

CHANGE DETAILS

diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -286,6 +286,14 @@
 
   $ cd ..
 
+With chg, blackbox should not log into other repos
+
+  $ hg init repo1
+  $ hg init repo2
+  $ hg --config extensions.a=! -R repo1 log
+  $ rm -rf $TESTTMP/repo1
+  $ hg --config extensions.a=! init repo1
+
 #endif
 
 blackbox should work if repo.ui.log is not called (issue5518)
diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -77,9 +77,13 @@
     class blackboxui(ui.__class__):
         @property
         def _bbvfs(self):
+            vfs = None
             repo = getattr(self, '_bbrepo', None)
             if repo:
-                return repo.vfs
+                vfs = repo.vfs
+                if not vfs.isdir('.'):
+                    vfs = None
+            return vfs
 
         @util.propertycache
         def track(self):
@@ -136,6 +140,10 @@
 
             if not ui:
                 return
+            vfs = ui._bbvfs
+            if not vfs:
+                return
+
             repo = getattr(ui, '_bbrepo', None)
             if not lastui or repo:
                 lastui = ui



To: quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list