From: Lars Hjemli Date: Fri, 29 Jun 2007 18:32:08 +0000 (+0200) Subject: Merge branch 'lh/menu' X-Git-Tag: v0.6~16 X-Git-Url: https://git.cameronkatri.com/cgit.git/commitdiff_plain/16a3d2779ccd56bf7954d98da547247d8796544b?hp=-c Merge branch 'lh/menu' * lh/menu: Add ofs argument to cgit_log_link and use it in ui-log.c Add trim_end() and use it to remove trailing slashes from repo paths Do not include current path in the "tree" menu link Add setting to enable/disable extra links on index page Change S/L/T to summary/log/tree Change "files" to "tree" Include querystring as part of cached filename for repo summary page Add more menuitems on repo pages --- 16a3d2779ccd56bf7954d98da547247d8796544b diff --combined cgit.c index 11dff76,b943fe5..d9a03c2 --- a/cgit.c +++ b/cgit.c @@@ -8,6 -8,9 +8,6 @@@ #include "cgit.h" -const char cgit_version[] = CGIT_VERSION; - - static int cgit_prepare_cache(struct cacheitem *item) { if (!cgit_repo && cgit_query_repo) { @@@ -26,13 -29,15 +26,15 @@@ } if (!cgit_cmd) { - item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, - cache_safe_filename(cgit_repo->url))); + item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, + cache_safe_filename(cgit_repo->url), + cache_safe_filename(cgit_querystring))); item->ttl = cgit_cache_repo_ttl; } else { item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, - cache_safe_filename(cgit_repo->url), cgit_query_page, - cache_safe_filename(cgit_querystring))); + cache_safe_filename(cgit_repo->url), + cgit_query_page, + cache_safe_filename(cgit_querystring))); if (cgit_query_has_symref) item->ttl = cgit_cache_dynamic_ttl; else if (cgit_query_has_sha1) diff --combined cgit.h index 9558362,a59a370..2ff5340 --- a/cgit.h +++ b/cgit.h @@@ -98,7 -98,7 +98,7 @@@ struct taginfo char *msg; }; -extern const char cgit_version[]; +extern const char *cgit_version; extern struct repolist cgit_repolist; extern struct repoinfo *cgit_repo; @@@ -118,6 -118,7 +118,7 @@@ extern char *cgit_repo_group extern int cgit_nocache; extern int cgit_snapshots; + extern int cgit_enable_index_links; extern int cgit_enable_log_filecount; extern int cgit_enable_log_linecount; extern int cgit_max_lock_attempts; @@@ -158,6 -159,7 +159,7 @@@ extern int chk_zero(int result, char *m extern int chk_positive(int result, char *msg); extern int hextoint(char c); + extern char *trim_end(const char *str, char c); extern void *cgit_free_commitinfo(struct commitinfo *info); @@@ -204,7 -206,7 +206,7 @@@ extern char *cgit_pageurl(const char *r 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); + char *rev, char *path, int ofs); extern void cgit_commit_link(char *name, char *title, char *class, char *head, char *rev); extern void cgit_diff_link(char *name, char *title, char *class, char *head, diff --combined shared.c index f7f43b2,45db735..1a5b866 --- a/shared.c +++ b/shared.c @@@ -12,8 -12,6 +12,8 @@@ struct repolist cgit_repolist struct repoinfo *cgit_repo; int cgit_cmd; +const char *cgit_version = CGIT_VERSION; + char *cgit_root_title = "Git repository browser"; char *cgit_css = "/cgit.css"; char *cgit_logo = "/git-logo.png"; @@@ -28,6 -26,7 +28,7 @@@ char *cgit_repo_group = NULL int cgit_nocache = 0; int cgit_snapshots = 0; + int cgit_enable_index_links = 0; int cgit_enable_log_filecount = 0; int cgit_enable_log_linecount = 0; int cgit_max_lock_attempts = 5; @@@ -148,6 -147,8 +149,8 @@@ void cgit_global_config_cb(const char * cgit_nocache = atoi(value); else if (!strcmp(name, "snapshots")) cgit_snapshots = atoi(value); + else if (!strcmp(name, "enable-index-links")) + cgit_enable_index_links = atoi(value); else if (!strcmp(name, "enable-log-filecount")) cgit_enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) @@@ -227,7 -228,7 +230,7 @@@ void cgit_querystring_cb(const char *na } else if (!strcmp(name, "ofs")) { cgit_query_ofs = atoi(value); } else if (!strcmp(name, "path")) { - cgit_query_path = xstrdup(value); + cgit_query_path = trim_end(value, '/'); } else if (!strcmp(name, "name")) { cgit_query_name = xstrdup(value); } @@@ -256,6 -257,28 +259,28 @@@ int hextoint(char c return -1; } + char *trim_end(const char *str, char c) + { + int len; + char *s, *t; + + if (str == NULL) + return NULL; + t = (char *)str; + len = strlen(t); + while(len > 0 && t[len - 1] == c) + len--; + + if (len == 0) + return NULL; + + c = t[len]; + t[len] = '\0'; + s = xstrdup(t); + t[len] = c; + return s; + } + void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options, void *data) { diff --combined ui-shared.c index 110c696,bfcc2ac..d4376ce --- a/ui-shared.c +++ b/ui-shared.c @@@ -111,20 -111,24 +111,24 @@@ static char *repolink(char *title, cha html_attr(cgit_repo->url); if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') html("/"); - html(page); - html("/"); - if (path) - html_attr(path); + if (page) { + 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); + if (page) { + html(page); + html("/"); + if (path) + html_attr(path); + } delim = "&"; } if (head && strcmp(head, cgit_repo->defbranch)) { @@@ -159,9 -163,25 +163,25 @@@ void cgit_tree_link(char *name, char *t } void cgit_log_link(char *name, char *title, char *class, char *head, - char *rev, char *path) + char *rev, char *path, int ofs) { - reporevlink("log", name, title, class, head, rev, path); + char *delim; + + delim = repolink(title, class, "log", head, path); + if (rev && strcmp(rev, cgit_query_head)) { + html(delim); + html("id="); + html_attr(rev); + delim = "&"; + } + if (ofs > 0) { + html(delim); + html("ofs="); + htmlf("%d", ofs); + } + html("'>"); + html_txt(name); + html(""); } void cgit_commit_link(char *name, char *title, char *class, char *head, @@@ -262,7 -282,7 +282,7 @@@ void cgit_print_docstart(char *title, s html(""); html_txt(title); html("\n"); - htmlf("\n", cgit_version); + htmlf("\n", cgit_version); html("\n"); @@@ -279,19 -299,38 +299,38 @@@ void cgit_print_docend( void cgit_print_pageheader(char *title, int show_search) { html(""); - html(""); html(""); html("
"); - htmlf("root", cgit_rooturl()); if (cgit_query_repo) { - htmlf(" : ", cgit_repourl(cgit_repo->url)); html_txt(cgit_repo->name); - htmlf(" : %s", title); + html(" ("); + html_txt(cgit_query_head); + html(") :  "); + reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, + NULL, NULL); + html(" "); + cgit_log_link("log", NULL, NULL, cgit_query_head, + cgit_query_sha1, cgit_query_path, 0); + html(" "); + cgit_tree_link("tree", NULL, NULL, cgit_query_head, + cgit_query_sha1, NULL); + html(" "); + cgit_commit_link("commit", NULL, NULL, cgit_query_head, + cgit_query_sha1); + html(" "); + cgit_diff_link("diff", NULL, NULL, cgit_query_head, + cgit_query_sha1, cgit_query_sha2, + cgit_query_path); + } else { + html_txt("Index of repositories"); } html("