author | Lars Hjemli <hjemli@gmail.com> | 2008-12-03 16:34:23 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-12-03 16:34:23 (UTC) |
commit | a1b01b2513510f8f93f7f8ca39969002cd496a19 (patch) (side-by-side diff) | |
tree | 143e569416a89b31de6f96e8e79f8841c24dd935 | |
parent | c7d1402b177f4cf835e81f962e2faa3c9e28c549 (diff) | |
download | cgit-a1b01b2513510f8f93f7f8ca39969002cd496a19.zip cgit-a1b01b2513510f8f93f7f8ca39969002cd496a19.tar.gz cgit-a1b01b2513510f8f93f7f8ca39969002cd496a19.tar.bz2 |
ui-log: try to disambiguate ref names
The 'h' querystring parameter in cgit is normally used to specify
a branch (i.e. a ref below refs/heads/), but if a repository contains
a tag with the same name as a branch the output from ui-log would use
the tag as start-revision.
This patch tries to fix the issue by checking if the specified ref is
valid as a branch name; if so, the full refname is used in the call
to setup_revisions().
Noticed-by: Takamori Yamaguchi <akschar@gmail.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-log.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -43,60 +43,73 @@ void print_commit(struct commit *commit) html_link_open(tmp, NULL, NULL); cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); html_link_close(); html("</td><td>"); cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, sha1_to_hex(commit->object.sha1)); html("</td><td>"); html_txt(info->author); if (ctx.repo->enable_log_filecount) { files = 0; add_lines = 0; rem_lines = 0; cgit_diff_commit(commit, inspect_files); html("</td><td>"); htmlf("%d", files); if (ctx.repo->enable_log_linecount) { html("</td><td>"); htmlf("-%d/+%d", rem_lines, add_lines); } } html("</td></tr>\n"); cgit_free_commitinfo(info); } +static const char *disambiguate_ref(const char *ref) +{ + unsigned char sha1[20]; + const char *longref; + + longref = fmt("refs/heads/%s", ref); + if (get_sha1(longref, sha1) == 0) + return longref; + + return ref; +} void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) { struct rev_info rev; struct commit *commit; - const char *argv[] = {NULL, tip, NULL, NULL, NULL}; + const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; int argc = 2; int i, columns = 3; if (!tip) - argv[1] = ctx.qry.head; + tip = ctx.qry.head; + + argv[1] = disambiguate_ref(tip); if (grep && pattern && (!strcmp(grep, "grep") || !strcmp(grep, "author") || !strcmp(grep, "committer"))) argv[argc++] = fmt("--%s=%s", grep, pattern); if (path) { argv[argc++] = "--"; argv[argc++] = path; } init_revisions(&rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.verbose_header = 1; rev.show_root_diff = 0; setup_revisions(argc, argv, &rev, NULL); rev.grep_filter.regflags |= REG_ICASE; compile_grep_patterns(&rev.grep_filter); prepare_revision_walk(&rev); if (pager) html("<table class='list nowrap'>"); html("<tr class='nohover'><th class='left'>Age</th>" |