Skip to content

Commit

Permalink
git-archive: wire up ZIP format.
Browse files Browse the repository at this point in the history
Again, this is based on Rene Scharfe's earlier patch, but uses
the archiver support introduced by the previous patch.

Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
Acked-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Franck Bui-Huu authored and Junio C Hamano committed Sep 9, 2006
1 parent efd8696 commit ec06bff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ extern void parse_pathspec_arg(const char **pathspec,
* Archive-format specific backends.
*/
extern int write_tar_archive(struct archiver_args *);
extern int write_zip_archive(struct archiver_args *);

#endif /* ARCHIVE_H */
1 change: 1 addition & 0 deletions builtin-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const char archive_usage[] = \

struct archiver archivers[] = {
{ .name = "tar", .write_archive = write_tar_archive },
{ .name = "zip", .write_archive = write_zip_archive },
};

static int run_remote_archiver(struct archiver *ar, int argc,
Expand Down
28 changes: 28 additions & 0 deletions builtin-zip-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "tree.h"
#include "quote.h"
#include "builtin.h"
#include "archive.h"

static const char zip_tree_usage[] =
"git-zip-tree [-0|...|-9] <tree-ish> [ <base> ]";
Expand Down Expand Up @@ -351,3 +352,30 @@ int cmd_zip_tree(int argc, const char **argv, const char *prefix)

return 0;
}

int write_zip_archive(struct archiver_args *args)
{
int plen = strlen(args->base);

dos_time(&args->time, &zip_date, &zip_time);

zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;

if (args->base && plen > 0 && args->base[plen - 1] == '/') {
char *base = strdup(args->base);
int baselen = strlen(base);

while (baselen > 0 && base[baselen - 1] == '/')
base[--baselen] = '\0';
write_zip_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
free(base);
}
read_tree_recursive(args->tree, args->base, plen, 0,
args->pathspec, write_zip_entry);
write_zip_trailer(args->commit_sha1);

free(zip_dir);

return 0;
}

0 comments on commit ec06bff

Please sign in to comment.