hg status: add option -f to select filetype

Thomas Arendsen Hein thomas at intevation.de
Sat Aug 6 06:09:34 CDT 2005


* TK Soh <teekaysoh at yahoo.com> [20050722 02:44]:
> +    filetype = "";
> +    if opts['modified']: filetype += "M";
> +    if opts[   'added']: filetype += "A";
> +    if opts[ 'removed']: filetype += "R";
> +    if opts[ 'unknown']: filetype += "?";

Python doesn't need ; at the end, but I've rewritten this code
anyway, so they're gone.

* TK Soh <teekaysoh at yahoo.com> [20050806 04:21]:
> I wonder if the Hg team has considered this patch for commit.

I like it and so I included it with some changes to my tree.

Attached and pullable as usual.

Thomas

-- 
Email: thomas at intevation.de
http://intevation.de/~thomas/
-------------- next part --------------
# HG changeset patch
# User tksoh at users.sourceforge.net
# Node ID 141744605b516a4011f29f2bd5347cb5d0743336
# Parent  9c918287d10b4018e27f9148e247e68ff5fe952c
hg status: added options to select files by status.

Added options -m, -a, -r and u to select files corresponding
to status M, A, R and ? respectively. If none of these
options are specified, files of all status will be shown.

diff -r 9c918287d10b4018e27f9148e247e68ff5fe952c -r 141744605b516a4011f29f2bd5347cb5d0743336 doc/hg.1.txt
--- a/doc/hg.1.txt	Thu Aug  4 21:31:25 2005
+++ b/doc/hg.1.txt	Sat Aug  6 06:09:10 2005
@@ -346,6 +346,10 @@
 
     options:
 
+    -m, --modified       show only modified files
+    -a, --added          show only added files
+    -r, --removed        show only removed files
+    -u, --unknown        show only unknown (not tracked) files
     -I, --include <pat>  include names matching the given patterns
     -X, --exclude <pat>  exclude names matching the given patterns
 
diff -r 9c918287d10b4018e27f9148e247e68ff5fe952c -r 141744605b516a4011f29f2bd5347cb5d0743336 mercurial/commands.py
--- a/mercurial/commands.py	Thu Aug  4 21:31:25 2005
+++ b/mercurial/commands.py	Sat Aug  6 06:09:10 2005
@@ -1040,14 +1040,17 @@
     (c, a, d, u) = [[pathto(cwd, x) for x in n]
                     for n in repo.changes(files=files, match=matchfn)]
 
-    for f in c:
-        ui.write("M ", f, "\n")
-    for f in a:
-        ui.write("A ", f, "\n")
-    for f in d:
-        ui.write("R ", f, "\n")
-    for f in u:
-        ui.write("? ", f, "\n")
+    filetype = "";
+    if opts['modified']: filetype += "M";
+    if opts[   'added']: filetype += "A";
+    if opts[ 'removed']: filetype += "R";
+    if opts[ 'unknown']: filetype += "?";
+    if filetype == "" : filetype = "MAR?"
+    
+    for key, value in zip(["M", "A", "R", "?"], (c, a, d, u)):
+        if value and filetype.find(key) >= 0:
+            for f in value:
+                ui.write("%s " % key, f, "\n")
 
 def tag(ui, repo, name, rev=None, **opts):
     """add a tag for the current tip or a given revision"""
@@ -1261,10 +1264,15 @@
           ('t', 'templates', "", 'template map'),
           ('6', 'ipv6', None, 'use IPv6 in addition to IPv4')],
          "hg serve [OPTION]..."),
