[PATCH 3 of 5] dirstate: add a way to get the ignore file/line matching an ignored file

Laurent Charignon lcharignon at fb.com
Wed Dec 23 14:42:20 CST 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1450902341 28800
#      Wed Dec 23 12:25:41 2015 -0800
# Node ID 11d0d62e0579a0b8c06f3cb2fc5a8ae2de5e9177
# Parent  391510022f76e3fc135b78b4cb14dec73a3761cb
dirstate: add a way to get the ignore file/line matching an ignored file

This information will be used to improve debugignore (issue4856).

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -8,7 +8,7 @@
 from node import nullid
 from i18n import _
 import scmutil, util, osutil, parsers, encoding, pathutil, error
-import os, stat, errno
+import os, stat, errno, collections
 import match as matchmod
 
 propertycache = util.propertycache
@@ -738,6 +738,26 @@
                 files.append(os.path.join(self._rootdir, util.expandpath(path)))
         return files
 
+    def _ignorefileandline(self, f):
+        files = collections.deque(self._ignorefiles())
+        visited = set()
+        while files:
+            i = files.popleft()
+            patterns = matchmod.readpatternfile(i, self._ui.warn,
+                                                sourceinfo=True)
+            for pattern, lineno, line in patterns:
+                kind, p = matchmod._patsplit(pattern, 'glob')
+                if kind == "subinclude":
+                    if p not in visited:
+                        files.append(p)
+                    continue
+                m = matchmod.match(self._root, '', [], [pattern],
+                                   warn=self._ui.warn)
+                if m(f):
+                    return (i, lineno, line)
+            visited.add(i)
+        return (None, -1, "")
+
     def _walkexplicit(self, match, subrepos):
         '''Get stat data about the files explicitly specified by match.
 


More information about the Mercurial-devel mailing list