]> git.ipfire.org Git - thirdparty/git.git/blobdiff - archive-tar.c
switch: fix errors and comments related to -c and -C
[thirdparty/git.git] / archive-tar.c
index 7a535cba24a2a0535b412f1cfb3531ddde155c1e..e16d3f756ddd61d38477e73b71aa01e912ba2b13 100644 (file)
@@ -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));
 }
 
 /*
@@ -202,7 +208,7 @@ static void prepare_header(struct archiver_args *args,
                           unsigned int mode, unsigned long size)
 {
        xsnprintf(header->mode, sizeof(header->mode), "%07o", mode & 07777);
-       xsnprintf(header->size, sizeof(header->size), "%011lo", S_ISREG(mode) ? size : 0);
+       xsnprintf(header->size, sizeof(header->size), "%011"PRIoMAX , S_ISREG(mode) ? (uintmax_t)size : (uintmax_t)0);
        xsnprintf(header->mtime, sizeof(header->mtime), "%011lo", (unsigned long) args->time);
 
        xsnprintf(header->uid, sizeof(header->uid), "%07o", 0);
@@ -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);