# [PATCH] cg-export user the new tar-tree

1 messages from 2005-04-27 to 2005-04-27. Participants: Joshua T. Corbin.
Thread: https://gitlist.dev/t/353

## Joshua T. Corbin, 2005-04-27 20:14

Subject: [PATCH] cg-export user the new tar-tree
Message-ID: <20050427201434.E21BE42F01@node1.wunjo.org>
URL: https://gitlist.dev/e/20050427201434.E21BE42F01%40node1.wunjo.org

```
If at first you don't succeed, try to fix it....failing that, dump kmail and cat | mail ;)

Okay, so this time around, there are REAL-LIVE tabs in this one...

And this time, there are no temporary files...

Signed-off-by: Joshua T. Corbin <jcorbin@wunjo.org>

--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/cg-export  (mode:100755 sha1:d39eb8e723c8cb74c96b64d510f49d1bfcd7d5f8)
+++ 345e15e9173ca1d419a2ff2583696ff4166e5df3/cg-export  (mode:100755 sha1:ff9aa02ff3426e20b09901a291d568bc2ce2b72a)
@@ -8,15 +8,35 @@
 
 . cg-Xlib
 
-destdir=$1
+dest=$1
 id=$(tree-id $2)
 
-([ "$destdir" ] && [ "$id" ]) || die "usage: cg-export DESTDIR [TREE_ID]"
+([ "$dest" ] && [ "$id" ]) || die "usage: cg-export DESTDIR [TREE_ID]"
 
-[ -e "$destdir" ] && die "$destdir already exists."
+[ -e "$dest" ] && die "$dest already exists."
 
-mkdir -p $destdir || die "cannot create $destdir"
-export GIT_INDEX_FILE="$destdir/.git-index"
-read-tree $id
-checkout-cache "--prefix=$destdir/" -a
-rm $GIT_INDEX_FILE
+case $dest in
+	*.tar|*.tar.gz|*.tar.bz2|*.tgz)
+		base=${dest%.tar*};
+		base=${base%.tgz}
+		ext=${dest#$base}
+		case $ext in
+		.tar.gz|.tgz)
+			tar-tree $id "$base" | gzip -c9 $tar > $dest
+			;;
+		.tar.bz2)
+			tar-tree $id "$base" | bzip2 -c $tar > $dest
+			;;
+		.tar)
+			tar-tree $id "$base" > $dest
+			;;
+		esac
+		;;
+	*)
+		mkdir -p $dest || die "cannot create $dest"
+		export GIT_INDEX_FILE="$dest/.git-index"
+		read-tree $id
+		checkout-cache "--prefix=$dest/" -a
+		rm $GIT_INDEX_FILE
+	;;
+esac

```
