# HG changeset patch # User Laurent Charignon # Date 2016-01-05 15:52:04 # Node ID 4374f039d2691e3b4c635fa0c1a2d1f252bd9952 # Parent b1824a1725ed84fb7dea751ed52dab359ef9f1ed 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 @@ -7,6 +7,7 @@ from __future__ import absolute_import +import collections import errno import os import stat @@ -777,6 +778,26 @@ class dirstate(object): 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.