neocgit

a more 'modern' version of cgit
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/neocgit

commit bc9e61bbeadee6b71fdfd9b295093e2573ee1de1
parent fd92830ce99e8556df78135d575c68646eaf7951
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 10 Jul 2018 13:41:21 +0200

FIX: Tree OID links now fully working

Signed-off-by: Ne02ptzero <louis@ne02ptzero.me>

Diffstat:
Mui-log.c | 6+++++-
Mui-shared.c | 37+++++++++++++++++++++++++++----------
Mui-tree.c | 19+++++++++++++------
3 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/ui-log.c b/ui-log.c @@ -322,7 +322,11 @@ struct commit *cgit_get_last_commit_from_path(const char *path) int must_free_tip = 0; const char *tip; - tip = ctx.qry.head; + if (ctx.qry.sha1) + tip = ctx.qry.sha1; + else + tip = ctx.qry.head; + argv_array_push(&rev_argv, "log_rev_setup"); tip = disambiguate_ref(tip, &must_free_tip); argv_array_push(&rev_argv, tip); diff --git a/ui-shared.c b/ui-shared.c @@ -898,7 +898,7 @@ static int print_branch_option(const char *refname, const struct object_id *oid, int flags, void *cb_data) { char *name = (char *)refname; - html_option(name, name, ctx.qry.head); + html_option(name, name, ctx.qry.sha1 == NULL ? ctx.qry.head : ""); return 0; } @@ -1085,16 +1085,22 @@ void cgit_print_pageheader(void) _html("<div class='summary-branches'>") { _html("<ul>") { _html("<li>") { - _html("<form method='get'>") { - cgit_add_hidden_formfields(0, 1, ctx.qry.page); - html("<select name='h' onchange='this.form.submit();'>\n"); - for_each_branch_ref(print_branch_option, ctx.qry.head); - html("</select> "); - } html("</form>"); + _html("<form method='get'>") { + cgit_add_hidden_formfields(0, 1, ctx.qry.page); + html("<select name='h' onchange='this.form.submit();'>\n"); + for_each_branch_ref(print_branch_option, ctx.qry.head); + if (ctx.qry.sha1 != NULL) + htmlf("<option value='%s' selected='selected'>%s</option>", ctx.qry.sha1, ctx.qry.sha1); + html("</select> "); + } html("</form>"); } _html("</li>"); _html("<li class='repo-name'>") { - htmlf("<a href='/%s?h=%s'>%s</a>", ctx.repo->name, ctx.qry.head, ctx.repo->name); + htmlf("<a href='/%s?%s=%s'>%s</a>", ctx.repo->name, + ctx.qry.sha1 != NULL ? "id" : "h", + ctx.qry.sha1 != NULL ? ctx.qry.sha1 : ctx.qry.head, + ctx.repo->name); + if (ctx.qry.path) { int z = 0; @@ -1105,12 +1111,20 @@ void cgit_print_pageheader(void) continue; ctx.qry.path[i] = 0; - htmlf("/<a href='/%s/tree/%s?h=%s'>%s</a>", ctx.repo->name, ctx.qry.path, ctx.qry.head, ctx.qry.path + z); + htmlf("/<a href='/%s/tree/%s?%s=%s'>%s</a>", + ctx.repo->name, ctx.qry.path, + ctx.qry.sha1 != NULL ? "id" : "h", + ctx.qry.sha1 != NULL ? ctx.qry.sha1 : ctx.qry.head, + ctx.qry.path + z); ctx.qry.path[i] = '/'; z = ++i; } - htmlf("/<a href='/%s/tree/%s?h=%s'>%s</a>", ctx.repo->name, ctx.qry.path, ctx.qry.head, ctx.qry.path + z); + htmlf("/<a href='/%s/tree/%s?%s=%s'>%s</a>", + ctx.repo->name, ctx.qry.path, + ctx.qry.sha1 != NULL ? "id" : "h", + ctx.qry.sha1 != NULL ? ctx.qry.sha1 : ctx.qry.head, + ctx.qry.path + z); } } _html("</li>"); @@ -1131,11 +1145,14 @@ void cgit_print_pageheader(void) if (ctx.qry.path) commit = cgit_get_last_commit_from_path(ctx.qry.path); + else if (ctx.qry.sha1) + commit = cgit_get_last_commit_from_path("."); else { get_oid(ctx.qry.head, &oid); commit = lookup_commit_reference(&oid); } + clear_object_flags(ALL_REV_FLAGS); info = cgit_parse_commit(commit); _html("<ul>") { diff --git a/ui-tree.c b/ui-tree.c @@ -331,7 +331,10 @@ static void print_tree_item(struct tree_link *ptr, struct walk_tree_context *tre if (commit) info = cgit_parse_commit(commit); - _htmlf("<tr onclick=\"location.href='/%s/tree/%s?h=%s'\" class='tree-entry'>", ctx.repo->name, fullpath.buf, ctx.qry.head) { + _htmlf("<tr onclick=\"location.href='/%s/tree/%s?%s=%s'\" class='tree-entry'>", + ctx.repo->name, fullpath.buf, ctx.qry.sha1 != NULL ? "id" : "h", + ctx.qry.sha1 != NULL ? ctx.qry.sha1 : ctx.qry.head) { + _html("<td class='table-left file-path'>") { print_file_icon(name, ptr->mode); htmlf("<span>%s</span>", name); @@ -451,9 +454,11 @@ static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_co if (ctx.qry.path) { - htmlf("<tr onclick=\"location.href='/%s/tree/%s/../?h=%s'\" class='tree-entry'>" + htmlf("<tr onclick=\"location.href='/%s/tree/%s/../?%s=%s'\" class='tree-entry'>" "<td><span>..</span></td><td></td><td></td></tr>", - ctx.repo->name, ctx.qry.path, ctx.qry.head); + ctx.repo->name, ctx.qry.path, + ctx.qry.sha1 != NULL ? "id" : "h", + ctx.qry.sha1 != NULL ? ctx.qry.sha1 : ctx.qry.head); } walk_tree_ctx->head = NULL; @@ -560,9 +565,11 @@ void cgit_print_tree(const char *rev, char *path, bool layout) if (ctx.qry.path) { - htmlf("<tr onclick=\"location.href='/%s/tree/%s/../?h=%s'\" class='tree-entry'>" - "<td><span>..</span></td><td></td><td></td></tr>", - ctx.repo->name, ctx.qry.path, ctx.qry.head); + htmlf("<tr onclick=\"location.href='/%s/tree/%s/../?%s=%s'\" class='tree-entry'>" + "<td><span>..</span></td><td></td><td></td></tr>", + ctx.repo->name, ctx.qry.path, + ctx.qry.sha1 != NULL ? "id" : "h", + ctx.qry.sha1 != NULL ? ctx.qry.sha1 : ctx.qry.head); } for (struct tree_link *tmp = walk_tree_ctx.head; tmp; tmp = tmp->next)