From: Rene Scharfe <rene.scharfe@xxxxxxxxxxxxxx> Signed-off-by: Rene Scharfe <rene.scharfe@xxxxxxxxxxxxxx> Signed-off-by: Franck Bui-Huu <vagabon.xyz@xxxxxxxxx> --- archive.h | 1 + builtin-archive.c | 1 + builtin-zip-tree.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 0 deletions(-) diff --git a/archive.h b/archive.h index 3690c53..760776d 100644 --- a/archive.h +++ b/archive.h @@ -41,5 +41,6 @@ extern void parse_pathspec_arg(const cha * */ extern int write_tar_archive(struct archiver_args *); +extern int write_zip_archive(struct archiver_args *); #endif /* ARCHIVE_H */ diff --git a/builtin-archive.c b/builtin-archive.c index 214ec5d..fd53e9a 100644 --- a/builtin-archive.c +++ b/builtin-archive.c @@ -17,6 +17,7 @@ static const char archive_usage[] = \ struct archiver archivers[] = { { .name = "tar", .write_archive = write_tar_archive }, + { .name = "zip", .write_archive = write_zip_archive }, }; diff --git a/builtin-zip-tree.c b/builtin-zip-tree.c index a5b834d..788317c 100644 --- a/builtin-zip-tree.c +++ b/builtin-zip-tree.c @@ -8,6 +8,7 @@ #include "blob.h" #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> ]"; @@ -351,3 +352,30 @@ int cmd_zip_tree(int argc, const char ** 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; +} -- 1.4.2 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html