# [PATCH] cg-export to tarball

3 messages from 2005-04-26 to 2005-04-26. Participants: Joshua T. Corbin, Petr Baudis, Rene Scharfe.
Thread: https://gitlist.dev/t/322

## Joshua T. Corbin, 2005-04-26 07:12

Subject: [PATCH] cg-export to tarball
Message-ID: <200504260312.46320.jcorbin@wunjo.org>
URL: https://gitlist.dev/e/200504260312.46320.jcorbin%40wunjo.org

```
The following patch to cg-export will simlpy create a tarball if the argument 
ends in .tar.gz, .tar.bz2, or .tar.

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

Index: cg-export
===================================================================
--- c7eec90959408a71c465b36e728113a2754f99df/cg-export  (mode:100755 
sha1:94d419de48a12f1ea1059451ac4cd489f7008916)
+++ b839b802f91e79ea7b0bb7dcf3e228659bf96a87/cg-export  (mode:100755 
sha1:29834b2749b0a8d7c71a4c67325e4f5ece9d28a0)
@@ -24,8 +24,33 @@
 
 [ -e "$destdir" ] && die "$destdir already exists."
 
+case $destdir in
+  *.tar*)
+    tarfile=$destdir
+    destdir=${destdir%.tar*}
+    ;;
+esac
+
 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
+
+[ -z "$tarfile" ] && exit 0
+
+case $tarfile in
+  *.tar.gz)
+    tar -cvzf $tarfile $destdir || die "Failed to create $tarfile"
+    ;;
+  *.tar.bz2)
+    tar -cvjf $tarfile $destdir || die "Failed to create $tarfile"
+    ;;
+  *.tar)
+    tar -cvf $tarfile $destdir || die "Failed to create $tarfile"
+    ;;
+  *)
+    die "Don't know how to make a ${tarfile#$destdir} file"
+    ;;
+esac
+rm -fr $destdir

```

## Petr Baudis, 2005-04-26 20:20

Subject: Re: [PATCH] cg-export to tarball
Message-ID: <20050426202014.GJ13224@pasky.ji.cz>
URL: https://gitlist.dev/e/20050426202014.GJ13224%40pasky.ji.cz
In-Reply-To: <200504260312.46320.jcorbin@wunjo.org>

```
Dear diary, on Tue, Apr 26, 2005 at 09:12:46AM CEST, I got a letter
where "Joshua T. Corbin" <jcorbin@wunjo.org> told me that...
> The following patch to cg-export will simlpy create a tarball if the argument 
> ends in .tar.gz, .tar.bz2, or .tar.
> 
> Signed-off-by; Joshua T. Corbin <jcorbin@wunjo.org>

What about cooperating with Rene Scharfe and using his tar-tree?
I didn't actually try it yet (not even look at the code so far),
it'd be cool if someone would give it some review and testing.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

```

## Rene Scharfe, 2005-04-26 22:24

Subject: Re: [PATCH] cg-export to tarball
Message-ID: <426EBF8E.5000906@lsrfire.ath.cx>
URL: https://gitlist.dev/e/426EBF8E.5000906%40lsrfire.ath.cx
In-Reply-To: <20050426202014.GJ13224@pasky.ji.cz>

```
Petr Baudis schrieb:
> Dear diary, on Tue, Apr 26, 2005 at 09:12:46AM CEST, I got a letter 
> where "Joshua T. Corbin" <jcorbin@wunjo.org> told me that...
> 
>> The following patch to cg-export will simlpy create a tarball if 
>> the argument ends in .tar.gz, .tar.bz2, or .tar.
>> 
>> Signed-off-by; Joshua T. Corbin <jcorbin@wunjo.org>
> 
> 
> What about cooperating with Rene Scharfe and using his tar-tree? I 
> didn't actually try it yet (not even look at the code so far), it'd 
> be cool if someone would give it some review and testing.

Yes, this looks like a job for tar-tree.  You could do something like this:

   destbasename=${destdir##*/}
   case "$destdir" in
   *.tar)
       tar-tree $id "${destbasename%.tar}" > "$destdir"
       ;;
   *.tgz)
       tar-tree $id "${destbasename%.tgz}" | gzip -9 > "$destdir"
       ;;
   # *.tar.gz, *.tar.bz2, ...
   *)
       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"
       ;;
   esac

The second parameter to tar-tree is an optional prefix for all paths
inside the archive (official kernel tarballs always have linux-2.x.xx as
a prefix).  It makes some sense to set this value to the archive
filename, "cg-export linux-2.6.12-rc3.tar.bz2" would than work as expected.

What do you think?  If you like it I'll cook up a patch later unless you
beat me to it.

Thanks,
Rene

```
