]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-snapshot.c
ui-shared: remove unused parameter
[cgit.git] / ui-snapshot.c
index f68e877fb2e5db33d20bf1bf3575fa9b57fa0558..abf83995011075db6668810a8df3da993fc109d5 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, 1, NULL, 0);
+       result = write_archive(argv.argc, nargv, NULL, NULL, 0);
        argv_array_clear(&argv);
        free(nargv);
        return result;
@@ -109,19 +109,19 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
                         const char *hex, const char *prefix,
                         const char *filename)
 {
-       unsigned char sha1[20];
+       struct object_id oid;
 
-       if (get_sha1(hex, sha1)) {
+       if (get_oid(hex, &oid)) {
                cgit_print_error_page(404, "Not found",
                                "Bad object id: %s", hex);
                return 1;
        }
-       if (!lookup_commit_reference(sha1)) {
+       if (!lookup_commit_reference(&oid)) {
                cgit_print_error_page(400, "Bad request",
                                "Not a commit reference: %s", hex);
                return 1;
        }
-       ctx.page.etag = sha1_to_hex(sha1);
+       ctx.page.etag = oid_to_hex(&oid);
        ctx.page.mimetype = xstrdup(format->mimetype);
        ctx.page.filename = xstrdup(filename);
        cgit_print_http_headers();
@@ -139,21 +139,22 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
  * pending a 'v' or a 'V' to the remaining snapshot name ("0.7.2" ->
  * "v0.7.2") gives us something valid.
  */
-static const char *get_ref_from_filename(const char *url, const char *filename,
+static const char *get_ref_from_filename(const struct cgit_repo *repo,
+                                        const char *filename,
                                         const struct cgit_snapshot_format *format)
 {
        const char *reponame;
-       unsigned char sha1[20];
+       struct object_id oid;
        struct strbuf snapshot = STRBUF_INIT;
        int result = 1;
 
        strbuf_addstr(&snapshot, filename);
        strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix));
 
-       if (get_sha1(snapshot.buf, sha1) == 0)
+       if (get_oid(snapshot.buf, &oid) == 0)
                goto out;
 
-       reponame = cgit_repobasename(url);
+       reponame = cgit_snapshot_prefix(repo);
        if (starts_with(snapshot.buf, reponame)) {
                const char *new_start = snapshot.buf;
                new_start += strlen(reponame);
@@ -162,15 +163,15 @@ static const char *get_ref_from_filename(const char *url, const char *filename,
                strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
        }
 
-       if (get_sha1(snapshot.buf, sha1) == 0)
+       if (get_oid(snapshot.buf, &oid) == 0)
                goto out;
 
        strbuf_insert(&snapshot, 0, "v", 1);
-       if (get_sha1(snapshot.buf, sha1) == 0)
+       if (get_oid(snapshot.buf, &oid) == 0)
                goto out;
 
        strbuf_splice(&snapshot, 0, 1, "V", 1);
-       if (get_sha1(snapshot.buf, sha1) == 0)
+       if (get_oid(snapshot.buf, &oid) == 0)
                goto out;
 
        result = 0;
@@ -193,14 +194,14 @@ void cgit_print_snapshot(const char *head, const char *hex,
        }
 
        f = get_format(filename);
-       if (!f) {
+       if (!f || !(ctx.repo->snapshots & f->bit)) {
                cgit_print_error_page(400, "Bad request",
                                "Unsupported snapshot format: %s", filename);
                return;
        }
 
        if (!hex && dwim) {
-               hex = get_ref_from_filename(ctx.repo->url, filename, f);
+               hex = get_ref_from_filename(ctx.repo, filename, f);
                if (hex == NULL) {
                        cgit_print_error_page(404, "Not found", "Not found");
                        return;
@@ -213,7 +214,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
                hex = head;
 
        if (!prefix)
-               prefix = xstrdup(cgit_repobasename(ctx.repo->url));
+               prefix = xstrdup(cgit_snapshot_prefix(ctx.repo));
 
        make_snapshot(f, hex, prefix, filename);
        free(prefix);