changeset 9493:fe1ecd15c6bd

keyword: make kwfiles -u show untracked files only (like status) Remove extra documentation of -u/--unknown, as this is covered in the option help already. Like commands.status the code now zips the status flags. Add more kwfiles tests.
author Christian Ebert <blacktrash@gmx.net>
date Wed, 30 Sep 2009 23:59:03 +0200
parents 3b1864bcc58f
children bdd8a41ea6f6
files hgext/keyword.py tests/test-keyword tests/test-keyword.out
diffstat 3 files changed, 33 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/keyword.py	Wed Sep 30 23:59:03 2009 +0200
+++ b/hgext/keyword.py	Wed Sep 30 23:59:03 2009 +0200
@@ -382,8 +382,6 @@
     See "hg help keyword" on how to construct patterns both for
     inclusion and exclusion of files.
 
-    Use -u/--unknown to list unknown (not tracked) files as well.
-
     With -a/--all and -v/--verbose the codes used to show the status
     of files are::
 
@@ -394,18 +392,22 @@
     '''
     kwt = kwtools['templater']
     status = _status(ui, repo, kwt, *pats, **opts)
+    cwd = pats and repo.getcwd() or ''
     modified, added, removed, deleted, unknown, ignored, clean = status
-    files = sorted(modified + added + clean)
+    files = []
+    if not (opts.get('unknown') or opts.get('untracked')) or opts.get('all'):
+        files = sorted(modified + added + clean)
     wctx = repo[None]
     kwfiles = [f for f in files if kwt.iskwfile(f, wctx.flags)]
     kwunknown = [f for f in unknown if kwt.iskwfile(f, wctx.flags)]
-    cwd = pats and repo.getcwd() or ''
-    kwfstats = (not opts.get('ignore') and
-                (('K', kwfiles), ('k', kwunknown),) or ())
+    if not opts.get('ignore') or opts.get('all'):
+        showfiles = kwfiles, kwunknown
+    else:
+        showfiles = [], []
     if opts.get('all') or opts.get('ignore'):
-        kwfstats += (('I', [f for f in files if f not in kwfiles]),
-                     ('i', [f for f in unknown if f not in kwunknown]),)
-    for char, filenames in kwfstats:
+        showfiles += ([f for f in files if f not in kwfiles],
+                      [f for f in unknown if f not in kwunknown])
+    for char, filenames in zip('KkIi', showfiles):
         fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n'
         for f in filenames:
             ui.write(fmt % repo.pathto(f, cwd))
@@ -549,10 +551,8 @@
         (files,
          [('a', 'all', None, _('show keyword status flags of all files')),
           ('i', 'ignore', None, _('show files excluded from expansion')),
-          ('u', 'unknown', None,
-           _('additionally show unknown (not tracked) files')),
-          ('u', 'untracked', None,
-           _('additionally show untracked files (DEPRECATED)')),
+          ('u', 'unknown', None, _('only show unknown (not tracked) files')),
+          ('u', 'untracked', None, _('only show untracked files (DEPRECATED)')),
          ] + commands.walkopts,
          _('hg kwfiles [OPTION]... [FILE]...')),
     'kwshrink': (shrink, commands.walkopts,
--- a/tests/test-keyword	Wed Sep 30 23:59:03 2009 +0200
+++ b/tests/test-keyword	Wed Sep 30 23:59:03 2009 +0200
@@ -48,6 +48,11 @@
 echo % cat
 cat a b
 
+echo % no kwfiles
+hg kwfiles
+echo % untracked candidates
+hg -v kwfiles --unknown
+
 echo % addremove
 hg addremove
 echo % status
@@ -162,6 +167,10 @@
 
 echo % kwfiles
 hg kwfiles
+echo % ignored files
+hg -v kwfiles --ignore
+echo % all files
+hg kwfiles --all
 
 echo % diff --rev
 hg diff --rev 1 | grep -v 'b/c'
--- a/tests/test-keyword.out	Wed Sep 30 23:59:03 2009 +0200
+++ b/tests/test-keyword.out	Wed Sep 30 23:59:03 2009 +0200
@@ -42,6 +42,9 @@
 do not process $Id:
 xxx $
 ignore $Id$
+% no kwfiles
+% untracked candidates
+k a
 % addremove
 adding a
 adding b
@@ -181,6 +184,14 @@
 % kwfiles
 a
 c
+% ignored files
+I b
+I sym
+% all files
+K a
+K c
+I b
+I sym
 % diff --rev
 diff -r ef63ca68695b c
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000