From: Lars Hjemli Date: Sun, 18 Mar 2012 20:59:36 +0000 (+0000) Subject: Merge branch 'lh/module-links' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/2b9fab8d30420d935745c4d84ea22412ab2485e5?hp=-c Merge branch 'lh/module-links' --- 2b9fab8d30420d935745c4d84ea22412ab2485e5 diff --combined cgit.c index 1d50129,9eb2535..7e3d349 --- a/cgit.c +++ b/cgit.c @@@ -60,6 -60,8 +60,8 @@@ static void process_cached_repolist(con void repo_config(struct cgit_repo *repo, const char *name, const char *value) { + struct string_list_item *item; + if (!strcmp(name, "name")) repo->name = xstrdup(value); else if (!strcmp(name, "clone-url")) @@@ -86,7 -88,10 +88,10 @@@ repo->max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "module-link")) repo->module_link= xstrdup(value); - else if (!strcmp(name, "section")) + else if (!prefixcmp(name, "module-link.")) { + item = string_list_append(&repo->submodules, name + 12); + item->util = xstrdup(value); + } else if (!strcmp(name, "section")) repo->section = xstrdup(value); else if (!strcmp(name, "readme") && value != NULL) repo->readme = xstrdup(value); @@@ -298,7 -303,6 +303,7 @@@ static void querystring_cb(const char * ctx.qry.period = xstrdup(value); } else if (!strcmp(name, "ss")) { ctx.qry.ssdiff = atoi(value); + ctx.qry.has_ssdiff = 1; } else if (!strcmp(name, "all")) { ctx.qry.show_all = atoi(value); } else if (!strcmp(name, "context")) { @@@ -339,7 -343,6 +344,6 @@@ static void prepare_context(struct cgit ctx->cfg.max_repodesc_len = 80; ctx->cfg.max_blob_size = 0; ctx->cfg.max_stats = 0; - ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; ctx->cfg.project_list = NULL; ctx->cfg.renamelimit = -1; ctx->cfg.remove_suffix = 0; @@@ -422,17 -425,13 +426,17 @@@ static int prepare_repo_cmd(struct cgit char *tmp; unsigned char sha1[20]; int nongit = 0; + int rc; setenv("GIT_DIR", ctx->repo->path, 1); setup_git_directory_gently(&nongit); if (nongit) { + rc = errno; ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, "config error"); - tmp = fmt("Not a git repository: '%s'", ctx->repo->path); + tmp = fmt("Failed to open %s: %s", + ctx->repo->name, + rc ? strerror(rc) : "Not a valid git repository"); ctx->repo = NULL; cgit_print_http_headers(ctx); cgit_print_docstart(ctx); @@@ -470,6 -469,7 +474,7 @@@ cgit_print_docend(); return 1; } + sort_string_list(&ctx->repo->submodules); cgit_prepare_repo_env(ctx->repo); return 0; } diff --combined cgit.h index c7ab5c6,9d0b3d0..b7c7ac9 --- a/cgit.h +++ b/cgit.h @@@ -88,6 -88,7 +88,7 @@@ struct cgit_repo struct cgit_filter *about_filter; struct cgit_filter *commit_filter; struct cgit_filter *source_filter; + struct string_list submodules; }; typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name, @@@ -137,7 -138,6 +138,7 @@@ struct reflist struct cgit_query { int has_symref; int has_sha1; + int has_ssdiff; char *raw; char *repo; char *page; diff --combined cgitrc.5.txt index a22423b,c8198c1..b4ad2ac --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@@ -230,7 -230,7 +230,7 @@@ module-link: Text which will be used as the formatstring for a hyperlink when a submodule is printed in a directory listing. The arguments for the formatstring are the path and SHA1 of the submodule commit. Default - value: "./?repo=%s&page=commit&id=%s" + value: none. nocache:: If set to the value "1" caching will be disabled. This settings is @@@ -417,6 -417,12 +417,12 @@@ repo.module-link: formatstring are the path and SHA1 of the submodule commit. Default value: + repo.module-link.:: + Text which will be used as the formatstring for a hyperlink when a + submodule with the specified subdirectory path is printed in a + directory listing. The only argument for the formatstring is the SHA1 + of the submodule commit. Default value: none. + repo.max-stats:: Override the default maximum statistics period. Valid values are equal to the values specified for the global "max-stats" setting. Default @@@ -500,7 -506,7 +506,7 @@@ Also, all filters are handed the follow If a setting is not defined for a repository and the corresponding global setting is also not defined (if applicable), then the corresponding -environment variable will be an empty string. +environment variable will be unset. MACRO EXPANSION diff --combined shared.c index 0c8ce3e,0add2e5..cb52380 --- a/shared.c +++ b/shared.c @@@ -8,6 -8,7 +8,6 @@@ #include "cgit.h" #include -#include struct cgit_repolist cgit_repolist; struct cgit_context ctx; @@@ -70,6 -71,7 +70,7 @@@ struct cgit_repo *cgit_add_repo(const c ret->commit_filter = ctx.cfg.commit_filter; ret->source_filter = ctx.cfg.source_filter; ret->clone_url = ctx.cfg.clone_url; + ret->submodules.strdup_strings = 1; return ret; } @@@ -392,7 -394,7 +393,7 @@@ void cgit_prepare_repo_env(struct cgit_ p = env_vars; q = p + env_var_count; for (; p < q; p++) - if (setenv(p->name, p->value, 1)) + if (p->value && setenv(p->name, p->value, 1)) fprintf(stderr, warn, p->name, p->value); } diff --combined ui-shared.c index d7d75bf,b736fca..43166af --- a/ui-shared.c +++ b/ui-shared.c @@@ -133,7 -133,7 +133,7 @@@ char *cgit_currurl( return fmt("%s/", ctx.cfg.virtual_root); } -static void site_url(const char *page, const char *search, int ofs) +static void site_url(const char *page, const char *search, const char *sort, int ofs) { char *delim = "?"; @@@ -154,12 -154,6 +154,12 @@@ html_attr(search); delim = "&"; } + if (sort) { + html(delim); + html("s="); + html_attr(sort); + delim = "&"; + } if (ofs) { html(delim); htmlf("ofs=%d", ofs); @@@ -167,7 -161,7 +167,7 @@@ } static void site_link(const char *page, const char *name, const char *title, - const char *class, const char *search, int ofs) + const char *class, const char *search, const char *sort, int ofs) { html(""); html_txt(name); html(""); } void cgit_index_link(const char *name, const char *title, const char *class, - const char *pattern, int ofs) + const char *pattern, const char *sort, int ofs) { - site_link(NULL, name, title, class, pattern, ofs); + site_link(NULL, name, title, class, pattern, sort, ofs); } static char *repolink(const char *title, const char *class, const char *page, @@@ -294,7 -288,7 +294,7 @@@ void cgit_log_link(const char *name, co char *delim; delim = repolink(title, class, "log", head, path); - if (rev && strcmp(rev, ctx.qry.head)) { + if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { html(delim); html("id="); html_url_arg(rev); @@@ -338,7 -332,7 +338,7 @@@ void cgit_commit_link(char *name, cons char *delim; delim = repolink(title, class, "commit", head, path); - if (rev && strcmp(rev, ctx.qry.head)) { + if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { html(delim); html("id="); html_url_arg(rev); @@@ -434,7 -428,7 +434,7 @@@ void cgit_self_link(char *name, const c struct cgit_context *ctx) { if (!strcmp(ctx->qry.page, "repolist")) - return cgit_index_link(name, title, class, ctx->qry.search, + return cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort, ctx->qry.ofs); else if (!strcmp(ctx->qry.page, "summary")) return cgit_summary_link(name, title, class, ctx->qry.head); @@@ -509,6 -503,62 +509,62 @@@ void cgit_object_link(struct object *ob reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); } + struct string_list_item *lookup_path(struct string_list *list, + const char *path) + { + struct string_list_item *item; + + while (path && path[0]) { + if ((item = string_list_lookup(list, path))) + return item; + if (!(path = strchr(path, '/'))) + break; + path++; + } + return NULL; + } + + void cgit_submodule_link(const char *class, char *path, const char *rev) + { + struct string_list *list; + struct string_list_item *item; + char tail, *dir; + size_t len; + + tail = 0; + list = &ctx.repo->submodules; + item = lookup_path(list, path); + if (!item) { + len = strlen(path); + tail = path[len - 1]; + if (tail == '/') { + path[len - 1] = 0; + item = lookup_path(list, path); + } + } + html("module_link, dir, rev)); + } else { + html("#"); + } + html("'>"); + html_txt(path); + html(""); + if (item && tail) + path[len - 1] = tail; + } + void cgit_print_date(time_t secs, const char *format, int local_time) { char buf[64]; @@@ -619,7 -669,7 +675,7 @@@ void cgit_print_docstart(struct cgit_co html_attr(ctx->cfg.favicon); html("'/>\n"); } - if (host && ctx->repo) { + if (host && ctx->repo && ctx->qry.head) { html(""); if (ctx->repo) { - cgit_index_link("index", NULL, NULL, NULL, 0); + cgit_index_link("index", NULL, NULL, NULL, NULL, 0); html(" : "); cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); html(""); @@@ -864,10 -914,10 +920,10 @@@ void cgit_print_pageheader(struct cgit_ html("\n"); html("\n"); } else { - site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); + site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, NULL, 0); if (ctx->cfg.root_readme) site_link("about", "about", NULL, hc(ctx, "about"), - NULL, 0); + NULL, NULL, 0); html(""); html("