]> git.cameronkatri.com Git - cgit.git/blobdiff - cgit.c
ui-ssdiff.c: set correct diffmode in "control panel"
[cgit.git] / cgit.c
diff --git a/cgit.c b/cgit.c
index e0c2d9fb45e252d107853d03317c99c4b08d83ae..1d50129498ae63a458a69cbc5d3ee4a0365c0ae9 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -26,18 +26,33 @@ void add_mimetype(const char *name, const char *value)
        item->util = xstrdup(value);
 }
 
-struct cgit_filter *new_filter(const char *cmd, int extra_args)
+struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
 {
        struct cgit_filter *f;
+       int args_size = 0;
+       int extra_args;
 
        if (!cmd || !cmd[0])
                return NULL;
 
+       switch (filtertype) {
+               case SOURCE:
+                       extra_args = 1;
+                       break;
+
+               case ABOUT:
+               case COMMIT:
+               default:
+                       extra_args = 0;
+                       break;
+       }
+
        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 +72,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,15 +88,19 @@ 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);
+                       repo->about_filter = new_filter(value, ABOUT);
                else if (!strcmp(name, "commit-filter"))
-                       repo->commit_filter = new_filter(value, 0);
+                       repo->commit_filter = new_filter(value, COMMIT);
                else if (!strcmp(name, "source-filter"))
-                       repo->source_filter = new_filter(value, 1);
+                       repo->source_filter = new_filter(value, SOURCE);
        }
 }
 
@@ -143,6 +164,8 @@ void config_cb(const char *name, const char *value)
                ctx.cfg.enable_http_clone = 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"))
@@ -170,9 +193,9 @@ void config_cb(const char *name, const char *value)
        else if (!strcmp(name, "cache-dynamic-ttl"))
                ctx.cfg.cache_dynamic_ttl = atoi(value);
        else if (!strcmp(name, "about-filter"))
-               ctx.cfg.about_filter = new_filter(value, 0);
+               ctx.cfg.about_filter = new_filter(value, ABOUT);
        else if (!strcmp(name, "commit-filter"))
-               ctx.cfg.commit_filter = new_filter(value, 0);
+               ctx.cfg.commit_filter = new_filter(value, COMMIT);
        else if (!strcmp(name, "embedded"))
                ctx.cfg.embedded = atoi(value);
        else if (!strcmp(name, "max-atom-items"))
@@ -197,10 +220,12 @@ 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);
+               ctx.cfg.source_filter = new_filter(value, SOURCE);
        else if (!strcmp(name, "summary-log"))
                ctx.cfg.summary_log = atoi(value);
        else if (!strcmp(name, "summary-branches"))
@@ -219,6 +244,8 @@ void config_cb(const char *name, const char *value)
                ctx.cfg.robots = xstrdup(value);
        else if (!strcmp(name, "clone-prefix"))
                ctx.cfg.clone_prefix = xstrdup(value);
+       else if (!strcmp(name, "clone-url"))
+               ctx.cfg.clone_url = xstrdup(value);
        else if (!strcmp(name, "local-time"))
                ctx.cfg.local_time = atoi(value);
        else if (!prefixcmp(name, "mimetype."))
@@ -271,6 +298,7 @@ static void querystring_cb(const char *name, const char *value)
                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")) {
@@ -318,6 +346,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;
@@ -393,13 +422,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);
@@ -437,6 +470,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
                cgit_print_docend();
                return 1;
        }
+       cgit_prepare_repo_env(ctx->repo);
        return 0;
 }
 
@@ -550,6 +584,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",
@@ -749,10 +785,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