sequencer (rebase -i): show only failed `git commit`'s output
[gitweb.git] / archive-tar.c
index 57a15406d9724e70c6dfaaf6d1c0dba64f2156ad..380e3aedd23c02da9ba70d9c5a258550a9637c71 100644 (file)
@@ -22,8 +22,16 @@ static int write_tar_filter_archive(const struct archiver *ar,
  * This is the max value that a ustar size header can specify, as it is fixed
  * at 11 octal digits. POSIX specifies that we switch to extended headers at
  * this size.
+ *
+ * Likewise for the mtime (which happens to use a buffer of the same size).
  */
+#if ULONG_MAX == 0xFFFFFFFF
+#define USTAR_MAX_SIZE ULONG_MAX
+#define USTAR_MAX_MTIME ULONG_MAX
+#else
 #define USTAR_MAX_SIZE 077777777777UL
+#define USTAR_MAX_MTIME 077777777777UL
+#endif
 
 /* writes out the whole block, but only if it is full */
 static void write_if_needed(void)
@@ -205,9 +213,9 @@ static void prepare_header(struct archiver_args *args,
        xsnprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
 }
 
-static int write_extended_header(struct archiver_args *args,
-                                const unsigned char *sha1,
-                                const void *buffer, unsigned long size)
+static void write_extended_header(struct archiver_args *args,
+                                 const unsigned char *sha1,
+                                 const void *buffer, unsigned long size)
 {
        struct ustar_header header;
        unsigned int mode;
@@ -218,7 +226,6 @@ static int write_extended_header(struct archiver_args *args,
        prepare_header(args, &header, mode, size);
        write_blocked(&header, sizeof(header));
        write_blocked(buffer, size);
-       return 0;
 }
 
 static int write_tar_entry(struct archiver_args *args,
@@ -297,12 +304,8 @@ static int write_tar_entry(struct archiver_args *args,
        prepare_header(args, &header, mode, size_in_header);
 
        if (ext_header.len > 0) {
-               err = write_extended_header(args, sha1, ext_header.buf,
-                                           ext_header.len);
-               if (err) {
-                       free(buffer);
-                       return err;
-               }
+               write_extended_header(args, sha1, ext_header.buf,
+                                     ext_header.len);
        }
        strbuf_release(&ext_header);
        write_blocked(&header, sizeof(header));
@@ -316,15 +319,25 @@ static int write_tar_entry(struct archiver_args *args,
        return err;
 }
 
-static int write_global_extended_header(struct archiver_args *args)
+static void write_global_extended_header(struct archiver_args *args)
 {
        const unsigned char *sha1 = args->commit_sha1;
        struct strbuf ext_header = STRBUF_INIT;
        struct ustar_header header;
        unsigned int mode;
-       int err = 0;
 
-       strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
+       if (sha1)
+               strbuf_append_ext_header(&ext_header, "comment",
+                                        sha1_to_hex(sha1), 40);
+       if (args->time > USTAR_MAX_MTIME) {
+               strbuf_append_ext_header_uint(&ext_header, "mtime",
+                                             args->time);
+               args->time = USTAR_MAX_MTIME;
+       }
+
+       if (!ext_header.len)
+               return;
+
        memset(&header, 0, sizeof(header));
        *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
        mode = 0100666;
@@ -333,7 +346,6 @@ static int write_global_extended_header(struct archiver_args *args)
        write_blocked(&header, sizeof(header));
        write_blocked(ext_header.buf, ext_header.len);
        strbuf_release(&ext_header);
-       return err;
 }
 
 static struct archiver **tar_filters;
@@ -409,10 +421,8 @@ static int write_tar_archive(const struct archiver *ar,
 {
        int err = 0;
 
-       if (args->commit_sha1)
-               err = write_global_extended_header(args);
-       if (!err)
-               err = write_archive_entries(args, write_tar_entry);
+       write_global_extended_header(args);
+       err = write_archive_entries(args, write_tar_entry);
        if (!err)
                write_trailer();
        return err;