X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=archive-zip.c;h=d18254c5c00a0a491afa1d8517d08c747dbad395;hb=d53fe8187c38a5a160ef2199a899d9c47ec881b9;hp=74e30f6205f41112dc2bafe9371a790aca55f70c;hpb=c4316674c48708ca62876470c615101ab8fee2e0;p=git.git diff --git a/archive-zip.c b/archive-zip.c index 74e30f620..d18254c5c 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -13,6 +13,7 @@ static int verbose; static int zip_date; static int zip_time; static const struct commit *commit; +static size_t base_len; static unsigned char *zip_dir; static unsigned int zip_dir_size; @@ -151,9 +152,9 @@ static char *construct_path(const char *base, int baselen, return path; } -static int write_zip_entry(const unsigned char *sha1, - const char *base, int baselen, - const char *filename, unsigned mode, int stage) +static int write_zip_entry(const unsigned char *sha1, const char *base, + int baselen, const char *filename, unsigned mode, int stage, + void *context) { struct zip_local_header header; struct zip_dir_header dirent; @@ -175,6 +176,8 @@ static int write_zip_entry(const unsigned char *sha1, crc = crc32(0, NULL, 0); path = construct_path(base, baselen, filename, S_ISDIR(mode), &pathlen); + if (is_archive_path_ignored(path + base_len)) + return 0; if (verbose) fprintf(stderr, "%s\n", path); if (pathlen > 0xffff) { @@ -197,8 +200,8 @@ static int write_zip_entry(const unsigned char *sha1, if (S_ISREG(mode) && zlib_compression_level != 0) method = 8; result = 0; - buffer = sha1_file_to_archive(path, sha1, mode, &type, &size, - commit); + buffer = sha1_file_to_archive(path + base_len, sha1, mode, + &type, &size, commit); if (!buffer) die("cannot read %s", sha1_to_hex(sha1)); crc = crc32(crc, buffer, size); @@ -313,26 +316,26 @@ static void dos_time(time_t *time, int *dos_date, int *dos_time) 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; verbose = args->verbose; commit = args->commit; + base_len = args->baselen; - if (args->base && plen > 0 && args->base[plen - 1] == '/') { + if (args->baselen > 0 && args->base[args->baselen - 1] == '/') { char *base = xstrdup(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); + write_zip_entry(args->tree->object.sha1, "", 0, base, 040777, + 0, NULL); free(base); } - read_tree_recursive(args->tree, args->base, plen, 0, - args->pathspec, write_zip_entry); + read_tree_recursive(args->tree, args->base, args->baselen, 0, + args->pathspec, write_zip_entry, NULL); write_zip_trailer(args->commit_sha1); free(zip_dir);