[PATCH] Option --decode for hg cat to apply decode filters

Jesse Glick Jesse.Glick at Sun.COM
Sat Feb 9 12:13:20 CST 2008


# HG changeset patch
# User Jesse Glick <jesse.glick at sun.com>
# Date 1202580322 18000
# Node ID b7a9b52d57edfa8e93f562185e62e4fc6437cd9e
# Parent  e2cbdd93134105f9c11f05c6e2a4c32e5a0e6945
Option --decode for hg cat to apply decode filters.

(Does not trigger expansion of keyword arguments when using keyword
extension, though that might be desirable as well.)

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -466,7 +466,10 @@ def cat(ui, repo, file1, *pats, **opts):
     for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
                                              ctx.node()):
         fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
-        fp.write(ctx.filectx(abs).data())
+        data = ctx.filectx(abs).data()
+        if opts['decode']:
+            data = repo.wwritedata(abs, data)
+        fp.write(data)
         err = 0
     return err
 
@@ -2758,6 +2761,7 @@ table = {
         (cat,
          [('o', 'output', '', _('print output to file with formatted name')),
           ('r', 'rev', '', _('print the given revision')),
+          ('d', 'decode', None, _('apply any matching decode filter')),
          ] + walkopts,
          _('hg cat [OPTION]... FILE...')),
     "^clone":
diff --git a/tests/test-cat b/tests/test-cat
--- a/tests/test-cat
+++ b/tests/test-cat
@@ -8,6 +8,7 @@ hg ci -A -m m -d "1000000 0"
 hg ci -A -m m -d "1000000 0"
 hg rm a
 hg cat a
+hg cat --decode a # more tests in test-encode
 sleep 1 # make sure mtime is changed
 echo 1 > b
 hg ci -m m -d "1000000 0"
diff --git a/tests/test-cat.out b/tests/test-cat.out
--- a/tests/test-cat.out
+++ b/tests/test-cat.out
@@ -3,5 +3,6 @@ 0
 0
 0
 0
+0
 a: No such file in rev 03f6b0774996
 1
diff --git a/tests/test-dispatch.out b/tests/test-dispatch.out
--- a/tests/test-dispatch.out
+++ b/tests/test-dispatch.out
@@ -21,6 +21,7 @@ options:
 
  -o --output   print output to file with formatted name
  -r --rev      print the given revision
+ -d --decode   apply any matching decode filter
  -I --include  include names matching the given patterns
  -X --exclude  exclude names matching the given patterns
 
diff --git a/tests/test-encode b/tests/test-encode
--- a/tests/test-encode
+++ b/tests/test-encode
@@ -32,3 +32,11 @@ hg co
 
 echo %% uncompress our new working dir copy
 gunzip < a.gz
+
+echo %% check hg cat operation
+hg cat a.gz
+hg cat -d a.gz | gunzip
+mkdir subdir
+cd subdir
+hg -R .. cat ../a.gz
+hg -R .. cat -d ../a.gz | gunzip
diff --git a/tests/test-encode.out b/tests/test-encode.out
--- a/tests/test-encode.out
+++ b/tests/test-encode.out
@@ -7,3 +7,8 @@ 1 files updated, 0 files merged, 0 files
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 %% uncompress our new working dir copy
 this is a test
+%% check hg cat operation
+this is a test
+this is a test
+this is a test
+this is a test


More information about the Mercurial-devel mailing list