]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
doc: use consistent id's when generating html files
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index 1075753e15b4de5672aa8445fcc86ef4e7079a92..bd9cb3fb11a66383d56256b2c0426e0070e7208c 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -167,6 +167,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);
                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"))
        else if (!strcmp(name, "enable-commit-graph"))
                ctx.cfg.enable_commit_graph = atoi(value);
        else if (!strcmp(name, "enable-log-filecount"))
@@ -476,7 +478,7 @@ static char *guess_defbranch(void)
        const char *ref, *refname;
        struct object_id oid;
 
        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);
        if (!ref || !skip_prefix(ref, "refs/heads/", &refname))
                return "master";
        return xstrdup(refname);
@@ -559,12 +561,8 @@ static void print_no_repo_clone_urls(const char *url)
         html("</a></td></tr>\n");
 }
 
         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);
 
        /* The path to the git repository. */
        setenv("GIT_DIR", ctx.repo->path, 1);
 
@@ -577,8 +575,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 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);
        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;
 
        if (nongit) {
                const char *name = ctx.repo->name;
@@ -698,6 +701,7 @@ static inline void authenticate_cookie(void)
 static void process_request(void)
 {
        struct cgit_cmd *cmd;
 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
 
        /* 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 +717,9 @@ static void process_request(void)
                return;
        }
 
                return;
        }
 
+       if (ctx.repo)
+               prepare_repo_env(&nongit);
+
        cmd = cgit_get_cmd();
        if (!cmd) {
                ctx.page.title = "cgit error";
        cmd = cgit_get_cmd();
        if (!cmd) {
                ctx.page.title = "cgit error";
@@ -726,19 +733,19 @@ static void process_request(void)
                return;
        }
 
                return;
        }
 
-       /* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual"
-        * in-project path limit to be made available at ctx.qry.vpath.
-        * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL).
-        */
-       ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
-
        if (cmd->want_repo && !ctx.repo) {
                cgit_print_error_page(400, "Bad request",
                                "No repository selected");
                return;
        }
 
        if (cmd->want_repo && !ctx.repo) {
                cgit_print_error_page(400, "Bad request",
                                "No repository selected");
                return;
        }
 
-       if (ctx.repo && prepare_repo_cmd())
+       /* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual"
+        * in-project path limit to be made available at ctx.qry.vpath.
+        * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL).
+        */
+       ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
+
+       if (ctx.repo && prepare_repo_cmd(nongit))
                return;
 
        cmd->fn();
                return;
 
        cmd->fn();