]> git.cameronkatri.com Git - cgit.git/blobdiff - cgit.c
Add sort parameter to pager of repo list
[cgit.git] / cgit.c
diff --git a/cgit.c b/cgit.c
index 04cef23d0d0f27b4a7c9fa663bb9c7e425e23ebf..5259f56fcd9cc09ebf152bcc163fd2801427afa4 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -29,15 +29,17 @@ void add_mimetype(const char *name, const char *value)
 struct cgit_filter *new_filter(const char *cmd, int extra_args)
 {
        struct cgit_filter *f;
+       int args_size = 0;
 
        if (!cmd || !cmd[0])
                return NULL;
 
        f = xmalloc(sizeof(struct cgit_filter));
        f->cmd = xstrdup(cmd);
-       f->argv = xmalloc((2 + extra_args) * sizeof(char *));
+       args_size = (2 + extra_args) * sizeof(char *);
+       f->argv = xmalloc(args_size);
+       memset(f->argv, 0, args_size);
        f->argv[0] = f->cmd;
-       f->argv[1] = NULL;
        return f;
 }
 
@@ -57,6 +59,8 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
                repo->defbranch = xstrdup(value);
        else if (!strcmp(name, "snapshots"))
                repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
+       else if (!strcmp(name, "enable-commit-graph"))
+               repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value);
        else if (!strcmp(name, "enable-log-filecount"))
                repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
        else if (!strcmp(name, "enable-log-linecount"))
@@ -71,9 +75,13 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
                repo->module_link= xstrdup(value);
        else if (!strcmp(name, "section"))
                repo->section = xstrdup(value);
-       else if (!strcmp(name, "readme") && value != NULL) {
+       else if (!strcmp(name, "readme") && value != NULL)
                repo->readme = xstrdup(value);
-       } else if (ctx.cfg.enable_filter_overrides) {
+       else if (!strcmp(name, "logo") && value != NULL)
+               repo->logo = xstrdup(value);
+       else if (!strcmp(name, "logo-link") && value != NULL)
+               repo->logo_link = xstrdup(value);
+       else if (ctx.cfg.enable_filter_overrides) {
                if (!strcmp(name, "about-filter"))
                        repo->about_filter = new_filter(value, 0);
                else if (!strcmp(name, "commit-filter"))
@@ -121,6 +129,8 @@ void config_cb(const char *name, const char *value)
                ctx.cfg.logo_link = xstrdup(value);
        else if (!strcmp(name, "module-link"))
                ctx.cfg.module_link = xstrdup(value);
+       else if (!strcmp(name, "strict-export"))
+               ctx.cfg.strict_export = xstrdup(value);
        else if (!strcmp(name, "virtual-root")) {
                ctx.cfg.virtual_root = trim_end(value, '/');
                if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
@@ -139,6 +149,8 @@ void config_cb(const char *name, const char *value)
                ctx.cfg.enable_gitweb_owner = atoi(value);
        else if (!strcmp(name, "enable-index-links"))
                ctx.cfg.enable_index_links = atoi(value);
+       else if (!strcmp(name, "enable-commit-graph"))
+               ctx.cfg.enable_commit_graph = atoi(value);
        else if (!strcmp(name, "enable-log-filecount"))
                ctx.cfg.enable_log_filecount = atoi(value);
        else if (!strcmp(name, "enable-log-linecount"))
@@ -193,6 +205,10 @@ void config_cb(const char *name, const char *value)
                                      ctx.cfg.project_list, repo_config);
                else
                        scan_tree(expand_macros(value), repo_config);
+       else if (!strcmp(name, "scan-hidden-path"))
+               ctx.cfg.scan_hidden_path = atoi(value);
+       else if (!strcmp(name, "section-from-path"))
+               ctx.cfg.section_from_path = atoi(value);
        else if (!strcmp(name, "source-filter"))
                ctx.cfg.source_filter = new_filter(value, 1);
        else if (!strcmp(name, "summary-log"))
@@ -311,6 +327,7 @@ static void prepare_context(struct cgit_context *ctx)
        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.scan_hidden_path = 0;
        ctx->cfg.script_name = CGIT_SCRIPT_NAME;
        ctx->cfg.section = "";
        ctx->cfg.summary_branches = 10;
@@ -386,13 +403,17 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
        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);
@@ -536,6 +557,8 @@ void print_repo(FILE *f, struct cgit_repo *repo)
                fprintf(f, "repo.section=%s\n", repo->section);
        if (repo->clone_url)
                fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
+       fprintf(f, "repo.enable-commit-graph=%d\n",
+               repo->enable_commit_graph);
        fprintf(f, "repo.enable-log-filecount=%d\n",
                repo->enable_log_filecount);
        fprintf(f, "repo.enable-log-linecount=%d\n",
@@ -608,7 +631,7 @@ static void process_cached_repolist(const char *path)
        hash = hash_str(path);
        if (ctx.cfg.project_list)
                hash += hash_str(ctx.cfg.project_list);
-       cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, hash));
+       cached_rc = xstrdup(fmt("%s/rc-%8lx", ctx.cfg.cache_root, hash));
 
        if (stat(cached_rc, &st)) {
                /* Nothing is cached, we need to scan without forking. And
@@ -735,10 +758,14 @@ int main(int argc, const char **argv)
        http_parse_querystring(ctx.qry.raw, querystring_cb);
 
        /* If virtual-root isn't specified in cgitrc, lets pretend
-        * that virtual-root equals SCRIPT_NAME.
+        * that virtual-root equals SCRIPT_NAME, minus any possibly
+        * trailing slashes.
         */
-       if (!ctx.cfg.virtual_root)
-               ctx.cfg.virtual_root = ctx.cfg.script_name;
+       if (!ctx.cfg.virtual_root && ctx.cfg.script_name) {
+               ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/');
+               if (!ctx.cfg.virtual_root)
+                       ctx.cfg.virtual_root = "";
+        }
 
        /* If no url parameter is specified on the querystring, lets
         * use PATH_INFO as url. This allows cgit to work with virtual