Code

git-merge: add --ff and --no-ff options
[git.git] / archive-tar.c
index 56ff356966c002a0d0a86b1b0d88a3ae60718172..c0d95dab0d965ff0ae961d72d7eae4c021c5c05a 100644 (file)
@@ -17,6 +17,7 @@ static unsigned long offset;
 static time_t archive_time;
 static int tar_umask = 002;
 static int verbose;
+static const struct commit *commit;
 
 /* writes out the whole block, but only if it is full */
 static void write_if_needed(void)
@@ -82,12 +83,13 @@ static void strbuf_append_string(struct strbuf *sb, const char *s)
 {
        int slen = strlen(s);
        int total = sb->len + slen;
-       if (total > sb->alloc) {
-               sb->buf = xrealloc(sb->buf, total);
-               sb->alloc = total;
+       if (total + 1 > sb->alloc) {
+               sb->buf = xrealloc(sb->buf, total + 1);
+               sb->alloc = total + 1;
        }
        memcpy(sb->buf + sb->len, s, slen);
        sb->len = total;
+       sb->buf[total] = '\0';
 }
 
 /*
@@ -166,7 +168,7 @@ static void write_entry(const unsigned char *sha1, struct strbuf *path,
        } else {
                if (verbose)
                        fprintf(stderr, "%.*s\n", path->len, path->buf);
-               if (S_ISDIR(mode) || S_ISDIRLNK(mode)) {
+               if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
                        *header.typeflag = TYPEFLAG_DIR;
                        mode = (mode | 0777) & ~tar_umask;
                } else if (S_ISLNK(mode)) {
@@ -270,20 +272,22 @@ static int write_tar_entry(const unsigned char *sha1,
                path.alloc = PATH_MAX;
                path.len = path.eof = 0;
        }
-       if (path.alloc < baselen + filenamelen) {
+       if (path.alloc < baselen + filenamelen + 1) {
                free(path.buf);
-               path.buf = xmalloc(baselen + filenamelen);
-               path.alloc = baselen + filenamelen;
+               path.buf = xmalloc(baselen + filenamelen + 1);
+               path.alloc = baselen + filenamelen + 1;
        }
        memcpy(path.buf, base, baselen);
        memcpy(path.buf + baselen, filename, filenamelen);
        path.len = baselen + filenamelen;
-       if (S_ISDIR(mode) || S_ISDIRLNK(mode)) {
+       path.buf[path.len] = '\0';
+       if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
                strbuf_append_string(&path, "/");
                buffer = NULL;
                size = 0;
        } else {
-               buffer = read_sha1_file(sha1, &type, &size);
+               buffer = sha1_file_to_archive(path.buf, sha1, mode, &type,
+                                             &size, commit);
                if (!buffer)
                        die("cannot read %s", sha1_to_hex(sha1));
        }
@@ -302,6 +306,7 @@ int write_tar_archive(struct archiver_args *args)
 
        archive_time = args->time;
        verbose = args->verbose;
+       commit = args->commit;
 
        if (args->commit_sha1)
                write_global_extended_header(args->commit_sha1);