]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
Bump version.
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index ec8f69c26f13dab83b894c661a35fd9740e92ce1..20f6e279e3be60653d70a3e0966064afcd8c6480 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"))
@@ -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);
@@ -331,6 +333,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;
@@ -451,7 +454,7 @@ static char *guess_defbranch(void)
        unsigned char sha1[20];
 
        ref = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
-       if (!ref || prefixcmp(ref, "refs/heads/"))
+       if (!ref || !starts_with(ref, "refs/heads/"))
                return "master";
        return xstrdup(ref + 11);
 }
@@ -591,6 +594,7 @@ static int prepare_repo_cmd(void)
                cgit_print_pageheader();
                cgit_print_error("Invalid branch: %s", tmp);
                cgit_print_docend();
+               free(tmp);
                return 1;
        }
        sort_string_list(&ctx.repo->submodules);
@@ -920,28 +924,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
@@ -977,6 +998,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;