Patchwork [1,of,6] ignore: remove .hgignore from ignore list if nonexistent

login
register
mail settings
Submitter Durham Goode
Date May 18, 2015, 6:28 p.m.
Message ID <ef85707822930cf344e5.1431973737@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9143/
State Accepted
Headers show

Comments

Durham Goode - May 18, 2015, 6:28 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1431815083 25200
#      Sat May 16 15:24:43 2015 -0700
# Node ID ef85707822930cf344e59353e784f1f0223e257c
# Parent  99d01d288c3734ab1f7bb15e0428b2e55530cd1d
ignore: remove .hgignore from ignore list if nonexistent

Previously we would always pass the root .hgignore path to the ignore parser.
The parser then had to be aware that the first path was special, and not warn if
it didn't exist.

In preparation for making the ignore file parser more generically usable, let's
make the parse logic not aware of this special case, and instead just not pass
the root .hgignore in if it doesn't exist.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -143,7 +143,9 @@  class dirstate(object):
 
     @rootcache('.hgignore')
     def _ignore(self):
-        files = [self._join('.hgignore')]
+        files = []
+        if os.path.exists(self._join('.hgignore')):
+            files.append(self._join('.hgignore'))
         for name, path in self._ui.configitems("ui"):
             if name == 'ignore' or name.startswith('ignore.'):
                 # we need to use os.path.join here rather than self._join
diff --git a/mercurial/ignore.py b/mercurial/ignore.py
--- a/mercurial/ignore.py
+++ b/mercurial/ignore.py
@@ -55,7 +55,7 @@  def ignorepats(lines):
 
     return patterns, warnings
 
-def readignorefile(filepath, warn, skipwarning=False):
+def readignorefile(filepath, warn):
     try:
         pats = []
         fp = open(filepath)
@@ -64,9 +64,8 @@  def readignorefile(filepath, warn, skipw
         for warning in warnings:
             warn("%s: %s\n" % (filepath, warning))
     except IOError, inst:
-        if not skipwarning:
-            warn(_("skipping unreadable ignore file '%s': %s\n") %
-                 (filepath, inst.strerror))
+        warn(_("skipping unreadable ignore file '%s': %s\n") %
+             (filepath, inst.strerror))
     return pats
 
 def readpats(root, files, warn):
@@ -76,8 +75,7 @@  def readpats(root, files, warn):
     for f in files:
         if f in pats:
             continue
-        skipwarning = f == files[0]
-        pats[f] = readignorefile(f, warn, skipwarning=skipwarning)
+        pats[f] = readignorefile(f, warn)
 
     return [(f, pats[f]) for f in files if f in pats]