diff mercurial/commands.py @ 21040:bdf5ed5246d2

cat: move most of the implementation into cmdutils.cat() This will allow access to the reusable parts from subrepos, similar to add(), forget(), etc.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 13 Mar 2014 23:45:18 -0400
parents a1a1bd09e4f4
children a2cc3c08c3ac
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Apr 15 17:51:27 2014 -0400
+++ b/mercurial/commands.py	Thu Mar 13 23:45:18 2014 -0400
@@ -1172,32 +1172,9 @@
     Returns 0 on success.
     """
     ctx = scmutil.revsingle(repo, opts.get('rev'))
-    err = 1
     m = scmutil.match(ctx, (file1,) + pats, opts)
 
-    def write(path):
-        fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
-                                 pathname=path)
-        data = ctx[path].data()
-        if opts.get('decode'):
-            data = repo.wwritedata(path, data)
-        fp.write(data)
-        fp.close()
-
-    # Automation often uses hg cat on single files, so special case it
-    # for performance to avoid the cost of parsing the manifest.
-    if len(m.files()) == 1 and not m.anypats():
-        file = m.files()[0]
-        mf = repo.manifest
-        mfnode = ctx._changeset[0]
-        if mf.find(mfnode, file)[0]:
-            write(file)
-            return 0
-
-    for abs in ctx.walk(m):
-        write(abs)
-        err = 0
-    return err
+    return cmdutil.cat(ui, repo, ctx, m, **opts)
 
 @command('^clone',
     [('U', 'noupdate', None,