changeset 25216:dc562165044a

ignore: use 'include:' rules instead of custom syntax Now that the matcher supports 'include:' rules, let's change the dirstate.ignore creation to just create a matcher with a bunch of includes. This allows us to completely delete ignore.py. I moved some of the syntax documentation over to readpatternfile in match.py so we don't lose it.
author Durham Goode <durham@fb.com>
date Sat, 16 May 2015 16:06:22 -0700
parents 4040e06e9b99
children 70e822796ac8
files mercurial/dirstate.py mercurial/ignore.py mercurial/match.py tests/test-hgignore.t
diffstat 4 files changed, 28 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Sat May 16 15:56:52 2015 -0700
+++ b/mercurial/dirstate.py	Sat May 16 16:06:22 2015 -0700
@@ -7,8 +7,9 @@
 
 from node import nullid
 from i18n import _
-import scmutil, util, ignore, osutil, parsers, encoding, pathutil
+import scmutil, util, osutil, parsers, encoding, pathutil
 import os, stat, errno
+import match as matchmod
 
 propertycache = util.propertycache
 filecache = scmutil.filecache
@@ -151,7 +152,12 @@
                 # we need to use os.path.join here rather than self._join
                 # because path is arbitrary and user-specified
                 files.append(os.path.join(self._rootdir, util.expandpath(path)))
-        return ignore.ignore(self._root, files, self._ui.warn)
+
+        if not files:
+            return util.never
+
+        pats = ['include:%s' % f for f in files]
+        return matchmod.match(self._root, '', [], pats, warn=self._ui.warn)
 
     @propertycache
     def _slash(self):
--- a/mercurial/ignore.py	Sat May 16 15:56:52 2015 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-# ignore.py - ignored file handling for mercurial
-#
-# Copyright 2007 Matt Mackall <mpm@selenic.com>
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-
-from i18n import _
-import util, match
-
-def readpats(root, files, warn):
-    '''return a dict mapping ignore-file-name to list-of-patterns'''
-
-    pats = {}
-    for f in files:
-        if f in pats:
-            continue
-        try:
-            pats[f] = match.readpatternfile(f, warn)
-        except IOError, inst:
-            warn(_("skipping unreadable ignore file '%s': %s\n") %
-                 (f, inst.strerror))
-
-    return [(f, pats[f]) for f in files if f in pats]
-
-def ignore(root, files, warn):
-    '''return matcher covering patterns in 'files'.
-
-    the files parsed for patterns include:
-    .hgignore in the repository root
-    any additional files specified in the [ui] section of ~/.hgrc
-
-    trailing white space is dropped.
-    the escape character is backslash.
-    comments start with #.
-    empty lines are skipped.
-
-    lines can be of the following formats:
-
-    syntax: regexp # defaults following lines to non-rooted regexps
-    syntax: glob   # defaults following lines to non-rooted globs
-    re:pattern     # non-rooted regular expression
-    glob:pattern   # non-rooted glob
-    pattern        # pattern of the current default type'''
-
-    pats = readpats(root, files, warn)
-
-    allpats = []
-    for f, patlist in pats:
-        allpats.extend(patlist)
-    if not allpats:
-        return util.never
-
-    try:
-        ignorefunc = match.match(root, '', [], allpats)
-    except util.Abort:
-        # Re-raise an exception where the src is the right file
-        for f, patlist in pats:
-            try:
-                match.match(root, '', [], patlist)
-            except util.Abort, inst:
-                raise util.Abort('%s: %s' % (f, inst[0]))
-
-    return ignorefunc
--- a/mercurial/match.py	Sat May 16 15:56:52 2015 -0700
+++ b/mercurial/match.py	Sat May 16 16:06:22 2015 -0700
@@ -528,7 +528,21 @@
 def readpatternfile(filepath, warn):
     '''parse a pattern file, returning a list of
     patterns. These patterns should be given to compile()
-    to be validated and converted into a match function.'''
+    to be validated and converted into a match function.
+
+    trailing white space is dropped.
+    the escape character is backslash.
+    comments start with #.
+    empty lines are skipped.
+
+    lines can be of the following formats:
+
+    syntax: regexp # defaults following lines to non-rooted regexps
+    syntax: glob   # defaults following lines to non-rooted globs
+    re:pattern     # non-rooted regular expression
+    glob:pattern   # non-rooted glob
+    pattern        # pattern of the current default type'''
+
     syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:',
                 'include': 'include'}
     syntax = 'relre:'
--- a/tests/test-hgignore.t	Sat May 16 15:56:52 2015 -0700
+++ b/tests/test-hgignore.t	Sat May 16 16:06:22 2015 -0700
@@ -189,3 +189,8 @@
   $ echo "glob:*ignore" > nestedignore
   $ hg status
   A dir/b.o
+
+  $ echo "include:badignore" >> otherignore
+  $ hg status
+  skipping unreadable pattern file 'badignore': No such file or directory
+  A dir/b.o