Add cgit_commit_link() + support for id=sha1 to commit view
This adds a function to generate links to the commit page and extends said page to use id from querystring as primary revision specified (fallback to h). Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Этот коммит содержится в:
родитель
48c487d72d
Коммит
42a7eb9c73
2
cgit.c
2
cgit.c
@ -100,7 +100,7 @@ static void cgit_print_repo_page(struct cacheitem *item)
|
|||||||
cgit_print_tree(cgit_query_sha1, cgit_query_path);
|
cgit_print_tree(cgit_query_sha1, cgit_query_path);
|
||||||
break;
|
break;
|
||||||
case CMD_COMMIT:
|
case CMD_COMMIT:
|
||||||
cgit_print_commit(cgit_query_head);
|
cgit_print_commit(cgit_query_sha1);
|
||||||
break;
|
break;
|
||||||
case CMD_DIFF:
|
case CMD_DIFF:
|
||||||
cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2,
|
cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2,
|
||||||
|
2
cgit.h
2
cgit.h
@ -205,6 +205,8 @@ extern void cgit_tree_link(char *name, char *title, char *class, char *head,
|
|||||||
char *rev, char *path);
|
char *rev, char *path);
|
||||||
extern void cgit_log_link(char *name, char *title, char *class, char *head,
|
extern void cgit_log_link(char *name, char *title, char *class, char *head,
|
||||||
char *rev, char *path);
|
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_error(char *msg);
|
||||||
extern void cgit_print_date(time_t secs, char *format);
|
extern void cgit_print_date(time_t secs, char *format);
|
||||||
|
@ -156,6 +156,9 @@ void cgit_print_commit(const char *hex)
|
|||||||
char *tmp;
|
char *tmp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (!hex)
|
||||||
|
hex = cgit_query_head;
|
||||||
|
|
||||||
if (get_sha1(hex, sha1)) {
|
if (get_sha1(hex, sha1)) {
|
||||||
cgit_print_error(fmt("Bad object id: %s", hex));
|
cgit_print_error(fmt("Bad object id: %s", hex));
|
||||||
return;
|
return;
|
||||||
|
7
ui-log.c
7
ui-log.c
@ -31,11 +31,8 @@ void print_commit(struct commit *commit)
|
|||||||
html("<tr><td>");
|
html("<tr><td>");
|
||||||
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
|
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
|
||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1));
|
cgit_commit_link(info->subject, NULL, NULL, cgit_query_head,
|
||||||
char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
|
sha1_to_hex(commit->object.sha1));
|
||||||
html_link_open(url, NULL, NULL);
|
|
||||||
html_ntxt(cgit_max_msg_len, info->subject);
|
|
||||||
html_link_close();
|
|
||||||
if (cgit_repo->enable_log_filecount) {
|
if (cgit_repo->enable_log_filecount) {
|
||||||
files = 0;
|
files = 0;
|
||||||
lines = 0;
|
lines = 0;
|
||||||
|
16
ui-shared.c
16
ui-shared.c
@ -136,8 +136,8 @@ static char *repolink(char *title, char *class, char *page, char *head,
|
|||||||
return fmt("%s", delim);
|
return fmt("%s", delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *reporevlink(char *page, char *name, char *title, char *class,
|
static void reporevlink(char *page, char *name, char *title, char *class,
|
||||||
char *head, char *rev, char *path)
|
char *head, char *rev, char *path)
|
||||||
{
|
{
|
||||||
char *delim;
|
char *delim;
|
||||||
|
|
||||||
@ -164,6 +164,18 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
|
|||||||
reporevlink("log", name, title, class, head, rev, 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)
|
void cgit_print_date(time_t secs, char *format)
|
||||||
{
|
{
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
18
ui-summary.c
18
ui-summary.c
@ -15,8 +15,10 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
|
|||||||
{
|
{
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
struct commitinfo *info;
|
struct commitinfo *info;
|
||||||
char buf[256], *url;
|
char buf[256];
|
||||||
|
char *ref;
|
||||||
|
|
||||||
|
ref = xstrdup(refname);
|
||||||
strncpy(buf, refname, sizeof(buf));
|
strncpy(buf, refname, sizeof(buf));
|
||||||
commit = lookup_commit(sha1);
|
commit = lookup_commit(sha1);
|
||||||
// object is not really parsed at this point, because of some fallout
|
// object is not really parsed at this point, because of some fallout
|
||||||
@ -25,17 +27,13 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
|
|||||||
if (commit && !parse_commit(commit)){
|
if (commit && !parse_commit(commit)){
|
||||||
info = cgit_parse_commit(commit);
|
info = cgit_parse_commit(commit);
|
||||||
html("<tr><td>");
|
html("<tr><td>");
|
||||||
cgit_log_link(refname, NULL, NULL, refname, NULL, NULL);
|
cgit_log_link(ref, NULL, NULL, ref, NULL, NULL);
|
||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
cgit_print_age(commit->date, -1, NULL);
|
cgit_print_age(commit->date, -1, NULL);
|
||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
html_txt(info->author);
|
html_txt(info->author);
|
||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
url = cgit_pageurl(cgit_query_repo, "commit",
|
cgit_commit_link(info->subject, NULL, NULL, ref, NULL);
|
||||||
fmt("h=%s", sha1_to_hex(sha1)));
|
|
||||||
html_link_open(url, NULL, NULL);
|
|
||||||
html_ntxt(cgit_max_msg_len, info->subject);
|
|
||||||
html_link_close();
|
|
||||||
html("</td></tr>\n");
|
html("</td></tr>\n");
|
||||||
cgit_free_commitinfo(info);
|
cgit_free_commitinfo(info);
|
||||||
} else {
|
} else {
|
||||||
@ -45,6 +43,7 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
|
|||||||
htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
|
htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
|
||||||
html("</td></tr>\n");
|
html("</td></tr>\n");
|
||||||
}
|
}
|
||||||
|
free(ref);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +53,9 @@ static void cgit_print_object_ref(struct object *obj)
|
|||||||
char *page, *arg, *url;
|
char *page, *arg, *url;
|
||||||
|
|
||||||
if (obj->type == OBJ_COMMIT) {
|
if (obj->type == OBJ_COMMIT) {
|
||||||
page = "commit";
|
cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
|
||||||
arg = "h";
|
cgit_query_head, sha1_to_hex(obj->sha1));
|
||||||
|
return;
|
||||||
} else if (obj->type == OBJ_TREE) {
|
} else if (obj->type == OBJ_TREE) {
|
||||||
page = "tree";
|
page = "tree";
|
||||||
arg = "id";
|
arg = "id";
|
||||||
|
@ -58,7 +58,6 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
|
|||||||
char *fullpath;
|
char *fullpath;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
unsigned long size = 0;
|
unsigned long size = 0;
|
||||||
char *url, *qry;
|
|
||||||
|
|
||||||
name = xstrdup(pathname);
|
name = xstrdup(pathname);
|
||||||
fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
|
fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user