author | Lars Hjemli <hjemli@gmail.com> | 2007-06-17 12:53:02 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-06-17 12:53:02 (UTC) |
commit | 42a7eb9c73457319a3fd5441ff26046fc9b31dad (patch) (side-by-side diff) | |
tree | 4771b955e031005e7c222ef0cbabb719f7cd003a /ui-shared.c | |
parent | 48c487d72daef7e71683a85f775db8d36ab20341 (diff) | |
download | cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.zip cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.tar.gz cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.tar.bz2 |
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>
-rw-r--r-- | ui-shared.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/ui-shared.c b/ui-shared.c index 64ee79c..71c899a 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -91,124 +91,136 @@ static char *repolink(char *title, char *class, char *page, char *head, char *path) { char *delim = "?"; html("<a"); if (title) { html(" title='"); html_attr(title); html("'"); } if (class) { html(" class='"); html_attr(class); html("'"); } html(" href='"); if (cgit_virtual_root) { html_attr(cgit_virtual_root); if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') html("/"); html_attr(cgit_repo->url); if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') html("/"); html(page); html("/"); if (path) html_attr(path); } else { html(cgit_script_name); html("?url="); html_attr(cgit_repo->url); if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') html("/"); html(page); html("/"); if (path) 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, +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>"); } 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) { time_t now, secs; time(&now); secs = now - t; if (secs > max_relative && max_relative >= 0) { cgit_print_date(t, format); return; } if (secs < TM_HOUR * 2) { htmlf("<span class='age-mins'>%.0f min.</span>", secs * 1.0 / TM_MIN); return; } if (secs < TM_DAY * 2) { htmlf("<span class='age-hours'>%.0f hours</span>", secs * 1.0 / TM_HOUR); return; } if (secs < TM_WEEK * 2) { htmlf("<span class='age-days'>%.0f days</span>", secs * 1.0 / TM_DAY); return; } if (secs < TM_MONTH * 2) { htmlf("<span class='age-weeks'>%.0f weeks</span>", secs * 1.0 / TM_WEEK); return; } if (secs < TM_YEAR * 2) { htmlf("<span class='age-months'>%.0f months</span>", secs * 1.0 / TM_MONTH); return; } htmlf("<span class='age-years'>%.0f years</span>", |