-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-log.c | 7 | ||||
-rw-r--r-- | ui-shared.c | 16 | ||||
-rw-r--r-- | ui-summary.c | 18 | ||||
-rw-r--r-- | ui-tree.c | 1 |
7 files changed, 31 insertions, 18 deletions
@@ -91,25 +91,25 @@ static void cgit_print_repo_page(struct cacheitem *item) cgit_print_pageheader(cgit_query_page, show_search); switch(cgit_cmd) { case CMD_LOG: cgit_print_log(cgit_query_head, cgit_query_ofs, cgit_max_commit_count, cgit_query_search, cgit_query_path, 1); break; case CMD_TREE: cgit_print_tree(cgit_query_sha1, cgit_query_path); break; case CMD_COMMIT: - cgit_print_commit(cgit_query_head); + cgit_print_commit(cgit_query_sha1); break; case CMD_DIFF: cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, cgit_query_path); break; default: cgit_print_error("Invalid request"); } cgit_print_docend(); } static void cgit_fill_cache(struct cacheitem *item, int use_cache) @@ -196,24 +196,26 @@ extern int cache_unlock(struct cacheitem *item); extern int cache_cancel_lock(struct cacheitem *item); extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); extern void cgit_log_link(char *name, char *title, char *class, char *head, char *rev, char *path); +extern void cgit_commit_link(char *name, char *title, char *class, char *head, + char *rev); extern void cgit_print_error(char *msg); extern void cgit_print_date(time_t secs, char *format); extern void cgit_print_age(time_t t, time_t max_relative, char *format); extern void cgit_print_docstart(char *title, struct cacheitem *item); extern void cgit_print_docend(); extern void cgit_print_pageheader(char *title, int show_search); extern void cgit_print_snapshot_start(const char *mimetype, const char *filename, struct cacheitem *item); extern void cgit_print_repolist(struct cacheitem *item); diff --git a/ui-commit.c b/ui-commit.c index 885f870..8864fc6 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -147,24 +147,27 @@ void inspect_filepair(struct diff_filepair *pair) void cgit_print_commit(const char *hex) { struct commit *commit, *parent; struct commitinfo *info; struct commit_list *p; unsigned char sha1[20]; char *query; char *filename; char *tmp; int i; + if (!hex) + hex = cgit_query_head; + if (get_sha1(hex, sha1)) { cgit_print_error(fmt("Bad object id: %s", hex)); return; } commit = lookup_commit_reference(sha1); if (!commit) { cgit_print_error(fmt("Bad commit reference: %s", hex)); return; } info = cgit_parse_commit(commit); html("<table class='commit-info'>\n"); @@ -22,29 +22,26 @@ void inspect_files(struct diff_filepair *pair) if (cgit_repo->enable_log_linecount) cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); } void print_commit(struct commit *commit) { struct commitinfo *info; info = cgit_parse_commit(commit); html("<tr><td>"); cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); html("</td><td>"); - char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1)); - char *url = cgit_pageurl(cgit_query_repo, "commit", qry); - html_link_open(url, NULL, NULL); - html_ntxt(cgit_max_msg_len, info->subject); - html_link_close(); + cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, + sha1_to_hex(commit->object.sha1)); if (cgit_repo->enable_log_filecount) { files = 0; lines = 0; cgit_diff_commit(commit, inspect_files); html("</td><td class='right'>"); htmlf("%d", files); if (cgit_repo->enable_log_linecount) { html("</td><td class='right'>"); htmlf("%d", lines); } } html("</td><td>"); diff --git a/ui-shared.c b/ui-shared.c index 64ee79c..71c899a 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -127,26 +127,26 @@ static char *repolink(char *title, char *class, char *page, char *head, html_attr(path); delim = "&"; } if (head && strcmp(head, cgit_repo->defbranch)) { html(delim); html("h="); html_attr(head); delim = "&"; } return fmt("%s", delim); } -static char *reporevlink(char *page, char *name, char *title, char *class, - char *head, char *rev, char *path) +static void reporevlink(char *page, char *name, char *title, char *class, + char *head, char *rev, char *path) { char *delim; delim = repolink(title, class, page, head, path); if (rev && strcmp(rev, cgit_query_head)) { html(delim); html("id="); html_attr(rev); } html("'>"); html_txt(name); html("</a>"); @@ -155,24 +155,36 @@ static char *reporevlink(char *page, char *name, char *title, char *class, void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path) { reporevlink("tree", name, title, class, head, rev, path); } void cgit_log_link(char *name, char *title, char *class, char *head, char *rev, char *path) { reporevlink("log", name, title, class, head, rev, path); } +void cgit_commit_link(char *name, char *title, char *class, char *head, + char *rev) +{ + if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { + name[cgit_max_msg_len] = '\0'; + name[cgit_max_msg_len - 1] = '.'; + name[cgit_max_msg_len - 2] = '.'; + name[cgit_max_msg_len - 3] = '.'; + } + reporevlink("commit", name, title, class, head, rev, NULL); +} + void cgit_print_date(time_t secs, char *format) { char buf[64]; struct tm *time; time = gmtime(&secs); strftime(buf, sizeof(buf)-1, format, time); html_txt(buf); } void cgit_print_age(time_t t, time_t max_relative, char *format) { diff --git a/ui-summary.c b/ui-summary.c index 29b76e3..03dd078 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -6,65 +6,65 @@ * (see COPYING for full license text) */ #include "cgit.h" static int header; static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { struct commit *commit; struct commitinfo *info; - char buf[256], *url; + char buf[256]; + char *ref; + ref = xstrdup(refname); strncpy(buf, refname, sizeof(buf)); commit = lookup_commit(sha1); // object is not really parsed at this point, because of some fallout // from previous calls to git functions in cgit_print_log() commit->object.parsed = 0; if (commit && !parse_commit(commit)){ info = cgit_parse_commit(commit); html("<tr><td>"); - cgit_log_link(refname, NULL, NULL, refname, NULL, NULL); + cgit_log_link(ref, NULL, NULL, ref, NULL, NULL); html("</td><td>"); cgit_print_age(commit->date, -1, NULL); html("</td><td>"); html_txt(info->author); html("</td><td>"); - url = cgit_pageurl(cgit_query_repo, "commit", - fmt("h=%s", sha1_to_hex(sha1))); - html_link_open(url, NULL, NULL); - html_ntxt(cgit_max_msg_len, info->subject); - html_link_close(); + cgit_commit_link(info->subject, NULL, NULL, ref, NULL); html("</td></tr>\n"); cgit_free_commitinfo(info); } else { html("<tr><td>"); html_txt(buf); html("</td><td colspan='3'>"); htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); html("</td></tr>\n"); } + free(ref); return 0; } static void cgit_print_object_ref(struct object *obj) { char *page, *arg, *url; if (obj->type == OBJ_COMMIT) { - page = "commit"; - arg = "h"; + cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, + cgit_query_head, sha1_to_hex(obj->sha1)); + return; } else if (obj->type == OBJ_TREE) { page = "tree"; arg = "id"; } else { page = "view"; arg = "id"; } url = cgit_pageurl(cgit_query_repo, page, fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); html_link_open(url, NULL, NULL); htmlf("%s %s", typename(obj->type), @@ -49,25 +49,24 @@ static void print_object(const unsigned char *sha1, char *path) } html("</table>\n"); } static int ls_item(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned int mode, int stage) { char *name; char *fullpath; enum object_type type; unsigned long size = 0; - char *url, *qry; name = xstrdup(pathname); fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", cgit_query_path ? "/" : "", name); type = sha1_object_info(sha1, &size); if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", name, sha1_to_hex(sha1)); return 0; } |