]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
git: update to v2.40.0
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index fda0aa4b5ff87fa95690f95698406c661ba8f63f..57d70974c50fbd0ade407d8fd46b0ee480d046b1 100644 (file)
--- a/cgit.c
+++ b/cgit.c
 
 const char *cgit_version = CGIT_VERSION;
 
+__attribute__((constructor))
+static void constructor_environment()
+{
+       /* Do not look in /etc/ for gitconfig and gitattributes. */
+       setenv("GIT_CONFIG_NOSYSTEM", "1", 1);
+       setenv("GIT_ATTR_NOSYSTEM", "1", 1);
+       unsetenv("HOME");
+       unsetenv("XDG_CONFIG_HOME");
+}
+
 static void add_mimetype(const char *name, const char *value)
 {
        struct string_list_item *item;
@@ -50,6 +60,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
                repo->extra_head_content = xstrdup(value);
        else if (!strcmp(name, "snapshots"))
                repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
+       else if (!strcmp(name, "enable-blame"))
+               repo->enable_blame = atoi(value);
        else if (!strcmp(name, "enable-commit-graph"))
                repo->enable_commit_graph = atoi(value);
        else if (!strcmp(name, "enable-log-filecount"))
@@ -130,7 +142,9 @@ static void config_cb(const char *name, const char *value)
        else if (!strcmp(name, "root-readme"))
                ctx.cfg.root_readme = xstrdup(value);
        else if (!strcmp(name, "css"))
-               ctx.cfg.css = xstrdup(value);
+               string_list_append(&ctx.cfg.css, xstrdup(value));
+       else if (!strcmp(name, "js"))
+               string_list_append(&ctx.cfg.js, xstrdup(value));
        else if (!strcmp(name, "favicon"))
                ctx.cfg.favicon = xstrdup(value);
        else if (!strcmp(name, "footer"))
@@ -225,9 +239,11 @@ static void config_cb(const char *name, const char *value)
                ctx.cfg.max_repodesc_len = atoi(value);
        else if (!strcmp(name, "max-blob-size"))
                ctx.cfg.max_blob_size = atoi(value);
-       else if (!strcmp(name, "max-repo-count"))
+       else if (!strcmp(name, "max-repo-count")) {
                ctx.cfg.max_repo_count = atoi(value);
-       else if (!strcmp(name, "max-commit-count"))
+               if (ctx.cfg.max_repo_count <= 0)
+                       ctx.cfg.max_repo_count = INT_MAX;
+       } else if (!strcmp(name, "max-commit-count"))
                ctx.cfg.max_commit_count = atoi(value);
        else if (!strcmp(name, "project-list"))
                ctx.cfg.project_list = xstrdup(expand_macros(value));
@@ -312,11 +328,11 @@ static void querystring_cb(const char *name, const char *value)
                ctx.qry.head = xstrdup(value);
                ctx.qry.has_symref = 1;
        } else if (!strcmp(name, "id")) {
-               ctx.qry.sha1 = xstrdup(value);
-               ctx.qry.has_sha1 = 1;
+               ctx.qry.oid = xstrdup(value);
+               ctx.qry.has_oid = 1;
        } else if (!strcmp(name, "id2")) {
-               ctx.qry.sha2 = xstrdup(value);
-               ctx.qry.has_sha1 = 1;
+               ctx.qry.oid2 = xstrdup(value);
+               ctx.qry.has_oid = 1;
        } else if (!strcmp(name, "ofs")) {
                ctx.qry.ofs = atoi(value);
        } else if (!strcmp(name, "path")) {
@@ -364,7 +380,6 @@ static void prepare_context(void)
        ctx.cfg.case_sensitive_sort = 1;
        ctx.cfg.branch_sort = 0;
        ctx.cfg.commit_sort = 0;
-       ctx.cfg.css = "/cgit.css";
        ctx.cfg.logo = "/cgit.png";
        ctx.cfg.favicon = "/favicon.ico";
        ctx.cfg.local_time = 0;
@@ -416,7 +431,7 @@ static void prepare_context(void)
        ctx.page.modified = time(NULL);
        ctx.page.expires = ctx.page.modified;
        ctx.page.etag = NULL;
-       string_list_init(&ctx.cfg.mimetypes, 1);
+       string_list_init_dup(&ctx.cfg.mimetypes);
        if (ctx.env.script_name)
                ctx.cfg.script_name = xstrdup(ctx.env.script_name);
        if (ctx.env.query_string)
@@ -495,9 +510,11 @@ static inline void parse_readme(const char *readme, char **filename, char **ref,
        /* Check if the readme is tracked in the git repo. */
        colon = strchr(readme, ':');
        if (colon && strlen(colon) > 1) {
-               /* If it starts with a colon, we want to use
-                * the default branch */
-               if (colon == readme && repo->defbranch)
+               /* If it starts with a colon, we want to use head given
+                * from query or the default branch */
+               if (colon == readme && ctx.qry.head)
+                       *ref = xstrdup(ctx.qry.head);
+               else if (colon == readme && repo->defbranch)
                        *ref = xstrdup(repo->defbranch);
                else
                        *ref = xstrndup(readme, colon - readme);
@@ -563,18 +580,13 @@ static void prepare_repo_env(int *nongit)
        /* The path to the git repository. */
        setenv("GIT_DIR", ctx.repo->path, 1);
 
-       /* Do not look in /etc/ for gitconfig and gitattributes. */
-       setenv("GIT_CONFIG_NOSYSTEM", "1", 1);
-       setenv("GIT_ATTR_NOSYSTEM", "1", 1);
-       unsetenv("HOME");
-       unsetenv("XDG_CONFIG_HOME");
-
        /* Setup the git directory and initialize the notes system. Both of these
         * load local configuration from the git repository, so we do them both while
         * the HOME variables are unset. */
        setup_git_directory_gently(nongit);
-       init_display_notes(NULL);
+       load_display_notes(NULL);
 }
+
 static int prepare_repo_cmd(int nongit)
 {
        struct object_id oid;
@@ -645,7 +657,7 @@ static inline void open_auth_filter(const char *function)
                ctx.env.https ? ctx.env.https : "",
                ctx.qry.repo ? ctx.qry.repo : "",
                ctx.qry.page ? ctx.qry.page : "",
-               ctx.qry.url ? ctx.qry.url : "",
+               cgit_currentfullurl(),
                cgit_loginurl());
 }
 
@@ -809,6 +821,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
                fprintf(f, "repo.homepage=%s\n", repo->homepage);
        if (repo->clone_url)
                fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
+       fprintf(f, "repo.enable-blame=%d\n",
+               repo->enable_blame);
        fprintf(f, "repo.enable-commit-graph=%d\n",
                repo->enable_commit_graph);
        fprintf(f, "repo.enable-log-filecount=%d\n",
@@ -830,6 +844,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
                fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
                free(tmp);
        }
+       if (repo->snapshot_prefix)
+               fprintf(f, "repo.snapshot-prefix=%s\n", repo->snapshot_prefix);
        if (repo->max_stats != ctx.cfg.max_stats)
                fprintf(f, "repo.max-stats=%s\n",
                        cgit_find_stats_periodname(repo->max_stats));
@@ -981,9 +997,9 @@ static void cgit_parse_args(int argc, const char **argv)
                } else if (skip_prefix(argv[i], "--head=", &arg)) {
                        ctx.qry.head = xstrdup(arg);
                        ctx.qry.has_symref = 1;
-               } else if (skip_prefix(argv[i], "--sha1=", &arg)) {
-                       ctx.qry.sha1 = xstrdup(arg);
-                       ctx.qry.has_sha1 = 1;
+               } else if (skip_prefix(argv[i], "--oid=", &arg)) {
+                       ctx.qry.oid = xstrdup(arg);
+                       ctx.qry.has_oid = 1;
                } else if (skip_prefix(argv[i], "--ofs=", &arg)) {
                        ctx.qry.ofs = atoi(arg);
                } else if (skip_prefix(argv[i], "--scan-tree=", &arg) ||
@@ -1026,7 +1042,7 @@ static int calc_ttl(void)
        if (!strcmp(ctx.qry.page, "snapshot"))
                return ctx.cfg.cache_snapshot_ttl;
 
-       if (ctx.qry.has_sha1)
+       if (ctx.qry.has_oid)
                return ctx.cfg.cache_static_ttl;
 
        if (ctx.qry.has_symref)