]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
Add "snapshot-prefix" repo configuration
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index 1dae4b8c39cf9e915f1375400c74ae392d1515e8..d2f7b9c7bbb4f30e0c2ee813c79b50466e1a5d3e 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -79,6 +79,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
                item->util = xstrdup(value);
        } else if (!strcmp(name, "section"))
                repo->section = xstrdup(value);
+       else if (!strcmp(name, "snapshot-prefix"))
+               repo->snapshot_prefix = xstrdup(value);
        else if (!strcmp(name, "readme") && value != NULL) {
                if (repo->readme.items == ctx.cfg.readme.items)
                        memset(&repo->readme, 0, sizeof(repo->readme));
@@ -167,6 +169,8 @@ static void config_cb(const char *name, const char *value)
                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-blame"))
+               ctx.cfg.enable_blame = atoi(value);
        else if (!strcmp(name, "enable-commit-graph"))
                ctx.cfg.enable_commit_graph = atoi(value);
        else if (!strcmp(name, "enable-log-filecount"))
@@ -476,7 +480,7 @@ static char *guess_defbranch(void)
        const char *ref, *refname;
        struct object_id oid;
 
-       ref = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL);
+       ref = resolve_ref_unsafe("HEAD", 0, &oid, NULL);
        if (!ref || !skip_prefix(ref, "refs/heads/", &refname))
                return "master";
        return xstrdup(refname);
@@ -559,12 +563,8 @@ static void print_no_repo_clone_urls(const char *url)
         html("</a></td></tr>\n");
 }
 
-static int prepare_repo_cmd(void)
+static void prepare_repo_env(int *nongit)
 {
-       struct object_id oid;
-       int nongit = 0;
-       int rc;
-
        /* The path to the git repository. */
        setenv("GIT_DIR", ctx.repo->path, 1);
 
@@ -577,8 +577,13 @@ static int prepare_repo_cmd(void)
        /* 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);
+       setup_git_directory_gently(nongit);
        init_display_notes(NULL);
+}
+static int prepare_repo_cmd(int nongit)
+{
+       struct object_id oid;
+       int rc;
 
        if (nongit) {
                const char *name = ctx.repo->name;
@@ -698,6 +703,7 @@ static inline void authenticate_cookie(void)
 static void process_request(void)
 {
        struct cgit_cmd *cmd;
+       int nongit = 0;
 
        /* If we're not yet authenticated, no matter what page we're on,
         * display the authentication body from the auth_filter. This should
@@ -713,6 +719,9 @@ static void process_request(void)
                return;
        }
 
+       if (ctx.repo)
+               prepare_repo_env(&nongit);
+
        cmd = cgit_get_cmd();
        if (!cmd) {
                ctx.page.title = "cgit error";
@@ -738,7 +747,7 @@ static void process_request(void)
         */
        ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
 
-       if (ctx.repo && prepare_repo_cmd())
+       if (ctx.repo && prepare_repo_cmd(nongit))
                return;
 
        cmd->fn();