Make kwfiles -u show untracked files only (like status)
authorChristian Ebert <blacktrash@gmx.net>
Thu, 01 Oct 2009 13:39:15 +0200
changeset 653 f4b2fe9d23df
parent 652 d278bbd85f5d
child 654 e188e35ff4ad
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.
hgkw/keyword.py
tests/test-keyword
tests/test-keyword.out
--- a/hgkw/keyword.py	Thu Oct 01 13:39:15 2009 +0200
+++ b/hgkw/keyword.py	Thu Oct 01 13:39:15 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	Thu Oct 01 13:39:15 2009 +0200
+++ b/tests/test-keyword	Thu Oct 01 13:39:15 2009 +0200
@@ -53,6 +53,11 @@
 echo % cat
 cat a b
 
+echo % no kwfiles
+hg kwfiles
+echo % untracked candidates
+hg -v kwfiles --unknown
+
 echo % addremove
 hg addremove
 echo % status
@@ -167,6 +172,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	Thu Oct 01 13:39:15 2009 +0200
+++ b/tests/test-keyword.out	Thu Oct 01 13:39:15 2009 +0200
@@ -38,6 +38,9 @@
 do not process $Id:
 xxx $
 ignore $Id$
+% no kwfiles
+% untracked candidates
+k a
 % addremove
 adding a
 adding b
@@ -177,6 +180,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