]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
log: allow users to follow a file
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index 8c4517d8e70554e02ac3cdaf8a246f2dad9dbfe0..d84b4be370bb17136430ffe40b2aa1e7eb677232 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -82,6 +82,10 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
                repo->logo = xstrdup(value);
        else if (!strcmp(name, "logo-link") && value != NULL)
                repo->logo_link = xstrdup(value);
                repo->logo = xstrdup(value);
        else if (!strcmp(name, "logo-link") && value != NULL)
                repo->logo_link = xstrdup(value);
+       else if (!strcmp(name, "hide"))
+               repo->hide = atoi(value);
+       else if (!strcmp(name, "ignore"))
+               repo->ignore = atoi(value);
        else if (ctx.cfg.enable_filter_overrides) {
                if (!strcmp(name, "about-filter"))
                        repo->about_filter = cgit_new_filter(value, ABOUT);
        else if (ctx.cfg.enable_filter_overrides) {
                if (!strcmp(name, "about-filter"))
                        repo->about_filter = cgit_new_filter(value, ABOUT);
@@ -91,6 +95,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
                        repo->source_filter = cgit_new_filter(value, SOURCE);
                else if (!strcmp(name, "email-filter"))
                        repo->email_filter = cgit_new_filter(value, EMAIL);
                        repo->source_filter = cgit_new_filter(value, SOURCE);
                else if (!strcmp(name, "email-filter"))
                        repo->email_filter = cgit_new_filter(value, EMAIL);
+               else if (!strcmp(name, "owner-filter"))
+                       repo->owner_filter = cgit_new_filter(value, OWNER);
        }
 }
 
        }
 }
 
@@ -146,6 +152,8 @@ static void config_cb(const char *name, const char *value)
                ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
        else if (!strcmp(name, "enable-filter-overrides"))
                ctx.cfg.enable_filter_overrides = atoi(value);
                ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
        else if (!strcmp(name, "enable-filter-overrides"))
                ctx.cfg.enable_filter_overrides = atoi(value);
+       else if (!strcmp(name, "enable-follow-links"))
+               ctx.cfg.enable_follow_links = atoi(value);
        else if (!strcmp(name, "enable-http-clone"))
                ctx.cfg.enable_http_clone = atoi(value);
        else if (!strcmp(name, "enable-index-links"))
        else if (!strcmp(name, "enable-http-clone"))
                ctx.cfg.enable_http_clone = atoi(value);
        else if (!strcmp(name, "enable-index-links"))
@@ -194,6 +202,8 @@ static void config_cb(const char *name, const char *value)
                ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
        else if (!strcmp(name, "email-filter"))
                ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
                ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
        else if (!strcmp(name, "email-filter"))
                ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
+       else if (!strcmp(name, "owner-filter"))
+               ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
        else if (!strcmp(name, "auth-filter"))
                ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
        else if (!strcmp(name, "embedded"))
        else if (!strcmp(name, "auth-filter"))
                ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
        else if (!strcmp(name, "embedded"))
@@ -237,7 +247,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"))
        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"))
        else if (!strcmp(name, "agefile"))
                ctx.cfg.agefile = xstrdup(value);
        else if (!strcmp(name, "mimetype-file"))
@@ -312,15 +322,21 @@ 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);
                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")) {
        } 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")) {
                ctx.qry.context = atoi(value);
        } else if (!strcmp(name, "ignorews")) {
                ctx.qry.ignorews = atoi(value);
        } else if (!strcmp(name, "all")) {
                ctx.qry.show_all = atoi(value);
        } else if (!strcmp(name, "context")) {
                ctx.qry.context = atoi(value);
        } else if (!strcmp(name, "ignorews")) {
                ctx.qry.ignorews = atoi(value);
+       } else if (!strcmp(name, "follow")) {
+               ctx.qry.follow = atoi(value);
        }
 }
 
        }
 }
 
@@ -372,7 +388,7 @@ static void prepare_context(void)
        ctx.cfg.summary_log = 10;
        ctx.cfg.summary_tags = 10;
        ctx.cfg.max_atom_items = 10;
        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");
        ctx.env.cgit_config = getenv("CGIT_CONFIG");
        ctx.env.http_host = getenv("HTTP_HOST");
        ctx.env.https = getenv("HTTPS");
@@ -409,7 +425,7 @@ struct refmatch {
        int match;
 };
 
        int match;
 };
 
