Merge branch 'maint-1.5.5' into maint-1.5.6
[gitweb.git] / archive-tar.c
index c84d7c0652783bfd039fe66e4ce2ca59f6a7df8f..d7598f907d9f7fb40c24c8cef815f8fc33a8b19b 100644 (file)
@@ -3,7 +3,6 @@
  */
 #include "cache.h"
 #include "commit.h"
-#include "strbuf.h"
 #include "tar.h"
 #include "builtin.h"
 #include "archive.h"
@@ -17,6 +16,8 @@ static unsigned long offset;
 static time_t archive_time;
 static int tar_umask = 002;
 static int verbose;
+static const struct commit *commit;
+static size_t base_len;
 
 /* writes out the whole block, but only if it is full */
 static void write_if_needed(void)
@@ -131,7 +132,7 @@ static void write_entry(const unsigned char *sha1, struct strbuf *path,
        struct strbuf ext_header;
 
        memset(&header, 0, sizeof(header));
-       strbuf_init(&ext_header);
+       strbuf_init(&ext_header, 0);
 
        if (!sha1) {
                *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
@@ -213,16 +214,16 @@ static void write_global_extended_header(const unsigned char *sha1)
 {
        struct strbuf ext_header;
 
-       strbuf_init(&ext_header);
+       strbuf_init(&ext_header, 0);
        strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
        write_entry(NULL, NULL, 0, ext_header.buf, ext_header.len);
        strbuf_release(&ext_header);
 }
 
-static int git_tar_config(const char *var, const char *value)
+static int git_tar_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "tar.umask")) {
-               if (!strcmp(value, "user")) {
+               if (value && !strcmp(value, "user")) {
                        tar_umask = umask(0);
                        umask(tar_umask);
                } else {
@@ -230,7 +231,7 @@ static int git_tar_config(const char *var, const char *value)
                }
                return 0;
        }
-       return git_default_config(var, value);
+       return git_default_config(var, value, cb);
 }
 
 static int write_tar_entry(const unsigned char *sha1,
@@ -238,21 +239,21 @@ static int write_tar_entry(const unsigned char *sha1,
                            const char *filename, unsigned mode, int stage)
 {
        static struct strbuf path = STRBUF_INIT;
-       int filenamelen = strlen(filename);
        void *buffer;
        enum object_type type;
        unsigned long size;
 
-       strbuf_grow(&path, MAX(PATH_MAX, baselen + filenamelen + 1));
        strbuf_reset(&path);
+       strbuf_grow(&path, PATH_MAX);
        strbuf_add(&path, base, baselen);
-       strbuf_add(&path, filename, filenamelen);
+       strbuf_addstr(&path, filename);
        if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
                strbuf_addch(&path, '/');
                buffer = NULL;
                size = 0;
        } else {
-               buffer = convert_sha1_file(path.buf, sha1, mode, &type, &size);
+               buffer = sha1_file_to_archive(path.buf + base_len, sha1, mode,
+                               &type, &size, commit);
                if (!buffer)
                        die("cannot read %s", sha1_to_hex(sha1));
        }
@@ -267,10 +268,12 @@ int write_tar_archive(struct archiver_args *args)
 {
        int plen = args->base ? strlen(args->base) : 0;
 
-       git_config(git_tar_config);
+       git_config(git_tar_config, NULL);
 
        archive_time = args->time;
        verbose = args->verbose;
+       commit = args->commit;
+       base_len = args->base ? strlen(args->base) : 0;
 
        if (args->commit_sha1)
                write_global_extended_header(args->commit_sha1);