GIT: Create tar archives of tree on the fly
PATCH 1/1 GIT: Create tar archives of tree on the fly
This patch introduces tar-tree, a tool to generate tar archives out of git repositories. Basically I took ls-tree and cat-file and melted them together. That means tar-tree doesn't create any temporary files, it just streams out the archive as it goes.
This could be useful for the web interface(s) to provide a downloadable tarball for any commit or tree object. For bigger repositories like the Linux kernel caching the resulting files might be a good idea, though. :-P
On my machine it's also a bit faster than directly tarring up the checked out files. I only ran a few basic checks to make sure the performance is in the same ballpark, YMMV.
Example usage:
$ tar-tree a2755a80f40e5794ddc20e00f781af9d6320fafb linux-2.6.12-rc3 |
bzip2 -9 > linux-2.6.12-rc3.tar.bz2tar-tree accepts tree IDs and commit IDs. In the former case all files within the archive get the current time set as mtime. Given a commit ID tar-tree tries to figure out the commit date and sets mtime of all files to that instead.
Currently the size of a file within the created archive is limited to 2^33-1. This could be fixed easily within the archive format (with a Pax extended header), but size is unsigned long throughout GIT, so this would need to be fixed first. OTOH I think putting 4GB+ files into a GIT archive is insane anyway. :]
Path names are limited to 500 characters at the moment. This can be stretched if the need should arise.
Patch is against d1df5743809614241883ecad51876607cf432034.
Makefile +1 -1
@@ -18,7 +18,7 @@ cat-file fsck-cache checkout-cache diff-tree rev-tree show-files \ check-files ls-tree merge-base merge-cache unpack-file git-export \ diff-cache convert-cache http-pull rpush rpull rev-list git-mktag \ - diff-tree-helper + diff-tree-helper tar-tree all: $(PROG)
tar-tree.c +328 -0
328 lines not on this page · raw message
Having just done the git-0.7.tar.gz file with git-tar-tree, I started wondering if there is some nice way to encode the commit version that got tarred up into the tar archive itself.
There are various obvious ways, like creating a fake zero-sized file called <base>/.git-version-<commit-id>, and maybe that's the right thing to do. But maybe the tar archive format (and no, I don't even want to know details) has some nice way to hide off a keyname even _without_ having to create a file.
Would people like to have such a file for later? Obviously there would be a need to suppress it with a command line flag if you don't want it (or have a cmd line flag to enable it in the first place), what do people think? Rene?
Linus
Quoted 5 lines · Linus Torvalds
Having just done the git-0.7.tar.gz file with git-tar-tree, I started wondering if there is some nice way to encode the commit version that got tarred up into the tar archive itself.
... and here is the patch that changes git-tar-tree to add the commit ID as a comment in a global pax header to the tar file. Archivers ignore this field. A little sample program is included to read the ID from a previously prepared archive.
Write commit ID to global extended pax header at the beginning of the tar file, if possible. get-tar-commit-id.c is an example program to get the ID back out of such a tar archive.
---
commit 716d21c45ba1c329fb88febf4704a4ab629a3933
tree 72f4d42eac2cd9099a663c16cb8201f90a8ff9c9
parent 0fc65a4572625405ff6dd9d8c16d835f2b1ebd49
author Rene Scharfe <[email protected]> 1114812895 +0200 committer Rene Scharfe <[email protected]> 1114812895 +0200
get-tar-commit-id.c (mode:100644 sha1:a1a17e53d29136df431d2a128292d7aefefaea41) renamed from dev/null (tree:c1546808797f6a3c4e6ae82069cee3dc316fbf24) +27 -0
@@ -0,0 +1,27 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#define HEADERSIZE 1024 + +int main(int argc, char **argv) +{ + char buffer[HEADERSIZE]; + ssize_t n; + + n = read(0, buffer, HEADERSIZE); + if (n < HEADERSIZE) { + fprintf(stderr, "read error\n"); + return 3; + } + if (buffer[156] != 'g') + return 1; + if (memcmp(&buffer[512], "52 comment=", 11)) + return 1; + n = write(1, &buffer[523], 41); + if (n < 41) { + fprintf(stderr, "write error\n"); + return 2; + } + return 0; +}
tar-tree.c (mode:100644 sha1:ea7ea91add54532c38dde9e343efe34d56805341) renamed from tar-tree.c (mode:100644 sha1:5cc7cfef6db1269d81589b82255537fb64ba02fa) +27 -16
100 lines not on this page · raw message
Quoted 4 lines · Linus Torvalds
Having just done the git-0.7.tar.gz file with git-tar-tree, I started
wondering if there is some nice way to encode the commit version
that got tarred up into the tar archive itself.
The pax archive format allows for comments; you can store the commit ID in a (archive-)global comment. Archivers are supposed to ignore it and GNU tar at least does so. You can extract the ID with
$ dd bs=1 skip=523 count=41 2>/dev/null < TARFILE
because it would always end up at that position at the start of the archive.
Rene