changeset 2476:0f7e4a39d9af

archive: make "hg archive -t XXX -" to write to stdout
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Wed, 21 Jun 2006 15:15:06 -0700
parents 7a77934ece46
children 857591c586e0
files mercurial/commands.py tests/test-archive tests/test-archive.out
diffstat 3 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Jun 21 09:32:31 2006 -0700
+++ b/mercurial/commands.py	Wed Jun 21 15:15:06 2006 -0700
@@ -780,12 +780,19 @@
                                'specific revision'))
 
     dest = make_filename(repo, repo.changelog, dest, node)
-    prefix = make_filename(repo, repo.changelog, opts['prefix'], node)
     if os.path.realpath(dest) == repo.root:
         raise util.Abort(_('repository root cannot be destination'))
     dummy, matchfn, dummy = matchpats(repo, [], opts)
-    archival.archive(repo, dest, node, opts.get('type') or 'files',
-                    not opts['no_decode'], matchfn, prefix)
+    kind = opts.get('type') or 'files'
+    prefix = opts['prefix']
+    if dest == '-':
+        if kind == 'files':
+            raise util.Abort(_('cannot archive plain files to stdout'))
+        dest = sys.stdout
+        if not prefix: prefix = os.path.basename(repo.root) + '-%h'
+    prefix = make_filename(repo, repo.changelog, prefix, node)
+    archival.archive(repo, dest, node, kind, not opts['no_decode'],
+                     matchfn, prefix)
 
 def backout(ui, repo, rev, **opts):
     '''reverse effect of earlier changeset
--- a/tests/test-archive	Wed Jun 21 09:32:31 2006 -0700
+++ b/tests/test-archive	Wed Jun 21 15:15:06 2006 -0700
@@ -51,3 +51,5 @@
 
 hg archive -t zip -r 2 test.zip
 unzip -t test.zip
+
+hg archive -t tar - | tar tf - | sed "s/$QTIP/TIP/"
--- a/tests/test-archive.out	Wed Jun 21 09:32:31 2006 -0700
+++ b/tests/test-archive.out	Wed Jun 21 15:15:06 2006 -0700
@@ -36,3 +36,7 @@
     testing: test/baz/bletch          OK
     testing: test/foo                 OK
 No errors detected in compressed data of test.zip.
+test-TIP/.hg_archival.txt
+test-TIP/bar
+test-TIP/baz/bletch
+test-TIP/foo