]> git.ipfire.org Git - thirdparty/git.git/blobdiff - archive-tar.c
upload-pack: move shallow_nr to upload_pack_data
[thirdparty/git.git] / archive-tar.c
index a58e1a8ebf874afc856b03f2203ee32d79183b31..5ceec3684be910c44216d38e11f240fa4cc22ed3 100644 (file)
@@ -112,7 +112,7 @@ static void write_trailer(void)
  * queues up writes, so that all our write(2) calls write exactly one
  * full block; pads writes to RECORDSIZE
  */
-static int stream_blocked(const struct object_id *oid)
+static int stream_blocked(struct repository *r, const struct object_id *oid)
 {
        struct git_istream *st;
        enum object_type type;
@@ -120,7 +120,7 @@ static int stream_blocked(const struct object_id *oid)
        char buf[BLOCKSIZE];
        ssize_t readlen;
 
-       st = open_istream(oid, &type, &sz, NULL);
+       st = open_istream(r, oid, &type, &sz, NULL);
        if (!st)
                return error(_("cannot stream blob %s"), oid_to_hex(oid));
        for (;;) {
@@ -142,19 +142,25 @@ static int stream_blocked(const struct object_id *oid)
  * string and appends it to a struct strbuf.
  */
 static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
-                                     const char *value, unsigned int valuelen)
+                                    const char *value, size_t valuelen)
 {
-       int len, tmp;
+       size_t orig_len = sb->len;
+       size_t len, tmp;
 
        /* "%u %s=%s\n" */
        len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1;
-       for (tmp = len; tmp > 9; tmp /= 10)
+       for (tmp = 1; len / 10 >= tmp; tmp *= 10)
                len++;
 
        strbuf_grow(sb, len);
-       strbuf_addf(sb, "%u %s=", len, keyword);
+       strbuf_addf(sb, "%"PRIuMAX" %s=", (uintmax_t)len, keyword);
        strbuf_add(sb, value, valuelen);
        strbuf_addch(sb, '\n');
+
+       if (len != sb->len - orig_len)
+               BUG("pax extended header length miscalculated as %"PRIuMAX
+                   ", should be %"PRIuMAX,
+                   (uintmax_t)len, (uintmax_t)(sb->len - orig_len));
 }
 
 /*
@@ -318,7 +324,7 @@ static int write_tar_entry(struct archiver_args *args,
                if (buffer)
                        write_blocked(buffer, size);
                else
-                       err = stream_blocked(oid);
+                       err = stream_blocked(args->repo, oid);
        }
        free(buffer);
        return err;
@@ -326,14 +332,15 @@ static int write_tar_entry(struct archiver_args *args,
 
 static void write_global_extended_header(struct archiver_args *args)
 {
-       const unsigned char *sha1 = args->commit_sha1;
+       const struct object_id *oid = args->commit_oid;
        struct strbuf ext_header = STRBUF_INIT;
        struct ustar_header header;
        unsigned int mode;
 
-       if (sha1)
+       if (oid)
                strbuf_append_ext_header(&ext_header, "comment",
-                                        sha1_to_hex(sha1), 40);
+                                        oid_to_hex(oid),
+                                        the_hash_algo->hexsz);
        if (args->time > USTAR_MAX_MTIME) {
                strbuf_append_ext_header_uint(&ext_header, "mtime",
                                              args->time);
@@ -357,7 +364,7 @@ static struct archiver **tar_filters;
 static int nr_tar_filters;
 static int alloc_tar_filters;
 
-static struct archiver *find_tar_filter(const char *name, int len)
+static struct archiver *find_tar_filter(const char *name, size_t len)
 {
        int i;
        for (i = 0; i < nr_tar_filters; i++) {
@@ -373,7 +380,7 @@ static int tar_filter_config(const char *var, const char *value, void *data)
        struct archiver *ar;
        const char *name;
        const char *type;
-       int namelen;
+       size_t namelen;
 
        if (parse_config_key(var, "tar", &name, &namelen, &type) < 0 || !name)
                return 0;