From 86a6d358f7a6c2432fde86b9e3c5011a656f20e4 Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Wed, 9 Aug 2017 19:02:56 -0500 Subject: git: update to v2.14 Numerous changes were made to git functions to use an object_id structure rather than sending sha1 hashes as raw unsigned character arrays. The functions that affect cgit are: parse_object, lookup_commit_reference, lookup_tag, lookup_tree, parse_tree_indirect, diff_root_tree_sha1, diff_tree_sha1, and format_display_notes. Commit b2141fc (config: don't include config.h by default) made it necessary to that config.h be explicitly included when needed. Commit 07a3d41 (grep: remove regflags from the public grep_opt API) removed one way of specifying the ignore-case grep option. Signed-off-by: Jeff Smith --- ui-tree.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ui-tree.c') diff --git a/ui-tree.c b/ui-tree.c index b310242..ca24a03 100644 --- 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; } @@ -380,7 +380,7 @@ void cgit_print_tree(const char *rev, char *path) "Invalid revision name: %s", rev); return; } - commit = lookup_commit_reference(oid.hash); + 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; } -- cgit v1.2.3-24-g4f1b From 9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Sun, 1 Oct 2017 23:39:06 -0500 Subject: ui-tree: move set_title_from_path to ui-shared The ui-blame code will also need to call set_title_from_path, so go ahead and move it to ui-shared. Signed-off-by: Jeff Smith Reviewed-by: John Keeping --- ui-tree.c | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) (limited to 'ui-tree.c') diff --git a/ui-tree.c b/ui-tree.c index ca24a03..3925809 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -84,37 +84,6 @@ static void print_binary_buffer(char *buf, unsigned long size) html("\n"); } -static void set_title_from_path(const char *path) -{ - size_t path_len, path_index, path_last_end; - char *new_title; - - if (!path) - return; - - path_len = strlen(path); - new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); - new_title[0] = '\0'; - - for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { - if (path[path_index] == '/') { - if (path_index == path_len - 1) { - path_last_end = path_index - 1; - continue; - } - strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); - strcat(new_title, "\\"); - path_last_end = path_index; - } - } - if (path_last_end) - strncat(new_title, path, path_last_end); - - strcat(new_title, " - "); - strcat(new_title, ctx.page.title); - ctx.page.title = new_title; -} - static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) { enum object_type type; @@ -135,7 +104,7 @@ static void print_object(const unsigned char *sha1, char *path, const char *base return; } - set_title_from_path(path); + cgit_set_title_from_path(path); cgit_print_layout_start(); htmlf("blob: %s (", sha1_to_hex(sha1)); @@ -335,7 +304,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (S_ISDIR(mode)) { walk_tree_ctx->state = 1; - set_title_from_path(buffer.buf); + cgit_set_title_from_path(buffer.buf); strbuf_release(&buffer); ls_head(); return READ_TREE_RECURSIVE; -- cgit v1.2.3-24-g4f1b From 1649afdc9b2febe9ab7e1abe1956c5dcaff93aa1 Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Sun, 1 Oct 2017 23:39:09 -0500 Subject: ui-tree: link to blame UI if enabled Create links to the blame page. Signed-off-by: Jeff Smith Reviewed-by: John Keeping --- ui-tree.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ui-tree.c') diff --git a/ui-tree.c b/ui-tree.c index 3925809..67fd1bc 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -1,6 +1,6 @@ /* ui-tree.c: functions for tree output * - * Copyright (C) 2006-2014 cgit Development Team + * Copyright (C) 2006-2017 cgit Development Team * * Licensed under GNU General Public License v2 * (see COPYING for full license text) @@ -110,6 +110,11 @@ static void print_object(const unsigned char *sha1, char *path, const char *base htmlf("blob: %s (", sha1_to_hex(sha1)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); + if (ctx.cfg.enable_blame) { + html(") ("); + cgit_blame_link("blame", NULL, NULL, ctx.qry.head, + rev, path); + } html(")\n"); if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { @@ -244,6 +249,9 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, if (!S_ISGITLINK(mode)) cgit_plain_link("plain", NULL, "button", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); + if (!S_ISDIR(mode) && ctx.cfg.enable_blame) + cgit_blame_link("blame", NULL, "button", ctx.qry.head, + walk_tree_ctx->curr_rev, fullpath.buf); html("\n"); free(name); strbuf_release(&fullpath); -- cgit v1.2.3-24-g4f1b