Code

branch --merged/--no-merged: allow specifying arbitrary commit
[git.git] / archive-zip.c
index 444e1623db66fe4f5d8983e1e9e2cf4083b005b4..5742762ac30c92e796255b74d2ed1ea087f3fba0 100644 (file)
@@ -12,6 +12,8 @@
 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;
@@ -174,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) {
@@ -191,11 +195,13 @@ static int write_zip_entry(const unsigned char *sha1,
                compressed_size = 0;
        } else if (S_ISREG(mode) || S_ISLNK(mode)) {
                method = 0;
-               attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) : 0;
+               attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
+                       (mode & 0111) ? ((mode) << 16) : 0;
                if (S_ISREG(mode) && zlib_compression_level != 0)
                        method = 8;
                result = 0;
-               buffer = convert_sha1_file(path, sha1, mode, &type, &size);
+               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);
@@ -229,7 +235,8 @@ static int write_zip_entry(const unsigned char *sha1,
        }
 
        copy_le32(dirent.magic, 0x02014b50);
-       copy_le16(dirent.creator_version, S_ISLNK(mode) ? 0x0317 : 0);
+       copy_le16(dirent.creator_version,
+               S_ISLNK(mode) || (S_ISREG(mode) && (mode & 0111)) ? 0x0317 : 0);
        copy_le16(dirent.version, 10);
        copy_le16(dirent.flags, 0);
        copy_le16(dirent.compression_method, method);
@@ -316,6 +323,8 @@ int write_zip_archive(struct archiver_args *args)
        zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
        zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
        verbose = args->verbose;
+       commit = args->commit;
+       base_len = args->base ? strlen(args->base) : 0;
 
        if (args->base && plen > 0 && args->base[plen - 1] == '/') {
                char *base = xstrdup(args->base);