[PATCH] Allow multiple .hgignore files

tailgunner at smtp.ru tailgunner at smtp.ru
Tue Feb 13 16:32:31 CST 2007


Allow multiple .hgignore files in a single repository


 Note that non-repository-root .hgignore files are treated differently
from root one.


diff -r 01855c47da37 -r 0f35560bc179 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Wed Feb 14 01:05:09 2007 +0300
+++ b/mercurial/dirstate.py	Wed Feb 14 01:05:09 2007 +0300
@@ -41,7 +41,7 @@ class dirstate(object):
         '''return the contents of .hgignore files as a list of patterns.
 
         the files parsed for patterns include:
-        .hgignore in the repository root
+        all .hgignore files in the repository
         any additional files specified in the [ui] section of ~/.hgrc
 
         trailing white space is dropped.
@@ -55,7 +55,11 @@ class dirstate(object):
         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'''
+        pattern        # pattern of the current default type
+
+         Every pattern has the name of its containing directory prepended to
+        it (this name is empty string for .hgignore in the repository root 
+        and ~/.hgrc ignore files). '''
         syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:'}
         def parselines(fp):
             for line in fp:
@@ -67,10 +71,21 @@ class dirstate(object):
                 line = line[:i].rstrip()
                 if line: yield line
         repoignore = self.wjoin('.hgignore')
-        files = [repoignore]
-        files.extend(self.ui.hgignorefiles())
+        # .hgignore in repository root is considered always (we don't even
+        # check if it exists prior to opening it)
+        files = [(repoignore, "")]
+        # ...but the rest of .hgignore files are considered only if they are
+        # managed by Mercurial
+        for f in self.map.keys():
+            if f == ".hgignore":
+	        pass # skip root .hgignore
+            elif f.endswith(".hgignore"):
+                cd = f[:len(f) - len(".hgignore")]
+                files.append((self.wjoin(f), cd))
+        for f in self.ui.hgignorefiles():
+            files.append((self.wjoin(f), ""))
         pats = {}
-        for f in files:
+        for f, cd in files:
             try:
                 pats[f] = []
                 fp = open(f)
@@ -84,7 +99,7 @@ class dirstate(object):
                             self.ui.warn(_("%s: ignoring invalid "
                                            "syntax '%s'\n") % (f, s))
                         continue
-                    pat = syntax + line
+                    pat = syntax + cd + line
                     for s in syntaxes.values():
                         if line.startswith(s):
                             pat = line



More information about the Mercurial-devel mailing list