]> git.cameronkatri.com Git - cgit.git/blobdiff - cgit.c
git: update to v2.2.1
[cgit.git] / cgit.c
diff --git a/cgit.c b/cgit.c
index 09fce0c7a49163a902a0e6675d9d8dbd7ee26465..796cb7fa9127ff2c9576e9567bc421fba9e498cb 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -69,7 +69,7 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
                repo->max_stats = cgit_find_stats_period(value, NULL);
        else if (!strcmp(name, "module-link"))
                repo->module_link= xstrdup(value);
-       else if (!prefixcmp(name, "module-link.")) {
+       else if (starts_with(name, "module-link.")) {
                item = string_list_append(&repo->submodules, xstrdup(name + 12));
                item->util = xstrdup(value);
        } else if (!strcmp(name, "section"))
@@ -102,7 +102,7 @@ static void config_cb(const char *name, const char *value)
                ctx.repo = cgit_add_repo(value);
        else if (ctx.repo && !strcmp(name, "repo.path"))
                ctx.repo->path = trim_end(value, '/');
-       else if (ctx.repo && !prefixcmp(name, "repo."))
+       else if (ctx.repo && starts_with(name, "repo."))
                repo_config(ctx.repo, name + 5, value);
        else if (!strcmp(name, "readme") && value != NULL)
                string_list_append(&ctx.cfg.readme, xstrdup(value));
@@ -184,6 +184,8 @@ static void config_cb(const char *name, const char *value)
                ctx.cfg.cache_dynamic_ttl = atoi(value);
        else if (!strcmp(name, "cache-about-ttl"))
                ctx.cfg.cache_about_ttl = atoi(value);
+       else if (!strcmp(name, "cache-snapshot-ttl"))
+               ctx.cfg.cache_snapshot_ttl = atoi(value);
        else if (!strcmp(name, "case-sensitive-sort"))
                ctx.cfg.case_sensitive_sort = atoi(value);
        else if (!strcmp(name, "about-filter"))
@@ -235,7 +237,7 @@ static void config_cb(const char *name, const char *value)
        else if (!strcmp(name, "summary-tags"))
                ctx.cfg.summary_tags = atoi(value);
        else if (!strcmp(name, "side-by-side-diffs"))
-               ctx.cfg.ssdiff = atoi(value);
+               ctx.cfg.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED;
        else if (!strcmp(name, "agefile"))
                ctx.cfg.agefile = xstrdup(value);
        else if (!strcmp(name, "mimetype-file"))
@@ -262,7 +264,7 @@ static void config_cb(const char *name, const char *value)
                        ctx.cfg.branch_sort = 1;
                if (!strcmp(value, "name"))
                        ctx.cfg.branch_sort = 0;
-       } else if (!prefixcmp(name, "mimetype."))
+       } else if (starts_with(name, "mimetype."))
                add_mimetype(name + 9, value);
        else if (!strcmp(name, "include"))
                parse_configfile(expand_macros(value), config_cb);
@@ -310,9 +312,13 @@ static void querystring_cb(const char *name, const char *value)
                ctx.qry.showmsg = atoi(value);
        } else if (!strcmp(name, "period")) {
                ctx.qry.period = xstrdup(value);
+       } else if (!strcmp(name, "dt")) {
+               ctx.qry.difftype = atoi(value);
+               ctx.qry.has_difftype = 1;
        } else if (!strcmp(name, "ss")) {
-               ctx.qry.ssdiff = atoi(value);
-               ctx.qry.has_ssdiff = 1;
+               /* No longer generated, but there may be links out there. */
+               ctx.qry.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED;
+               ctx.qry.has_difftype = 1;
        } else if (!strcmp(name, "all")) {
                ctx.qry.show_all = atoi(value);
        } else if (!strcmp(name, "context")) {
@@ -331,6 +337,7 @@ static void prepare_context(void)
        ctx.cfg.cache_max_create_time = 5;
        ctx.cfg.cache_root = CGIT_CACHE_ROOT;
        ctx.cfg.cache_about_ttl = 15;
+       ctx.cfg.cache_snapshot_ttl = 5;
        ctx.cfg.cache_repo_ttl = 5;
        ctx.cfg.cache_root_ttl = 5;
        ctx.cfg.cache_scanrc_ttl = 15;
@@ -369,7 +376,7 @@ static void prepare_context(void)
        ctx.cfg.summary_log = 10;
        ctx.cfg.summary_tags = 10;
        ctx.cfg.max_atom_items = 10;
-       ctx.cfg.ssdiff = 0;
+       ctx.cfg.difftype = DIFF_UNIFIED;
        ctx.env.cgit_config = getenv("CGIT_CONFIG");
        ctx.env.http_host = getenv("HTTP_HOST");
        ctx.env.https = getenv("HTTPS");
@@ -450,8 +457,8 @@ static char *guess_defbranch(void)
        const char *ref;
        unsigned char sha1[20];
 
-       ref = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
-       if (!ref || prefixcmp(ref, "refs/heads/"))
+       ref = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
+       if (!ref || !starts_with(ref, "refs/heads/"))
                return "master";
        return xstrdup(ref + 11);
 }
