]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-snapshot.c
git: update to v2.46.0
[ps-cgit] / ui-snapshot.c
index 9461d51a5979cc4c4102c08b9c584914d74afd63..3e38cd5aa751aa66a48778547ce67daa5454cc0a 100644 (file)
@@ -6,6 +6,8 @@
  *   (see COPYING for full license text)
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "cgit.h"
 #include "ui-snapshot.h"
 #include "html.h"
 
 static int write_archive_type(const char *format, const char *hex, const char *prefix)
 {
-       struct argv_array argv = ARGV_ARRAY_INIT;
+       struct strvec argv = STRVEC_INIT;
        const char **nargv;
        int result;
-       argv_array_push(&argv, "snapshot");
-       argv_array_push(&argv, format);
+       strvec_push(&argv, "snapshot");
+       strvec_push(&argv, format);
        if (prefix) {
                struct strbuf buf = STRBUF_INIT;
                strbuf_addstr(&buf, prefix);
                strbuf_addch(&buf, '/');
-               argv_array_push(&argv, "--prefix");
-               argv_array_push(&argv, buf.buf);
+               strvec_push(&argv, "--prefix");
+               strvec_push(&argv, buf.buf);
                strbuf_release(&buf);
        }
-       argv_array_push(&argv, hex);
+       strvec_push(&argv, hex);
        /*
         * Now we need to copy the pointers to arguments into a new
         * structure because write_archive will rearrange its arguments
         * which may result in duplicated/missing entries causing leaks
-        * or double-frees in argv_array_clear.
+        * or double-frees in strvec_clear.
         */
-       nargv = xmalloc(sizeof(char *) * (argv.argc + 1));
-       /* argv_array guarantees a trailing NULL entry. */
-       memcpy(nargv, argv.argv, sizeof(char *) * (argv.argc + 1));
+       nargv = xmalloc(sizeof(char *) * (argv.nr + 1));
+       /* strvec guarantees a trailing NULL entry. */
+       memcpy(nargv, argv.v, sizeof(char *) * (argv.nr + 1));
 
-       result = write_archive(argv.argc, nargv, NULL, the_repository, NULL, 0);
-       argv_array_clear(&argv);
+       result = write_archive(argv.nr, nargv, NULL, the_repository, NULL, 0);
+       strvec_clear(&argv);
        free(nargv);
        return result;
 }
@@ -79,18 +81,32 @@ static int write_tar_bzip2_archive(const char *hex, const char *prefix)
        return write_compressed_tar_archive(hex, prefix, argv);
 }
 
+static int write_tar_lzip_archive(const char *hex, const char *prefix)
+{
+       char *argv[] = { "lzip", NULL };
+       return write_compressed_tar_archive(hex, prefix, argv);
+}
+
 static int write_tar_xz_archive(const char *hex, const char *prefix)
 {
        char *argv[] = { "xz", NULL };
        return write_compressed_tar_archive(hex, prefix, argv);
 }
 
+static int write_tar_zstd_archive(const char *hex, const char *prefix)
+{
+       char *argv[] = { "zstd", "-T0", NULL };
+       return write_compressed_tar_archive(hex, prefix, argv);
+}
+
 const struct cgit_snapshot_format cgit_snapshot_formats[] = {
        /* .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.lz",    "application/x-lzip",   write_tar_lzip_archive  },
        { ".tar.xz",    "application/x-xz",     write_tar_xz_archive    },
+       { ".tar.zst",   "application/x-zstd",   write_tar_zstd_archive  },
        { ".zip",       "application/x-zip",    write_zip_archive       },
        { NULL }
 };
@@ -103,7 +119,7 @@ const struct object_id *cgit_snapshot_get_sig(const char *ref,
        struct notes_tree *tree;
        struct object_id oid;
 
-       if (get_oid(ref, &oid))
+       if (repo_get_oid(the_repository, ref, &oid))
                return NULL;
 
        tree = &snapshot_sig_notes[f - &cgit_snapshot_formats[0]];
@@ -142,7 +158,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
 {
        struct object_id oid;
 
-       if (get_oid(hex, &oid)) {
+       if (repo_get_oid(the_repository, hex, &oid)) {
                cgit_print_error_page(404, "Not found",
                                "Bad object id: %s", hex);
                return 1;
@@ -176,7 +192,7 @@ static int write_sig(const struct cgit_snapshot_format *format,
                return 0;
        }
 
-       buf = read_object_file(note, &type, &size);
+       buf = repo_read_object_file(the_repository, note, &type, &size);
        if (!buf) {
                cgit_print_error_page(404, "Not found", "Not found");
                return 0;
@@ -216,7 +232,7 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo,
        strbuf_addstr(&snapshot, filename);
        strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix));
 
-       if (get_oid(snapshot.buf, &oid) == 0)
+       if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0)
                goto out;
 
        reponame = cgit_snapshot_prefix(repo);
@@ -228,15 +244,15 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo,
                strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
        }
 
-       if (get_oid(snapshot.buf, &oid) == 0)
+       if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0)
                goto out;
 
        strbuf_insert(&snapshot, 0, "v", 1);
-       if (get_oid(snapshot.buf, &oid) == 0)
+       if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0)
                goto out;
 
        strbuf_splice(&snapshot, 0, 1, "V", 1);
-       if (get_oid(snapshot.buf, &oid) == 0)
+       if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0)
                goto out;
 
        result = 0;