-static int find_current_ref(const char *refname, const unsigned char *sha1,
+static int find_current_ref(const char *refname, const struct object_id *oid,
                            int flags, void *cb_data)
 {
        struct refmatch *info;
                            int flags, void *cb_data)
 {
        struct refmatch *info;
@@ -453,7 +469,7 @@ static char *guess_defbranch(void)
        const char *ref;
        unsigned char sha1[20];
 
        const char *ref;
        unsigned char sha1[20];
 
-       ref = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
+       ref = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
        if (!ref || !starts_with(ref, "refs/heads/"))
                return "master";
        return xstrdup(ref + 11);
        if (!ref || !starts_with(ref, "refs/heads/"))
                return "master";
        return xstrdup(ref + 11);
@@ -524,6 +540,17 @@ static void choose_readme(struct cgit_repo *repo)
                string_list_append(&repo->readme, filename)->util = ref;
 }
 
                string_list_append(&repo->readme, filename)->util = ref;
 }
 
+static void print_no_repo_clone_urls(const char *url)
+{
+        html("<tr><td><a rel='vcs-git' href='");
+        html_url_path(url);
+        html("' title='");
+        html_attr(ctx.repo->name);
+        html(" Git repository'>");
+        html_txt(url);
+        html("</a></td></tr>\n");
+}
+
 static int prepare_repo_cmd(void)
 {
        unsigned char sha1[20];
 static int prepare_repo_cmd(void)
 {
        unsigned char sha1[20];
@@ -574,6 +601,12 @@ static int prepare_repo_cmd(void)
                cgit_print_docstart();
                cgit_print_pageheader();
                cgit_print_error("Repository seems to be empty");
                cgit_print_docstart();
                cgit_print_pageheader();
                cgit_print_error("Repository seems to be empty");
+               if (!strcmp(ctx.qry.page, "summary")) {
+                       html("<table class='list'><tr class='nohover'><td>&nbsp;</td></tr><tr class='nohover'><th class='left'>Clone</th></tr>\n");
+                       cgit_prepare_repo_env(ctx.repo);
+                       cgit_add_clone_urls(print_no_repo_clone_urls);
+                       html("</table>\n");
+               }
                cgit_print_docend();
                return 1;
        }
                cgit_print_docend();
                return 1;
        }
@@ -591,7 +624,7 @@ static int prepare_repo_cmd(void)
                free(tmp);
                return 1;
        }
                free(tmp);
                return 1;
        }
-       sort_string_list(&ctx.repo->submodules);
+       string_list_sort(&ctx.repo->submodules);
        cgit_prepare_repo_env(ctx.repo);
        choose_readme(ctx.repo);
        return 0;
        cgit_prepare_repo_env(ctx.repo);
        choose_readme(ctx.repo);
        return 0;
@@ -713,6 +746,9 @@ static void process_request(void)
        if (ctx.repo && prepare_repo_cmd())
                return;
 
        if (ctx.repo && prepare_repo_cmd())
                return;
 
+       if (cmd->pre)
+               cmd->pre();
+
        if (cmd->want_layout) {
                cgit_print_http_headers();
                cgit_print_docstart();
        if (cmd->want_layout) {
                cgit_print_http_headers();
                cgit_print_docstart();
@@ -796,6 +832,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
                cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
        if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
                cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
                cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
        if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
                cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
+       if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
+               cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
        if (repo->snapshots != ctx.cfg.snapshots) {
                char *tmp = build_snapshot_setting(repo->snapshots);
                fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
        if (repo->snapshots != ctx.cfg.snapshots) {
                char *tmp = build_snapshot_setting(repo->snapshots);
                fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
@@ -818,6 +856,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
                else if (repo->commit_sort == 2)
                        fprintf(f, "repo.commit-sort=topo\n");
        }
                else if (repo->commit_sort == 2)
                        fprintf(f, "repo.commit-sort=topo\n");
        }
+       fprintf(f, "repo.hide=%d\n", repo->hide);
+       fprintf(f, "repo.ignore=%d\n", repo->ignore);
        fprintf(f, "\n");
 }
 
        fprintf(f, "\n");
 }
 
@@ -981,7 +1021,7 @@ static void cgit_parse_args(int argc, const char **argv)
        }
 }
 
        }
 }
 
-static int calc_ttl()
+static int calc_ttl(void)
 {
        if (!ctx.repo)
                return ctx.cfg.cache_root_ttl;
 {
        if (!ctx.repo)
                return ctx.cfg.cache_root_ttl;