aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cgit.c50
-rw-r--r--cgit.h7
-rw-r--r--cgitrc.5.txt60
-rw-r--r--cmd.c42
-rw-r--r--cmd.h3
-rwxr-xr-xfilters/commit-links.sh11
-rwxr-xr-xfilters/syntax-highlighting.sh11
-rw-r--r--html.c15
-rw-r--r--parsing.c29
-rw-r--r--scan-tree.c1
-rw-r--r--shared.c51
-rwxr-xr-xtests/setup.sh25
-rwxr-xr-xtests/t0101-index.sh1
-rwxr-xr-xtests/t0103-log.sh10
-rw-r--r--ui-commit.c6
-rw-r--r--ui-diff.c8
-rw-r--r--ui-log.c29
-rw-r--r--ui-repolist.c4
-rw-r--r--ui-snapshot.c2
-rw-r--r--ui-summary.c2
-rw-r--r--ui-tree.c4
21 files changed, 269 insertions, 102 deletions
diff --git a/cgit.c b/cgit.c
index f4dd6ef..6be3754 100644
--- a/cgit.c
+++ b/cgit.c
@@ -26,18 +26,33 @@ void add_mimetype(const char *name, const char *value)
26 item->util = xstrdup(value); 26 item->util = xstrdup(value);
27} 27}
28 28
29struct cgit_filter *new_filter(const char *cmd, int extra_args) 29struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
30{ 30{
31 struct cgit_filter *f; 31 struct cgit_filter *f;
32 int args_size = 0;
33 int extra_args;
32 34
33 if (!cmd || !cmd[0]) 35 if (!cmd || !cmd[0])
34 return NULL; 36 return NULL;
35 37
38 switch (filtertype) {
39 case SOURCE:
40 extra_args = 1;
41 break;
42
43 case ABOUT:
44 case COMMIT:
45 default:
46 extra_args = 0;
47 break;
48 }
49
36 f = xmalloc(sizeof(struct cgit_filter)); 50 f = xmalloc(sizeof(struct cgit_filter));
37 f->cmd = xstrdup(cmd); 51 f->cmd = xstrdup(cmd);
38 f->argv = xmalloc((2 + extra_args) * sizeof(char *)); 52 args_size = (2 + extra_args) * sizeof(char *);
53 f->argv = xmalloc(args_size);
54 memset(f->argv, 0, args_size);
39 f->argv[0] = f->cmd; 55 f->argv[0] = f->cmd;
40 f->argv[1] = NULL;
41 return f; 56 return f;
42} 57}
43 58
@@ -81,11 +96,11 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
81 repo->logo_link = xstrdup(value); 96 repo->logo_link = xstrdup(value);
82 else if (ctx.cfg.enable_filter_overrides) { 97 else if (ctx.cfg.enable_filter_overrides) {
83 if (!strcmp(name, "about-filter")) 98 if (!strcmp(name, "about-filter"))
84 repo->about_filter = new_filter(value, 0); 99 repo->about_filter = new_filter(value, ABOUT);
85 else if (!strcmp(name, "commit-filter")) 100 else if (!strcmp(name, "commit-filter"))
86 repo->commit_filter = new_filter(value, 0); 101 repo->commit_filter = new_filter(value, COMMIT);
87 else if (!strcmp(name, "source-filter")) 102 else if (!strcmp(name, "source-filter"))
88 repo->source_filter = new_filter(value, 1); 103 repo->source_filter = new_filter(value, SOURCE);
89 } 104 }
90} 105}
91 106
@@ -145,6 +160,8 @@ void config_cb(const char *name, const char *value)
145 ctx.cfg.enable_filter_overrides = atoi(value); 160 ctx.cfg.enable_filter_overrides = atoi(value);
146 else if (!strcmp(name, "enable-gitweb-owner")) 161 else if (!strcmp(name, "enable-gitweb-owner"))
147 ctx.cfg.enable_gitweb_owner = atoi(value); 162 ctx.cfg.enable_gitweb_owner = atoi(value);
163 else if (!strcmp(name, "enable-http-clone"))
164 ctx.cfg.enable_http_clone = atoi(value);
148 else if (!strcmp(name, "enable-index-links")) 165 else if (!strcmp(name, "enable-index-links"))
149 ctx.cfg.enable_index_links = atoi(value); 166 ctx.cfg.enable_index_links = atoi(value);
150 else if (!strcmp(name, "enable-commit-graph")) 167 else if (!strcmp(name, "enable-commit-graph"))
@@ -176,9 +193,9 @@ void config_cb(const char *name, const char *value)
176 else if (!strcmp(name, "cache-dynamic-ttl")) 193 else if (!strcmp(name, "cache-dynamic-ttl"))
177 ctx.cfg.cache_dynamic_ttl = atoi(value); 194 ctx.cfg.cache_dynamic_ttl = atoi(value);
178 else if (!strcmp(name, "about-filter")) 195 else if (!strcmp(name, "about-filter"))
179 ctx.cfg.about_filter = new_filter(value, 0); 196 ctx.cfg.about_filter = new_filter(value, ABOUT);
180 else if (!strcmp(name, "commit-filter")) 197 else if (!strcmp(name, "commit-filter"))
181 ctx.cfg.commit_filter = new_filter(value, 0); 198 ctx.cfg.commit_filter = new_filter(value, COMMIT);
182 else if (!strcmp(name, "embedded")) 199 else if (!strcmp(name, "embedded"))
183 ctx.cfg.embedded = atoi(value); 200 ctx.cfg.embedded = atoi(value);
184 else if (!strcmp(name, "max-atom-items")) 201 else if (!strcmp(name, "max-atom-items"))
@@ -208,7 +225,7 @@ void config_cb(const char *name, const char *value)
208 else if (!strcmp(name, "section-from-path")) 225 else if (!strcmp(name, "section-from-path"))
209 ctx.cfg.section_from_path = atoi(value); 226 ctx.cfg.section_from_path = atoi(value);
210 else if (!strcmp(name, "source-filter")) 227 else if (!strcmp(name, "source-filter"))
211 ctx.cfg.source_filter = new_filter(value, 1); 228 ctx.cfg.source_filter = new_filter(value, SOURCE);
212 else if (!strcmp(name, "summary-log")) 229 else if (!strcmp(name, "summary-log"))
213 ctx.cfg.summary_log = atoi(value); 230 ctx.cfg.summary_log = atoi(value);
214 else if (!strcmp(name, "summary-branches")) 231 else if (!strcmp(name, "summary-branches"))
@@ -310,6 +327,7 @@ static void prepare_context(struct cgit_context *ctx)
310 ctx->cfg.logo = "/cgit.png"; 327 ctx->cfg.logo = "/cgit.png";
311 ctx->cfg.local_time = 0; 328 ctx->cfg.local_time = 0;
312 ctx->cfg.enable_gitweb_owner = 1; 329 ctx->cfg.enable_gitweb_owner = 1;
330 ctx->cfg.enable_http_clone = 1;
313 ctx->cfg.enable_tree_linenumbers = 1; 331 ctx->cfg.enable_tree_linenumbers = 1;
314 ctx->cfg.max_repo_count = 50; 332 ctx->cfg.max_repo_count = 50;
315 ctx->cfg.max_commit_count = 50; 333 ctx->cfg.max_commit_count = 50;
@@ -437,7 +455,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
437 tmp = xstrdup(ctx->qry.head); 455 tmp = xstrdup(ctx->qry.head);
438 ctx->qry.head = ctx->repo->defbranch; 456 ctx->qry.head = ctx->repo->defbranch;
439 ctx->page.status = 404; 457 ctx->page.status = 404;
440 ctx->page.statusmsg = "not found"; 458 ctx->page.statusmsg = "Not found";
441 cgit_print_http_headers(ctx); 459 cgit_print_http_headers(ctx);
442 cgit_print_docstart(ctx); 460 cgit_print_docstart(ctx);
443 cgit_print_pageheader(ctx); 461 cgit_print_pageheader(ctx);
@@ -456,6 +474,8 @@ static void process_request(void *cbdata)
456 cmd = cgit_get_cmd(ctx); 474 cmd = cgit_get_cmd(ctx);
457 if (!cmd) { 475 if (!cmd) {
458 ctx->page.title = "cgit error"; 476 ctx->page.title = "cgit error";
477 ctx->page.status = 404;
478 ctx->page.statusmsg = "Not found";
459 cgit_print_http_headers(ctx); 479 cgit_print_http_headers(ctx);
460 cgit_print_docstart(ctx); 480 cgit_print_docstart(ctx);
461 cgit_print_pageheader(ctx); 481 cgit_print_pageheader(ctx);
@@ -464,6 +484,11 @@ static void process_request(void *cbdata)
464 return; 484 return;
465 } 485 }
466 486
487 if (!ctx->cfg.enable_http_clone && cmd->is_clone) {
488 html_status(404, "Not found", 0);
489 return;
490 }
491
467 /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" 492 /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual"
468 * in-project path limit to be made available at ctx->qry.vpath. 493 * in-project path limit to be made available at ctx->qry.vpath.
469 * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). 494 * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL).
@@ -755,8 +780,11 @@ int main(int argc, const char **argv)
755 * that virtual-root equals SCRIPT_NAME, minus any possibly 780 * that virtual-root equals SCRIPT_NAME, minus any possibly
756 * trailing slashes. 781 * trailing slashes.
757 */ 782 */
758 if (!ctx.cfg.virtual_root) 783 if (!ctx.cfg.virtual_root && ctx.cfg.script_name) {
759 ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); 784 ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/');
785 if (!ctx.cfg.virtual_root)
786 ctx.cfg.virtual_root = "";
787 }
760 788
761 /* If no url parameter is specified on the querystring, lets 789 /* If no url parameter is specified on the querystring, lets
762 * use PATH_INFO as url. This allows cgit to work with virtual 790 * use PATH_INFO as url. This allows cgit to work with virtual
diff --git a/cgit.h b/cgit.h
index b5f00fc..caa9d8e 100644
--- a/cgit.h
+++ b/cgit.h
@@ -51,6 +51,10 @@ typedef void (*configfn)(const char *name, const char *value);
51typedef void (*filepair_fn)(struct diff_filepair *pair); 51typedef void (*filepair_fn)(struct diff_filepair *pair);
52typedef void (*linediff_fn)(char *line, int len); 52typedef void (*linediff_fn)(char *line, int len);
53 53
54typedef enum {
55 ABOUT, COMMIT, SOURCE
56} filter_type;
57
54struct cgit_filter { 58struct cgit_filter {
55 char *cmd; 59 char *cmd;
56 char **argv; 60 char **argv;
@@ -191,6 +195,7 @@ struct cgit_config {
191 int embedded; 195 int embedded;
192 int enable_filter_overrides; 196 int enable_filter_overrides;
193 int enable_gitweb_owner; 197 int enable_gitweb_owner;
198 int enable_http_clone;
194 int enable_index_links; 199 int enable_index_links;
195 int enable_commit_graph; 200 int enable_commit_graph;
196 int enable_log_filecount; 201 int enable_log_filecount;
@@ -314,7 +319,7 @@ extern const char *cgit_repobasename(const char *reponame);
314 319
315extern int cgit_parse_snapshots_mask(const char *str); 320extern int cgit_parse_snapshots_mask(const char *str);
316 321
317extern int cgit_open_filter(struct cgit_filter *filter); 322extern int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo);
318extern int cgit_close_filter(struct cgit_filter *filter); 323extern int cgit_close_filter(struct cgit_filter *filter);
319 324
320extern int readfile(const char *path, char **buf, size_t *size); 325extern int readfile(const char *path, char **buf, size_t *size);
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index c3698a6..5903a93 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -31,7 +31,7 @@ about-filter::
31 about pages (both top-level and for each repository). The command will 31 about pages (both top-level and for each repository). The command will
32 get the content of the about-file on its STDIN, and the STDOUT from the 32 get the content of the about-file on its STDIN, and the STDOUT from the
33 command will be included verbatim on the about page. Default value: 33 command will be included verbatim on the about page. Default value:
34 none. 34 none. See also: "FILTER API".
35 35
36agefile:: 36agefile::
37 Specifies a path, relative to each repository path, which can be used 37 Specifies a path, relative to each repository path, which can be used
@@ -81,6 +81,7 @@ commit-filter::
81 The command will get the message on its STDIN, and the STDOUT from the 81 The command will get the message on its STDIN, and the STDOUT from the
82 command will be included verbatim as the commit message, i.e. this can 82 command will be included verbatim as the commit message, i.e. this can
83 be used to implement bugtracker integration. Default value: none. 83 be used to implement bugtracker integration. Default value: none.
84 See also: "FILTER API".
84 85
85css:: 86css::
86 Url which specifies the css document to include in all cgit pages. 87 Url which specifies the css document to include in all cgit pages.
@@ -105,6 +106,11 @@ enable-gitweb-owner::
105 for the git config value "gitweb.owner" to determine the owner. 106 for the git config value "gitweb.owner" to determine the owner.
106 Default value: "1". See also: scan-path. 107 Default value: "1". See also: scan-path.
107 108
109enable-http-clone::
110 If set to "1", cgit will act as an dumb HTTP endpoint for git clones.
111 If you use an alternate way of serving git repositories, you may wish
112 to disable this. Default value: "1".
113
108enable-index-links:: 114enable-index-links::
109 Flag which, when set to "1", will make cgit generate extra links for 115 Flag which, when set to "1", will make cgit generate extra links for
110 each repo in the repository index (specifically, to the "summary", 116 each repo in the repository index (specifically, to the "summary",
@@ -287,8 +293,9 @@ scan-path::
287 the result will be cached as a cgitrc include-file in the cache 293 the result will be cached as a cgitrc include-file in the cache
288 directory. If project-list has been defined prior to scan-path, 294 directory. If project-list has been defined prior to scan-path,
289 scan-path loads only the directories listed in the file pointed to by 295 scan-path loads only the directories listed in the file pointed to by
290 project-list. Default value: none. See also: cache-scanrc-ttl, 296 project-list. Be advised that only the global settings taken
291 project-list. 297 before the scan-path directive will be applied to each repository.
298 Default value: none. See also: cache-scanrc-ttl, project-list.
292 299
293section:: 300section::
294 The name of the current repository section - all repositories defined 301 The name of the current repository section - all repositories defined
@@ -308,7 +315,8 @@ side-by-side-diffs::
308snapshots:: 315snapshots::
309 Text which specifies the default set of snapshot formats generated by 316 Text which specifies the default set of snapshot formats generated by
310 cgit. The value is a space-separated list of zero or more of the 317 cgit. The value is a space-separated list of zero or more of the
311 values "tar", "tar.gz", "tar.bz2" and "zip". Default value: none. 318 values "tar", "tar.gz", "tar.bz2", "tar.xz" and "zip". Default value:
319 none.
312 320
313source-filter:: 321source-filter::
314 Specifies a command which will be invoked to format plaintext blobs 322 Specifies a command which will be invoked to format plaintext blobs
@@ -316,7 +324,7 @@ source-filter::
316 and the name of the blob as its only command line argument. The STDOUT 324 and the name of the blob as its only command line argument. The STDOUT
317 from the command will be included verbatim as the blob contents, i.e. 325 from the command will be included verbatim as the blob contents, i.e.
318 this can be used to implement e.g. syntax highlighting. Default value: 326 this can be used to implement e.g. syntax highlighting. Default value:
319 none. 327 none. See also: "FILTER API".
320 328
321summary-branches:: 329summary-branches::
322 Specifies the number of branches to display in the repository "summary" 330 Specifies the number of branches to display in the repository "summary"
@@ -349,7 +357,7 @@ REPOSITORY SETTINGS
349------------------- 357-------------------
350repo.about-filter:: 358repo.about-filter::
351 Override the default about-filter. Default value: none. See also: 359 Override the default about-filter. Default value: none. See also:
352 "enable-filter-overrides". 360 "enable-filter-overrides". See also: "FILTER API".
353 361
354repo.clone-url:: 362repo.clone-url::
355 A list of space-separated urls which can be used to clone this repo. 363 A list of space-separated urls which can be used to clone this repo.
@@ -357,7 +365,7 @@ repo.clone-url::
357 365
358repo.commit-filter:: 366repo.commit-filter::
359 Override the default commit-filter. Default value: none. See also: 367 Override the default commit-filter. Default value: none. See also:
360 "enable-filter-overrides". 368 "enable-filter-overrides". See also: "FILTER API".
361 369
362repo.defbranch:: 370repo.defbranch::
363 The name of the default branch for this repository. If no such branch 371 The name of the default branch for this repository. If no such branch
@@ -428,7 +436,7 @@ repo.section::
428 436
429repo.source-filter:: 437repo.source-filter::
430 Override the default source-filter. Default value: none. See also: 438 Override the default source-filter. Default value: none. See also:
431 "enable-filter-overrides". 439 "enable-filter-overrides". See also: "FILTER API".
432 440
433repo.url:: 441repo.url::
434 The relative url used to access the repository. This must be the first 442 The relative url used to access the repository. This must be the first
@@ -448,6 +456,42 @@ Note: the "repo." prefix is dropped from the option names in repo-specific
448config files, e.g. "repo.desc" becomes "desc". 456config files, e.g. "repo.desc" becomes "desc".
449 457
450 458
459FILTER API
460----------
461- about filter::
462 This filter is given no arguments.
463 The about text that is to be filtered is available on standard input and the
464 filtered text is expected on standard output.
465- commit filter::
466 This filter is given no arguments.
467 The commit message text that is to be filtered is available on standard input
468 and the filtered text is expected on standard output.
469- source filter::
470 This filter is given a single parameter: the filename of the source file to
471 filter. The filter can use the filename to determine (for example) the syntax
472 highlighting mode.
473 The contents of the source file that is to be filtered is available on
474 standard input and the filtered contents is expected on standard output.
475
476Also, all filters are handed the following environment variables:
477- CGIT_REPO_URL ( = repo.url setting )
478- CGIT_REPO_NAME ( = repo.name setting )
479- CGIT_REPO_PATH ( = repo.path setting )
480- CGIT_REPO_OWNER ( = repo.owner setting )
481- CGIT_REPO_DEFBRANCH ( = repo.defbranch setting )
482- CGIT_REPO_SECTION ( = section setting )
483- CGIT_REPO_CLONE_URL ( = repo.clone-url setting )
484
485If a setting is not defined for a repository and the corresponding global
486setting is also not defined (if applicable), then the corresponding
487environment variable will be an empty string.
488
489Note that under normal circumstance all these environment variables are
490defined. If however the total size of the defined settings exceed the
491allocated buffer within cgit then only the environment variables that fit
492in the allocated buffer are handed to the filter.
493
494
451EXAMPLE CGITRC FILE 495EXAMPLE CGITRC FILE
452------------------- 496-------------------
453 497
diff --git a/cmd.c b/cmd.c
index 05d5aaf..5a3d157 100644
--- a/cmd.c
+++ b/cmd.c
@@ -130,31 +130,31 @@ static void tree_fn(struct cgit_context *ctx)
130 cgit_print_tree(ctx->qry.sha1, ctx->qry.path); 130 cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
131} 131}
132 132
133#define def_cmd(name, want_repo, want_layout, want_vpath) \ 133#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \
134 {#name, name##_fn, want_repo, want_layout, want_vpath} 134 {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone}
135 135
136struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) 136struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
137{ 137{
138 static struct cgit_cmd cmds[] = { 138 static struct cgit_cmd cmds[] = {
139 def_cmd(HEAD, 1, 0, 0), 139 def_cmd(HEAD, 1, 0, 0, 1),
140 def_cmd(atom, 1, 0, 0), 140 def_cmd(atom, 1, 0, 0, 0),
141 def_cmd(about, 0, 1, 0), 141 def_cmd(about, 0, 1, 0, 0),
142 def_cmd(blob, 1, 0, 0), 142 def_cmd(blob, 1, 0, 0, 0),
143 def_cmd(commit, 1, 1, 1), 143 def_cmd(commit, 1, 1, 1, 0),
144 def_cmd(diff, 1, 1, 1), 144 def_cmd(diff, 1, 1, 1, 0),
145 def_cmd(info, 1, 0, 0), 145 def_cmd(info, 1, 0, 0, 1),
146 def_cmd(log, 1, 1, 1), 146 def_cmd(log, 1, 1, 1, 0),
147 def_cmd(ls_cache, 0, 0, 0), 147 def_cmd(ls_cache, 0, 0, 0, 0),
148 def_cmd(objects, 1, 0, 0), 148 def_cmd(objects, 1, 0, 0, 1),
149 def_cmd(patch, 1, 0, 1), 149 def_cmd(patch, 1, 0, 1, 0),
150 def_cmd(plain, 1, 0, 0), 150 def_cmd(plain, 1, 0, 0, 0),
151 def_cmd(refs, 1, 1, 0), 151 def_cmd(refs, 1, 1, 0, 0),
152 def_cmd(repolist, 0, 0, 0), 152 def_cmd(repolist, 0, 0, 0, 0),
153 def_cmd(snapshot, 1, 0, 0), 153 def_cmd(snapshot, 1, 0, 0, 0),
154 def_cmd(stats, 1, 1, 1), 154 def_cmd(stats, 1, 1, 1, 0),
155 def_cmd(summary, 1, 1, 0), 155 def_cmd(summary, 1, 1, 0, 0),
156 def_cmd(tag, 1, 1, 0), 156 def_cmd(tag, 1, 1, 0, 0),
157 def_cmd(tree, 1, 1, 1), 157 def_cmd(tree, 1, 1, 1, 0),
158 }; 158 };
159 int i; 159 int i;
160 160
diff --git a/cmd.h b/cmd.h
index 8dc01bd..eb5bc87 100644
--- a/cmd.h
+++ b/cmd.h
@@ -8,7 +8,8 @@ struct cgit_cmd {
8 cgit_cmd_fn fn; 8 cgit_cmd_fn fn;
9 unsigned int want_repo:1, 9 unsigned int want_repo:1,
10 want_layout:1, 10 want_layout:1,
11 want_vpath:1; 11 want_vpath:1,
12 is_clone:1;
12}; 13};
13 14
14extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx); 15extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx);
diff --git a/filters/commit-links.sh b/filters/commit-links.sh
index 110c609..d2cd2b3 100755
--- a/filters/commit-links.sh
+++ b/filters/commit-links.sh
@@ -3,6 +3,17 @@
3# 3#
4# To use this script, refer to this file with either the commit-filter or the 4# To use this script, refer to this file with either the commit-filter or the
5# repo.commit-filter options in cgitrc. 5# repo.commit-filter options in cgitrc.
6#
7# The following environment variables can be used to retrieve the configuration
8# of the repository for which this script is called:
9# CGIT_REPO_URL ( = repo.url setting )