From: Lars Hjemli Date: Sun, 18 Mar 2012 21:00:18 +0000 (+0000) Subject: Merge branch 'jp/defbranch' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/181b6e789b79fc385e5ec75b2b83f01192d54051?hp=-c Merge branch 'jp/defbranch' --- 181b6e789b79fc385e5ec75b2b83f01192d54051 diff --combined cgit.c index 7e3d349,624cb2c..6a75f27 --- a/cgit.c +++ b/cgit.c @@@ -60,8 -60,6 +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")) @@@ -88,10 -86,7 +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); @@@ -303,7 -298,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")) { @@@ -344,6 -338,7 +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; @@@ -421,6 -416,17 +421,17 @@@ char *find_default_branch(struct cgit_r return ref; } + static char *guess_defbranch(const char *repo_path) + { + const char *ref; + unsigned char sha1[20]; + + ref = resolve_ref("HEAD", sha1, 0, NULL); + if (!ref || prefixcmp(ref, "refs/heads/")) + return "master"; + return xstrdup(ref + 11); + } + static int prepare_repo_cmd(struct cgit_context *ctx) { char *tmp; @@@ -447,10 -453,12 +458,12 @@@ } ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); + if (!ctx->repo->defbranch) + ctx->repo->defbranch = guess_defbranch(ctx->repo->path); + if (!ctx->qry.head) { ctx->qry.nohead = 1; ctx->qry.head = find_default_branch(ctx->repo); - ctx->repo->defbranch = ctx->qry.head; } if (!ctx->qry.head) { @@@ -474,7 -482,6 +487,7 @@@ cgit_print_docend(); return 1; } + sort_string_list(&ctx->repo->submodules); cgit_prepare_repo_env(ctx->repo); return 0; } diff --combined cgitrc.5.txt index b4ad2ac,c2c5680..fab0e0a --- 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 @@@ -377,7 -377,8 +377,8 @@@ repo.commit-filter: repo.defbranch:: The name of the default branch for this repository. If no such branch exists in the repository, the first branch name (when sorted) is used - as default instead. Default value: "master". + as default instead. Default value: branch pointed to by HEAD, or + "master" if there is no suitable HEAD. repo.desc:: The value to show as repository description. Default value: none. @@@ -417,12 -418,6 +418,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 @@@ -506,7 -501,7 +507,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 cb52380,9c839a9..0a0e22e --- 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; @@@ -55,7 -56,6 +55,6 @@@ struct cgit_repo *cgit_add_repo(const c ret->desc = "[no description]"; ret->owner = NULL; ret->section = ctx.cfg.section; - ret->defbranch = "master"; ret->snapshots = ctx.cfg.snapshots; ret->enable_commit_graph = ctx.cfg.enable_commit_graph; ret->enable_log_filecount = ctx.cfg.enable_log_filecount; @@@ -70,7 -70,6 +69,7 @@@ 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; } @@@ -393,7 -392,7 +392,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-repolist.c index a09a689,f21d28d..d946f32 --- a/ui-repolist.c +++ b/ui-repolist.c @@@ -45,7 -45,8 +45,8 @@@ static int get_repo_modtime(const struc return 1; } - path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); + path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch ? + repo->defbranch : "master"); if (stat(path, &s) == 0) { *mtime = s.st_mtime; r->mtime = *mtime; @@@ -118,13 -119,13 +119,13 @@@ void print_header(int columns } -void print_pager(int items, int pagelen, char *search) +void print_pager(int items, int pagelen, char *search, char *sort) { int i; html("
"); for(i = 0; i * pagelen < items; i++) cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, - search, i * pagelen); + search, sort, i * pagelen); html("
"); } @@@ -291,7 -292,7 +292,7 @@@ void cgit_print_repolist( if (!hits) cgit_print_error("No repositories found"); else if (hits > ctx.cfg.max_repo_count) - print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search); + print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); cgit_print_docend(); }