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>
This commit is contained in:
Lars Hjemli 2008-12-03 17:34:23 +01:00
parent c7d1402b17
commit a1b01b2513

View File

@ -64,18 +64,31 @@ void print_commit(struct commit *commit)
cgit_free_commitinfo(info); 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, void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
char *path, int pager) char *path, int pager)
{ {
struct rev_info rev; struct rev_info rev;
struct commit *commit; struct commit *commit;
const char *argv[] = {NULL, tip, NULL, NULL, NULL}; const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
int argc = 2; int argc = 2;
int i, columns = 3; int i, columns = 3;
if (!tip) if (!tip)
argv[1] = ctx.qry.head; tip = ctx.qry.head;
argv[1] = disambiguate_ref(tip);
if (grep && pattern && (!strcmp(grep, "grep") || if (grep && pattern && (!strcmp(grep, "grep") ||
!strcmp(grep, "author") || !strcmp(grep, "author") ||