changeset 994:9c15c89088fd

gitdirstate: only wrap for hg-git repos Previously, if a user enables hg-git and in a non-git repo (i.e. hg-only) they have a .gitignore, then hg-git will try to parse that. I consider this a bug and a bad performance regression for what should be a no-op.
author Sean Farley <sean@farley.io>
date Fri, 02 Sep 2016 18:26:01 -0700
parents 1fec6463922b
children c4a2ef796c19
files hggit/__init__.py tests/test-gitignore.t
diffstat 2 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/__init__.py	Fri Aug 12 16:54:20 2016 -0500
+++ b/hggit/__init__.py	Fri Sep 02 18:26:01 2016 -0700
@@ -208,7 +208,9 @@
     if not isinstance(repo, gitrepo.gitrepo):
 
         if (getattr(dirstate, 'rootcache', False) and
-            (not ignoremod or getattr(ignore, 'readpats', False))):
+            (not ignoremod or getattr(ignore, 'readpats', False)) and
+            hgutil.safehasattr(repo, 'join') and
+            os.path.exists(repo.join('git'))):
             # only install our dirstate wrapper if it has a hope of working
             import gitdirstate
             if ignoremod:
--- a/tests/test-gitignore.t	Fri Aug 12 16:54:20 2016 -0500
+++ b/tests/test-gitignore.t	Fri Sep 02 18:26:01 2016 -0700
@@ -5,6 +5,11 @@
 
   $ hg init
 
+We should only read .gitignore files in a hg-git repo (i.e. one with .hg/git
+directory) otherwise, a rogue .gitignore could slow down a hg-only repo
+
+  $ mkdir .hg/git
+
   $ touch foo
   $ touch foobar
   $ touch bar