#include "configfile.h"
#include "html.h"
#include "ui-shared.h"
+#include "scan-tree.h"
const char *cgit_version = CGIT_VERSION;
ctx.cfg.root_readme = xstrdup(value);
else if (!strcmp(name, "css"))
ctx.cfg.css = xstrdup(value);
+ else if (!strcmp(name, "favicon"))
+ ctx.cfg.favicon = xstrdup(value);
+ else if (!strcmp(name, "footer"))
+ ctx.cfg.footer = xstrdup(value);
else if (!strcmp(name, "logo"))
ctx.cfg.logo = xstrdup(value);
else if (!strcmp(name, "index-header"))
ctx.cfg.robots = xstrdup(value);
else if (!strcmp(name, "clone-prefix"))
ctx.cfg.clone_prefix = xstrdup(value);
+ else if (!strcmp(name, "local-time"))
+ ctx.cfg.local_time = atoi(value);
else if (!strcmp(name, "repo.group"))
ctx.cfg.repo_group = xstrdup(value);
else if (!strcmp(name, "repo.url"))
} else if (!strcmp(name, "p")) {
ctx.qry.page = xstrdup(value);
} else if (!strcmp(name, "url")) {
+ ctx.qry.url = xstrdup(value);
cgit_parse_url(value);
} else if (!strcmp(name, "qt")) {
ctx.qry.grep = xstrdup(value);
ctx.qry.path = trim_end(value, '/');
} else if (!strcmp(name, "name")) {
ctx.qry.name = xstrdup(value);
+ } else if (!strcmp(name, "mimetype")) {
+ ctx.qry.mimetype = xstrdup(value);
+ } else if (!strcmp(name, "s")){
+ ctx.qry.sort = xstrdup(value);
+ } else if (!strcmp(name, "showmsg")) {
+ ctx.qry.showmsg = atoi(value);
}
}
ctx->cfg.cache_static_ttl = -1;
ctx->cfg.css = "/cgit.css";
ctx->cfg.logo = "/git-logo.png";
+ ctx->cfg.local_time = 0;
ctx->cfg.max_repo_count = 50;
ctx->cfg.max_commit_count = 50;
ctx->cfg.max_lock_attempts = 5;
- ctx->cfg.max_msg_len = 60;
- ctx->cfg.max_repodesc_len = 60;
+ ctx->cfg.max_msg_len = 80;
+ ctx->cfg.max_repodesc_len = 80;
ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
ctx->cfg.renamelimit = -1;
ctx->cfg.robots = "index, nofollow";
ctx->cfg.root_title = "Git repository browser";
ctx->cfg.root_desc = "a fast webinterface for the git dscm";
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
+ ctx->cfg.summary_branches = 10;
+ ctx->cfg.summary_log = 10;
+ ctx->cfg.summary_tags = 10;
ctx->page.mimetype = "text/html";
ctx->page.charset = PAGE_ENCODING;
ctx->page.filename = NULL;
+ ctx->page.size = 0;
ctx->page.modified = time(NULL);
ctx->page.expires = ctx->page.modified;
}
char *find_default_branch(struct cgit_repo *repo)
{
struct refmatch info;
+ char *ref;
info.req_ref = repo->defbranch;
info.first_ref = NULL;
info.match = 0;
for_each_branch_ref(find_current_ref, &info);
if (info.match)
- return info.req_ref;
+ ref = info.req_ref;
else
- return info.first_ref;
+ ref = info.first_ref;
+ if (ref)
+ ref = xstrdup(ref);
+ return ref;
}
static int prepare_repo_cmd(struct cgit_context *ctx)
ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc);
if (!ctx->qry.head) {
- ctx->qry.head = xstrdup(find_default_branch(ctx->repo));
+ ctx->qry.nohead = 1;
+ ctx->qry.head = find_default_branch(ctx->repo);
ctx->repo->defbranch = ctx->qry.head;
}
cgit_print_docend();
}
+int cmp_repos(const void *a, const void *b)
+{
+ const struct cgit_repo *ra = a, *rb = b;
+ return strcmp(ra->url, rb->url);
+}
+
+void print_repo(struct cgit_repo *repo)
+{
+ printf("repo.url=%s\n", repo->url);
+ printf("repo.name=%s\n", repo->name);
+ printf("repo.path=%s\n", repo->path);
+ if (repo->owner)
+ printf("repo.owner=%s\n", repo->owner);
+ if (repo->desc)
+ printf("repo.desc=%s\n", repo->desc);
+ if (repo->readme)
+ printf("repo.readme=%s\n", repo->readme);
+ printf("\n");
+}
+
+void print_repolist(struct cgit_repolist *list)
+{
+ int i;
+
+ for(i = 0; i < list->count; i++)
+ print_repo(&list->repos[i]);
+}
+
+
static void cgit_parse_args(int argc, const char **argv)
{
int i;
+ int scan = 0;
for (i = 1; i < argc; i++) {
if (!strncmp(argv[i], "--cache=", 8)) {
if (!strncmp(argv[i], "--ofs=", 6)) {
ctx.qry.ofs = atoi(argv[i]+6);
}
+ if (!strncmp(argv[i], "--scan-tree=", 12)) {
+ scan++;
+ scan_tree(argv[i] + 12);
+ }
+ }
+ if (scan) {
+ qsort(cgit_repolist.repos, cgit_repolist.count,
+ sizeof(struct cgit_repo), cmp_repos);
+ print_repolist(&cgit_repolist);
+ exit(0);
}
}
int main(int argc, const char **argv)
{
const char *cgit_config_env = getenv("CGIT_CONFIG");
+ const char *path;
+ char *qry;
int err, ttl;
prepare_context(&ctx);
cgit_repolist.count = 0;
cgit_repolist.repos = NULL;
- parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
- config_cb);
- ctx.repo = NULL;
if (getenv("SCRIPT_NAME"))
ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
if (getenv("QUERY_STRING"))
ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
cgit_parse_args(argc, argv);
+ parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
+ config_cb);
+ ctx.repo = NULL;
http_parse_querystring(ctx.qry.raw, querystring_cb);
+ /* If virtual-root isn't specified in cgitrc, lets pretend
+ * that virtual-root equals SCRIPT_NAME.
+ */
+ if (!ctx.cfg.virtual_root)
+ ctx.cfg.virtual_root = ctx.cfg.script_name;
+
+ /* If no url parameter is specified on the querystring, lets
+ * use PATH_INFO as url. This allows cgit to work with virtual
+ * urls without the need for rewriterules in the webserver (as
+ * long as PATH_INFO is included in the cache lookup key).
+ */
+ path = getenv("PATH_INFO");
+ if (!ctx.qry.url && path) {
+ if (path[0] == '/')
+ path++;
+ ctx.qry.url = xstrdup(path);
+ if (ctx.qry.raw) {
+ qry = ctx.qry.raw;
+ ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
+ free(qry);
+ } else
+ ctx.qry.raw = ctx.qry.url;
+ cgit_parse_url(ctx.qry.url);
+ }
+
ttl = calc_ttl();
ctx.page.expires += ttl*60;
if (ctx.cfg.nocache)
err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
ctx.qry.raw, ttl, process_request, &ctx);
if (err)
- cache_log("[cgit] error %d - %s\n",
- err, strerror(err));
+ cgit_print_error(fmt("Error processing page: %s (%d)",
+ strerror(err), err));
return err;
}