@@ -501,12 +508,6 @@ static void choose_readme(struct cgit_repo *repo)
                        free(ref);
                        continue;
                }
-               /* If there's only one item, we skip the possibly expensive
-                * selection process. */
-               if (repo->readme.nr == 1) {
-                       found = 1;
-                       break;
-               }
                if (ref) {
                        if (cgit_ref_path_exists(filename, ref, 1)) {
                                found = 1;
@@ -921,28 +922,45 @@ static void cgit_parse_args(int argc, const char **argv)
        int scan = 0;
 
        for (i = 1; i < argc; i++) {
-               if (!prefixcmp(argv[i], "--cache=")) {
+               if (!strcmp(argv[i], "--version")) {
+                       printf("CGit %s | http://git.zx2c4.com/cgit/\n\nCompiled in features:\n", CGIT_VERSION);
+#ifdef NO_LUA
+                       printf("[-] ");
+#else
+                       printf("[+] ");
+#endif
+                       printf("Lua scripting\n");
+#ifndef HAVE_LINUX_SENDFILE
+                       printf("[-] ");
+#else
+                       printf("[+] ");
+#endif
+                       printf("Linux sendfile() usage\n");
+
+                       exit(0);
+               }
+               if (starts_with(argv[i], "--cache=")) {
                        ctx.cfg.cache_root = xstrdup(argv[i] + 8);
                } else if (!strcmp(argv[i], "--nocache")) {
                        ctx.cfg.nocache = 1;
                } else if (!strcmp(argv[i], "--nohttp")) {
                        ctx.env.no_http = "1";
-               } else if (!prefixcmp(argv[i], "--query=")) {
+               } else if (starts_with(argv[i], "--query=")) {
                        ctx.qry.raw = xstrdup(argv[i] + 8);
-               } else if (!prefixcmp(argv[i], "--repo=")) {
+               } else if (starts_with(argv[i], "--repo=")) {
                        ctx.qry.repo = xstrdup(argv[i] + 7);
-               } else if (!prefixcmp(argv[i], "--page=")) {
+               } else if (starts_with(argv[i], "--page=")) {
                        ctx.qry.page = xstrdup(argv[i] + 7);
-               } else if (!prefixcmp(argv[i], "--head=")) {
+               } else if (starts_with(argv[i], "--head=")) {
                        ctx.qry.head = xstrdup(argv[i] + 7);
                        ctx.qry.has_symref = 1;
-               } else if (!prefixcmp(argv[i], "--sha1=")) {
+               } else if (starts_with(argv[i], "--sha1=")) {
                        ctx.qry.sha1 = xstrdup(argv[i] + 7);
                        ctx.qry.has_sha1 = 1;
-               } else if (!prefixcmp(argv[i], "--ofs=")) {
+               } else if (starts_with(argv[i], "--ofs=")) {
                        ctx.qry.ofs = atoi(argv[i] + 6);
-               } else if (!prefixcmp(argv[i], "--scan-tree=") ||
-                          !prefixcmp(argv[i], "--scan-path=")) {
+               } else if (starts_with(argv[i], "--scan-tree=") ||
+                          starts_with(argv[i], "--scan-path=")) {
                        /*
                         * HACK: The global snapshot bit mask defines the set
                         * of allowed snapshot formats, but the config file
@@ -978,6 +996,9 @@ static int calc_ttl()
        if (!strcmp(ctx.qry.page, "about"))
                return ctx.cfg.cache_about_ttl;
 
+       if (!strcmp(ctx.qry.page, "snapshot"))
+               return ctx.cfg.cache_snapshot_ttl;
+
        if (ctx.qry.has_sha1)
                return ctx.cfg.cache_static_ttl;