]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
ui-plain.c: Use a context structure in walk_tree()
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index 35f0da13da2218efff32168b799bcab9e5e68ca3..ade85ea0976640c49ce71e8a718e5f5c2d7978ac 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -84,7 +84,12 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
                repo->enable_remote_branches = atoi(value);
        else if (!strcmp(name, "enable-subject-links"))
                repo->enable_subject_links = atoi(value);
-       else if (!strcmp(name, "max-stats"))
+       else if (!strcmp(name, "commit-sort")) {
+               if (!strcmp(value, "date"))
+                       repo->commit_sort = 1;
+               if (!strcmp(value, "topo"))
+                       repo->commit_sort = 2;
+       } else if (!strcmp(name, "max-stats"))
                repo->max_stats = cgit_find_stats_period(value, NULL);
        else if (!strcmp(name, "module-link"))
                repo->module_link= xstrdup(value);
@@ -167,6 +172,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-index-owner"))
+               ctx.cfg.enable_index_owner = atoi(value);
        else if (!strcmp(name, "enable-commit-graph"))
                ctx.cfg.enable_commit_graph = atoi(value);
        else if (!strcmp(name, "enable-log-filecount"))
@@ -261,7 +268,12 @@ void config_cb(const char *name, const char *value)
                ctx.cfg.clone_url = xstrdup(value);
        else if (!strcmp(name, "local-time"))
                ctx.cfg.local_time = atoi(value);
-       else if (!prefixcmp(name, "mimetype."))
+       else if (!strcmp(name, "commit-sort")) {
+               if (!strcmp(value, "date"))
+                       ctx.cfg.commit_sort = 1;
+               if (!strcmp(value, "topo"))
+                       ctx.cfg.commit_sort = 2;
+       } else if (!prefixcmp(name, "mimetype."))
                add_mimetype(name + 9, value);
        else if (!strcmp(name, "include"))
                parse_configfile(expand_macros(value), config_cb);
@@ -303,7 +315,7 @@ static void querystring_cb(const char *name, const char *value)
                ctx.qry.name = xstrdup(value);
        } else if (!strcmp(name, "mimetype")) {
                ctx.qry.mimetype = xstrdup(value);
-       } else if (!strcmp(name, "s")){
+       } else if (!strcmp(name, "s")) {
                ctx.qry.sort = xstrdup(value);
        } else if (!strcmp(name, "showmsg")) {
                ctx.qry.showmsg = atoi(value);
@@ -344,6 +356,7 @@ static void prepare_context(struct cgit_context *ctx)
        ctx->cfg.logo = "/cgit.png";
        ctx->cfg.local_time = 0;
        ctx->cfg.enable_http_clone = 1;
+       ctx->cfg.enable_index_owner = 1;
        ctx->cfg.enable_tree_linenumbers = 1;
        ctx->cfg.enable_git_config = 0;
        ctx->cfg.max_repo_count = 50;
@@ -437,7 +450,7 @@ static char *guess_defbranch(const char *repo_path)
        const char *ref;
        unsigned char sha1[20];
 
-       ref = resolve_ref("HEAD", sha1, 0, NULL);
+       ref = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
        if (!ref || prefixcmp(ref, "refs/heads/"))
                return "master";
        return xstrdup(ref + 11);
@@ -640,7 +653,7 @@ void print_repolist(FILE *f, struct cgit_repolist *list, int start)
 {
        int i;
 
-       for(i = start; i < list->count; i++)
+       for (i = start; i < list->count; i++)
                print_repo(f, &list->repos[i]);
 }
 
@@ -728,7 +741,7 @@ static void cgit_parse_args(int argc, const char **argv)
 
        for (i = 1; i < argc; i++) {
                if (!strncmp(argv[i], "--cache=", 8)) {
-                       ctx.cfg.cache_root = xstrdup(argv[i]+8);
+                       ctx.cfg.cache_root = xstrdup(argv[i] + 8);
                }
                if (!strcmp(argv[i], "--nocache")) {
                        ctx.cfg.nocache = 1;
@@ -737,24 +750,24 @@ static void cgit_parse_args(int argc, const char **argv)
                        ctx.env.no_http = "1";
                }
                if (!strncmp(argv[i], "--query=", 8)) {
-                       ctx.qry.raw = xstrdup(argv[i]+8);
+                       ctx.qry.raw = xstrdup(argv[i] + 8);
                }
                if (!strncmp(argv[i], "--repo=", 7)) {
-                       ctx.qry.repo = xstrdup(argv[i]+7);
+                       ctx.qry.repo = xstrdup(argv[i] + 7);
                }
                if (!strncmp(argv[i], "--page=", 7)) {
-                       ctx.qry.page = xstrdup(argv[i]+7);
+                       ctx.qry.page = xstrdup(argv[i] + 7);
                }
                if (!strncmp(argv[i], "--head=", 7)) {
-                       ctx.qry.head = xstrdup(argv[i]+7);
+                       ctx.qry.head = xstrdup(argv[i] + 7);
                        ctx.qry.has_symref = 1;
                }
                if (!strncmp(argv[i], "--sha1=", 7)) {
-                       ctx.qry.sha1 = xstrdup(argv[i]+7);
+                       ctx.qry.sha1 = xstrdup(argv[i] + 7);
                        ctx.qry.has_sha1 = 1;
                }
                if (!strncmp(argv[i], "--ofs=", 6)) {
-                       ctx.qry.ofs = atoi(argv[i]+6);
+                       ctx.qry.ofs = atoi(argv[i] + 6);
                }
                if (!strncmp(argv[i], "--scan-tree=", 12) ||
                    !strncmp(argv[i], "--scan-path=", 12)) {
@@ -821,7 +834,7 @@ int main(int argc, const char **argv)
                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
@@ -843,7 +856,7 @@ int main(int argc, const char **argv)
        }
 
        ttl = calc_ttl();
-       ctx.page.expires += ttl*60;
+       ctx.page.expires += ttl * 60;
        if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
                ctx.cfg.nocache = 1;
        if (ctx.cfg.nocache)