]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-tree.c
html.c: add various strbuf and varadic helpers
[ps-cgit] / ui-tree.c
index 561f9e7c7a0a80a6a222e0aa12fe2e6aed59ad3e..d7135532baf8c6f69da6fe2b5c01599f75b351ee 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -8,6 +8,7 @@
 
 #include <ctype.h>
 #include "cgit.h"
+#include "ui-tree.h"
 #include "html.h"
 #include "ui-shared.h"
 
@@ -271,7 +272,6 @@ void cgit_print_tree(const char *rev, char *path)
        if (!rev)
                rev = ctx.qry.head;
 
-       walk_tree_ctx.curr_rev = xstrdup(rev);
        if (get_sha1(rev, sha1)) {
                cgit_print_error(fmt("Invalid revision name: %s", rev));
                return;
@@ -282,12 +282,17 @@ void cgit_print_tree(const char *rev, char *path)
                return;
        }
 
+       walk_tree_ctx.curr_rev = xstrdup(rev);
+
        if (path == NULL) {
                ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx);
-               return;
+               goto cleanup;
        }
 
        read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
        if (walk_tree_ctx.state == 1)
                ls_tail();
+
+cleanup:
+       free(walk_tree_ctx.curr_rev);
 }