]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-tree.c
ui-shared: don't print path crumbs without a repo
[ps-cgit] / ui-tree.c
index b98a7f0dd543977a84862de959057b8bbee3de1d..ca24a035c57cbe4a27acae26bab4191c781f565c 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -157,7 +157,7 @@ static void print_object(const unsigned char *sha1, char *path, const char *base
 
 struct single_tree_ctx {
        struct strbuf *path;
-       unsigned char sha1[GIT_SHA1_RAWSZ];
+       struct object_id oid;
        char *name;
        size_t count;
 };
@@ -177,7 +177,7 @@ static int single_tree_cb(const unsigned char *sha1, struct strbuf *base,
        }
 
        ctx->name = xstrdup(pathname);
-       hashcpy(ctx->sha1, sha1);
+       hashcpy(ctx->oid.hash, sha1);
        strbuf_addf(ctx->path, "/%s", pathname);
        return 0;
 }
@@ -195,13 +195,13 @@ static void write_tree_link(const unsigned char *sha1, char *name,
                .nr = 0
        };
 
-       hashcpy(tree_ctx.sha1, sha1);
+       hashcpy(tree_ctx.oid.hash, sha1);
 
        while (tree_ctx.count == 1) {
                cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev,
                               fullpath->buf);
 
-               tree = lookup_tree(tree_ctx.sha1);
+               tree = lookup_tree(&tree_ctx.oid);
                if (!tree)
                        return;
 
@@ -300,17 +300,17 @@ static void ls_tail(void)
        cgit_print_layout_end();
 }
 
-static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_context *walk_tree_ctx)
+static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_context *walk_tree_ctx)
 {
        struct tree *tree;
        struct pathspec paths = {
                .nr = 0
        };
 
-       tree = parse_tree_indirect(sha1);
+       tree = parse_tree_indirect(oid);
        if (!tree) {
                cgit_print_error_page(404, "Not found",
-                       "Not a tree object: %s", sha1_to_hex(sha1));
+                       "Not a tree object: %s", sha1_to_hex(oid->hash));
                return;
        }
 
@@ -357,7 +357,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
  */
 void cgit_print_tree(const char *rev, char *path)
 {
-       unsigned char sha1[20];
+       struct object_id oid;
        struct commit *commit;
        struct pathspec_item path_items = {
                .match = path,
@@ -375,12 +375,12 @@ void cgit_print_tree(const char *rev, char *path)
        if (!rev)
                rev = ctx.qry.head;
 
-       if (get_sha1(rev, sha1)) {
+       if (get_oid(rev, &oid)) {
                cgit_print_error_page(404, "Not found",
                        "Invalid revision name: %s", rev);
                return;
        }
-       commit = lookup_commit_reference(sha1);
+       commit = lookup_commit_reference(&oid);
        if (!commit || parse_commit(commit)) {
                cgit_print_error_page(404, "Not found",
                        "Invalid commit reference: %s", rev);
@@ -390,7 +390,7 @@ void cgit_print_tree(const char *rev, char *path)
        walk_tree_ctx.curr_rev = xstrdup(rev);
 
        if (path == NULL) {
-               ls_tree(commit->tree->object.oid.hash, NULL, &walk_tree_ctx);
+               ls_tree(&commit->tree->object.oid, NULL, &walk_tree_ctx);
                goto cleanup;
        }