git-archive: wire up ZIP format.
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>
Franck Bui-Huu committed
Sep 7, 2006 at 15:12 UTC
ec06bff5e6f76b46c22a3b2c97452568f088fa3c
3 files changed
+30
archive.h
+1
@@ -41,5 +41,6 @@ extern void parse_pathspec_arg(const char **pathspec,
41
* Archive-format specific backends.
42
*/
43
extern int write_tar_archive(struct archiver_args *);
44
+extern int write_zip_archive(struct archiver_args *);
45
46
#endif /* ARCHIVE_H */
builtin-archive.c
+1
@@ -16,6 +16,7 @@ static const char archive_usage[] = \
16
17
struct archiver archivers[] = {
18
{ .name = "tar", .write_archive = write_tar_archive },
19
+ { .name = "zip", .write_archive = write_zip_archive },
20
};
21
22
static int run_remote_archiver(struct archiver *ar, int argc,
builtin-zip-tree.c
+28
@@ -8,6 +8,7 @@
8
#include "tree.h"
9
#include "quote.h"
10
#include "builtin.h"
11
+#include "archive.h"
12
13
static const char zip_tree_usage[] =
14
"git-zip-tree [-0|...|-9] <tree-ish> [ <base> ]";
@@ -351,3 +352,30 @@ int cmd_zip_tree(int argc, const char **argv, const char *prefix)
352
353
return 0;
354
}
355
+
356
+int write_zip_archive(struct archiver_args *args)
357
+{
358
+ int plen = strlen(args->base);
359
+
360
+ dos_time(&args->time, &zip_date, &zip_time);
361
+
362
+ zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
363
+ zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
364
+
365
+ if (args->base && plen > 0 && args->base[plen - 1] == '/') {
366
+ char *base = strdup(args->base);
367
+ int baselen = strlen(base);
368
+
369
+ while (baselen > 0 && base[baselen - 1] == '/')
370
+ base[--baselen] = '\0';
371
+ write_zip_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
372
+ free(base);
373
+ }
374
+ read_tree_recursive(args->tree, args->base, plen, 0,
375
+ args->pathspec, write_zip_entry);
376
+ write_zip_trailer(args->commit_sha1);
377
+
378
+ free(zip_dir);
379
+
380
+ return 0;
381
+}