[PATCH 4 of 5] Add "ignored" command
Patrick Mezard
pmezard at gmail.com
Sat Sep 15 14:29:52 CDT 2007
# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1189883512 -7200
# Node ID 65c8bb91772ef90db5800f82e42fd95d69df355c
# Parent ce98ef6f3898983f74bb0c879ce82982812eaee0
Add "ignored" command.
Display ignored files and matching pattern location.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1518,6 +1518,28 @@ def identify(ui, repo, source=None,
output.extend(ctx.tags())
ui.write("%s\n" % ' '.join(output))
+
+def ignored(ui, repo, *pats, **opts):
+ """show ignored files
+
+ Show ignored files in the repository and matching pattern
+ location. If names are given, only files that match are shown.
+ """
+
+ showfiles = opts.get('file')
+ files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
+ cwd = (pats and repo.getcwd()) or ''
+
+ ignored = repo.status(files=files, match=matchfn, list_ignored=True)[5]
+ debugignore = repo.dirstate.debugignore
+ ignored = [(f, debugignore(f)) for f in ignored]
+
+ for f, (source, linenum, line) in ignored:
+ ui.write("%s\n" % repo.pathto(f, cwd))
+ if showfiles:
+ ui.write(_(" file: %s\n") % source)
+ ui.write(_(" line: %d\n") % linenum)
+ ui.write(_(" pattern: %s\n") % util.uirepr(line))
def import_(ui, repo, patch1, *patches, **opts):
"""import an ordered set of patches
@@ -2945,6 +2967,11 @@ table = {
('b', 'branch', None, _('show branch')),
('t', 'tags', None, _('show tags'))],
_('hg identify [-nibt] [-r REV] [SOURCE]')),
+ "ignored":
+ (ignored,
+ [(('f', 'file', None, _('show matching ignore file path'))),
+ ] + walkopts,
+ _('hg ignored [OPTION]... [FILE]...')),
"import|patch":
(import_,
[('p', 'strip', 1,
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -52,13 +52,18 @@ class dirstate(object):
for f in self._map:
self._incpath(f)
return self._dirs
- elif name == '_ignore':
+ elif name in ('_ignore', '_debugignore'):
files = [self._join('.hgignore')]
- for name, path in self._ui.configitems("ui"):
- if name == 'ignore' or name.startswith('ignore.'):
+ for varname, path in self._ui.configitems("ui"):
+ if varname == 'ignore' or varname.startswith('ignore.'):
files.append(os.path.expanduser(path))
- self._ignore = ignore.ignore(self._root, files, self._ui.warn)
- return self._ignore
+ if name == '_ignore':
+ self._ignore = ignore.ignore(self._root, files, self._ui.warn)
+ return self._ignore
+ else:
+ self._debugignore = ignore.debugignore(self._root,
+ files, self._ui.warn)
+ return self._debugignore
elif name == '_slash':
self._slash = self._ui.configbool('ui', 'slash') and os.sep != '/'
return self._slash
@@ -159,7 +164,7 @@ class dirstate(object):
pos = newpos
def invalidate(self):
- for a in "_map _copymap _branch _pl _dirs _ignore".split():
+ for a in "_map _copymap _branch _pl _dirs _ignore _debugignore".split():
if a in self.__dict__:
delattr(self, a)
self._dirty = False
@@ -545,3 +550,6 @@ class dirstate(object):
return (lookup, modified, added, removed, deleted, unknown, ignored,
clean)
+
+ def debugignore(self, filename):
+ return self._debugignore(filename)
More information about the Mercurial-devel
mailing list