]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-snapshot.c
tests: allow to skip git version tests
[cgit.git] / ui-snapshot.c
index c7611e88947edfed93b497bd654703e3c8987efe..9461d51a5979cc4c4102c08b9c584914d74afd63 100644 (file)
@@ -37,7 +37,7 @@ static int write_archive_type(const char *format, const char *hex, const char *p
        /* argv_array guarantees a trailing NULL entry. */
        memcpy(nargv, argv.argv, sizeof(char *) * (argv.argc + 1));
 
-       result = write_archive(argv.argc, nargv, NULL, NULL, 0);
+       result = write_archive(argv.argc, nargv, NULL, the_repository, NULL, 0);
        argv_array_clear(&argv);
        free(nargv);
        return result;
@@ -86,11 +86,12 @@ static int write_tar_xz_archive(const char *hex, const char *prefix)
 }
 
 const struct cgit_snapshot_format cgit_snapshot_formats[] = {
-       { ".zip", "application/x-zip", write_zip_archive, 0x01 },
-       { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x02 },
-       { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 },
-       { ".tar", "application/x-tar", write_tar_archive, 0x08 },
-       { ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 },
+       /* .tar must remain the 0 index */
+       { ".tar",       "application/x-tar",    write_tar_archive       },
+       { ".tar.gz",    "application/x-gzip",   write_tar_gzip_archive  },
+       { ".tar.bz2",   "application/x-bzip2",  write_tar_bzip2_archive },
+       { ".tar.xz",    "application/x-xz",     write_tar_xz_archive    },
+       { ".zip",       "application/x-zip",    write_zip_archive       },
        { NULL }
 };
 
@@ -130,6 +131,11 @@ static const struct cgit_snapshot_format *get_format(const char *filename)
        return NULL;
 }
 
+const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f)
+{
+       return BIT(f - &cgit_snapshot_formats[0]);
+}
+
 static int make_snapshot(const struct cgit_snapshot_format *format,
                         const char *hex, const char *prefix,
                         const char *filename)
@@ -141,7 +147,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
                                "Bad object id: %s", hex);
                return 1;
        }
-       if (!lookup_commit_reference(&oid)) {
+       if (!lookup_commit_reference(the_repository, &oid)) {
                cgit_print_error_page(400, "Bad request",
                                "Not a commit reference: %s", hex);
                return 1;
@@ -150,6 +156,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
        ctx.page.mimetype = xstrdup(format->mimetype);
        ctx.page.filename = xstrdup(filename);
        cgit_print_http_headers();
+       init_archivers();
        format->write_func(hex, prefix);
        return 0;
 }
@@ -169,7 +176,7 @@ static int write_sig(const struct cgit_snapshot_format *format,
                return 0;
        }
 
-       buf = read_sha1_file(note->hash, &type, &size);
+       buf = read_object_file(note, &type, &size);
        if (!buf) {
                cgit_print_error_page(404, "Not found", "Not found");
                return 0;
@@ -263,7 +270,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
        }
 
        f = get_format(filename);
-       if (!f || !(ctx.repo->snapshots & f->bit)) {
+       if (!f || (!sig_filename && !(ctx.repo->snapshots & cgit_snapshot_format_bit(f)))) {
                cgit_print_error_page(400, "Bad request",
                                "Unsupported snapshot format: %s", filename);
                return;