dirstate: add a way to get the ignore file/line matching an ignored file
authorLaurent Charignon <lcharignon@fb.com>
Tue, 05 Jan 2016 07:52:04 -0800
changeset 27670 4374f039d269
parent 27669 b1824a1725ed
child 27671 067d87feeb11
dirstate: add a way to get the ignore file/line matching an ignored file This information will be used to improve debugignore (issue4856).
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Tue Jan 05 19:59:21 2016 +0000
+++ b/mercurial/dirstate.py	Tue Jan 05 07:52:04 2016 -0800
@@ -7,6 +7,7 @@
 
 from __future__ import absolute_import
 
+import collections
 import errno
 import os
 import stat
@@ -777,6 +778,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.