changeset 13396:3e66eec9a814

add debugignore which yields the combined ignore patten of the .hgignore files For GUI clients its sometimes important to know which files will be ignored and which files will be important. This allows the GUI client to skipping redoing a 'hg status' when the files are ignored but have changed. (For instance, a typical case is that the "build" directory inside some project is ignored but files in it frequently change.)
author jfh <jason@jasonfharris.com>
date Sat, 15 Jan 2011 16:02:03 +0100
parents 104c9ed93fc5
children 6f9616a46f7c
files mercurial/commands.py mercurial/match.py tests/test-debugcomplete.t tests/test-hgignore.t
diffstat 4 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Feb 04 16:32:14 2011 -0300
+++ b/mercurial/commands.py	Sat Jan 15 16:02:03 2011 +0100
@@ -1351,6 +1351,11 @@
         m = util.matchdate(range)
         ui.write("match: %s\n" % m(d[0]))
 
+def debugignore(ui, repo, *values, **opts):
+    """display the combined ignore pattern"""
+    ignore = repo.dirstate._ignore
+    ui.write("%s\n" % ignore.includepat)
+
 def debugindex(ui, repo, file_, **opts):
     """dump the contents of an index file"""
     r = None
@@ -4347,6 +4352,7 @@
          _('[-e] DATE [RANGE]')),
     "debugdata": (debugdata, [], _('FILE REV')),
     "debugfsinfo": (debugfsinfo, [], _('[PATH]')),
+    "debugignore": (debugignore, [], ''),
     "debugindex": (debugindex,
                    [('f', 'format', 0, _('revlog format'), _('FORMAT'))],
                    _('FILE')),
--- a/mercurial/match.py	Fri Feb 04 16:32:14 2011 -0300
+++ b/mercurial/match.py	Sat Jan 15 16:02:03 2011 +0100
@@ -39,11 +39,11 @@
         self._anypats = bool(include or exclude)
 
         if include:
-            im = _buildmatch(_normalize(include, 'glob', root, cwd, auditor),
-                             '(?:/|$)')
+            pats = _normalize(include, 'glob', root, cwd, auditor)
+            self.includepat, im = _buildmatch(pats, '(?:/|$)')
         if exclude:
-            em = _buildmatch(_normalize(exclude, 'glob', root, cwd, auditor),
-                             '(?:/|$)')
+            pats = _normalize(exclude, 'glob', root, cwd, auditor)
+            self.excludepat, em = _buildmatch(pats, '(?:/|$)')
         if exact:
             self._files = patterns
             pm = self.exact
@@ -51,7 +51,7 @@
             pats = _normalize(patterns, default, root, cwd, auditor)
             self._files = _roots(pats)
             self._anypats = self._anypats or _anypats(pats)
-            pm = _buildmatch(pats, '$')
+            self.patternspat, pm = _buildmatch(pats, '$')
 
         if patterns or exact:
             if include:
@@ -246,7 +246,7 @@
         pat = '(?:%s)' % '|'.join([_regex(k, p, tail) for (k, p) in pats])
         if len(pat) > 20000:
             raise OverflowError()
-        return re.compile(pat).match
+        return pat, re.compile(pat).match
     except OverflowError:
         # We're using a Python with a tiny regex engine and we
         # made it explode, so we'll divide the pattern list in two
@@ -254,8 +254,9 @@
         l = len(pats)
         if l < 2:
             raise
-        a, b = _buildmatch(pats[:l//2], tail), _buildmatch(pats[l//2:], tail)
-        return lambda s: a(s) or b(s)
+        pata, a = _buildmatch(pats[:l//2], tail),
+        patb, b = _buildmatch(pats[l//2:], tail)
+        return pat, lambda s: a(s) or b(s)
     except re.error:
         for k, p in pats:
             try:
--- a/tests/test-debugcomplete.t	Fri Feb 04 16:32:14 2011 -0300
+++ b/tests/test-debugcomplete.t	Sat Jan 15 16:02:03 2011 +0100
@@ -75,6 +75,7 @@
   debugdata
   debugdate
   debugfsinfo
+  debugignore
   debugindex
   debugindexdot
   debuginstall
@@ -214,6 +215,7 @@
   debugdata: 
   debugdate: extended
   debugfsinfo: 
+  debugignore: 
   debugindex: format
   debugindexdot: 
   debuginstall: 
--- a/tests/test-hgignore.t	Fri Feb 04 16:32:14 2011 -0300
+++ b/tests/test-hgignore.t	Sat Jan 15 16:02:03 2011 +0100
@@ -120,3 +120,5 @@
   $ hg status .
   A b.o
 
+  $ hg debugignore
+  (?:(?:|.*/)[^/]*(?:/|$))