-    "^status": (status,
-                [('I', 'include', [], 'include path in search'),
-                 ('X', 'exclude', [], 'exclude path from search')],
-                'hg status [FILE]...'),
+    "^status":
+        (status,
+         [('m', 'modified', None, 'show only modified files'),
+          ('a', 'added', None, 'show only added files'),
+          ('r', 'removed', None, 'show only removed files'),
+          ('u', 'unknown', None, 'show only unknown (not tracked) files'),
+          ('I', 'include', [], 'include path in search'),
+          ('X', 'exclude', [], 'exclude path from search')],
+         "hg status [FILE]..."),
     "tag":
         (tag,
          [('l', 'local', None, 'make the tag local'),
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID 03cc2ba291d119823d613084b87ca1dbec358966
# Parent  141744605b516a4011f29f2bd5347cb5d0743336
Realigned command table again.

diff -r 141744605b516a4011f29f2bd5347cb5d0743336 -r 03cc2ba291d119823d613084b87ca1dbec358966 mercurial/commands.py
--- a/mercurial/commands.py	Sat Aug  6 06:09:10 2005
+++ b/mercurial/commands.py	Sat Aug  6 06:16:37 2005
@@ -1143,14 +1143,16 @@
 # Command options and aliases are listed here, alphabetically
 
 table = {
-    "^add": (add,
-             [('I', 'include', [], 'include path in search'),
-              ('X', 'exclude', [], 'exclude path from search')],
-             "hg add [FILE]..."),
-    "addremove": (addremove,
-                  [('I', 'include', [], 'include path in search'),
-                   ('X', 'exclude', [], 'exclude path from search')],
-                  "hg addremove [OPTION]... [FILE]..."),
+    "^add":
+        (add,
+         [('I', 'include', [], 'include path in search'),
+          ('X', 'exclude', [], 'exclude path from search')],
+         "hg add [FILE]..."),
+    "addremove":
+        (addremove,
+         [('I', 'include', [], 'include path in search'),
+          ('X', 'exclude', [], 'exclude path from search')],
+         "hg addremove [OPTION]... [FILE]..."),
     "^annotate":
         (annotate,
          [('r', 'rev', '', 'revision'),
@@ -1184,10 +1186,11 @@
     "debugstate": (debugstate, [], 'debugstate'),
     "debugindex": (debugindex, [], 'debugindex FILE'),
     "debugindexdot": (debugindexdot, [], 'debugindexdot FILE'),
-    "debugwalk": (debugwalk,
-                  [('I', 'include', [], 'include path in search'),
-                   ('X', 'exclude', [], 'exclude path from search')],
-                  'debugwalk [OPTIONS]... [FILE]...'),
+    "debugwalk":
+        (debugwalk,
+         [('I', 'include', [], 'include path in search'),
+          ('X', 'exclude', [], 'exclude path from search')],
+         'debugwalk [OPTIONS]... [FILE]...'),
     "^diff":
         (diff,
          [('r', 'rev', [], 'revision'),
@@ -1198,10 +1201,11 @@
         (export,
          [('o', 'output', "", 'output to file')],
          "hg export [-o OUTFILE] REV..."),
-    "forget": (forget,
-               [('I', 'include', [], 'include path in search'),
-                ('X', 'exclude', [], 'exclude path from search')],
-               "hg forget FILE..."),
+    "forget":
+        (forget,
+         [('I', 'include', [], 'include path in search'),
+          ('X', 'exclude', [], 'exclude path from search')],
+         "hg forget FILE..."),
     "heads": (heads, [], 'hg heads'),
     "help": (help_, [], 'hg help [COMMAND]'),
     "identify|id": (identify, [], 'hg identify'),
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID 8fb4887730637b402513809c332f69c388b74b97
# Parent  03cc2ba291d119823d613084b87ca1dbec358966
Rewritten change type selection for hg status.

diff -r 03cc2ba291d119823d613084b87ca1dbec358966 -r 8fb4887730637b402513809c332f69c388b74b97 mercurial/commands.py
--- a/mercurial/commands.py	Sat Aug  6 06:16:37 2005
+++ b/mercurial/commands.py	Sat Aug  6 11:05:09 2005
@@ -1033,24 +1033,23 @@
     M = modified
     A = added
     R = removed
-    ? = not tracked'''
+    ? = not tracked
+    '''
 
     cwd = repo.getcwd()
     files, matchfn = matchpats(cwd, pats, opts)
     (c, a, d, u) = [[pathto(cwd, x) for x in n]
                     for n in repo.changes(files=files, match=matchfn)]
 
-    filetype = "";
-    if opts['modified']: filetype += "M";
-    if opts[   'added']: filetype += "A";
-    if opts[ 'removed']: filetype += "R";
-    if opts[ 'unknown']: filetype += "?";
-    if filetype == "" : filetype = "MAR?"
-    
-    for key, value in zip(["M", "A", "R", "?"], (c, a, d, u)):
-        if value and filetype.find(key) >= 0:
-            for f in value:
-                ui.write("%s " % key, f, "\n")
+    changetypes = [('modified', 'M', c),
+                   ('added', 'A', a),
+                   ('removed', 'R', d),
+                   ('unknown', '?', u)]
+
+    for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]]
+                               or changetypes):
+        for f in changes:
+            ui.write("%s %s\n" % (char, f))
 
 def tag(ui, repo, name, rev=None, **opts):
     """add a tag for the current tip or a given revision"""


More information about the Mercurial mailing list