author | Lars Hjemli <hjemli@gmail.com> | 2009-08-09 11:22:00 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-08-09 11:22:00 (UTC) |
commit | e976df27952ca1e450c1c3d420532ac9f5e3036b (patch) (unidiff) | |
tree | 2634538f3144c935d1579315d4de289e6c890f19 | |
parent | f35db1cd2b75aac6952aa07713e44ca01fd89727 (diff) | |
download | cgit-e976df27952ca1e450c1c3d420532ac9f5e3036b.zip cgit-e976df27952ca1e450c1c3d420532ac9f5e3036b.tar.gz cgit-e976df27952ca1e450c1c3d420532ac9f5e3036b.tar.bz2 |
Add support for repo.commit-filter and repo.source-filter
These options can be used to override the default commit- and source-
filter settings per repository.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgit.h | 20 | ||||
-rw-r--r-- | cgitrc.5.txt | 6 | ||||
-rw-r--r-- | shared.c | 2 | ||||
-rw-r--r-- | ui-commit.c | 16 | ||||
-rw-r--r-- | ui-tree.c | 8 |
6 files changed, 35 insertions, 21 deletions
@@ -137,24 +137,28 @@ void config_cb(const char *name, const char *value) | |||
137 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) | 137 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) |
138 | ctx.repo->defbranch = xstrdup(value); | 138 | ctx.repo->defbranch = xstrdup(value); |
139 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) | 139 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
140 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | 140 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
141 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) | 141 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
142 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 142 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
143 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) | 143 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
144 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 144 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
145 | else if (ctx.repo && !strcmp(name, "repo.max-stats")) | 145 | else if (ctx.repo && !strcmp(name, "repo.max-stats")) |
146 | ctx.repo->max_stats = cgit_find_stats_period(value, NULL); | 146 | ctx.repo->max_stats = cgit_find_stats_period(value, NULL); |
147 | else if (ctx.repo && !strcmp(name, "repo.module-link")) | 147 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
148 | ctx.repo->module_link= xstrdup(value); | 148 | ctx.repo->module_link= xstrdup(value); |
149 | else if (ctx.repo && !strcmp(name, "repo.commit-filter")) | ||
150 | ctx.repo->commit_filter = new_filter(value, 0); | ||
151 | else if (ctx.repo && !strcmp(name, "repo.source-filter")) | ||
152 | ctx.repo->source_filter = new_filter(value, 1); | ||
149 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { | 153 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
150 | if (*value == '/') | 154 | if (*value == '/') |
151 | ctx.repo->readme = xstrdup(value); | 155 | ctx.repo->readme = xstrdup(value); |
152 | else | 156 | else |
153 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); | 157 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
154 | } else if (!strcmp(name, "include")) | 158 | } else if (!strcmp(name, "include")) |
155 | parse_configfile(value, config_cb); | 159 | parse_configfile(value, config_cb); |
156 | } | 160 | } |
157 | 161 | ||
158 | static void querystring_cb(const char *name, const char *value) | 162 | static void querystring_cb(const char *name, const char *value) |
159 | { | 163 | { |
160 | if (!strcmp(name,"r")) { | 164 | if (!strcmp(name,"r")) { |
@@ -39,40 +39,51 @@ | |||
39 | #define TM_MONTH (TM_YEAR / 12.0) | 39 | #define TM_MONTH (TM_YEAR / 12.0) |
40 | 40 | ||
41 | 41 | ||
42 | /* | 42 | /* |
43 | * Default encoding | 43 | * Default encoding |
44 | */ | 44 | */ |
45 | #define PAGE_ENCODING "UTF-8" | 45 | #define PAGE_ENCODING "UTF-8" |
46 | 46 | ||
47 | typedef void (*configfn)(const char *name, const char *value); | 47 | typedef void (*configfn)(const char *name, const char *value); |
48 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 48 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
49 | typedef void (*linediff_fn)(char *line, int len); | 49 | typedef void (*linediff_fn)(char *line, int len); |
50 | 50 | ||
51 | struct cgit_filter { | ||
52 | char *cmd; | ||
53 | char **argv; | ||
54 | int old_stdout; | ||
55 | int pipe_fh[2]; | ||
56 | int pid; | ||
57 | int exitstatus; | ||
58 | }; | ||
59 | |||
51 | struct cgit_repo { | 60 | struct cgit_repo { |
52 | char *url; | 61 | char *url; |
53 | char *name; | 62 | char *name; |
54 | char *path; | 63 | char *path; |
55 | char *desc; | 64 | char *desc; |
56 | char *owner; | 65 | char *owner; |
57 | char *defbranch; | 66 | char *defbranch; |
58 | char *group; | 67 | char *group; |
59 | char *module_link; | 68 | char *module_link; |
60 | char *readme; | 69 | char *readme; |
61 | char *clone_url; | 70 | char *clone_url; |
62 | int snapshots; | 71 | int snapshots; |
63 | int enable_log_filecount; | 72 | int enable_log_filecount; |
64 | int enable_log_linecount; | 73 | int enable_log_linecount; |
65 | int max_stats; | 74 | int max_stats; |
66 | time_t mtime; | 75 | time_t mtime; |
76 | struct cgit_filter *commit_filter; | ||
77 | struct cgit_filter *source_filter; | ||
67 | }; | 78 | }; |
68 | 79 | ||
69 | struct cgit_repolist { | 80 | struct cgit_repolist { |
70 | int length; | 81 | int length; |
71 | int count; | 82 | int count; |
72 | struct cgit_repo *repos; | 83 | struct cgit_repo *repos; |
73 | }; | 84 | }; |
74 | 85 | ||
75 | struct commitinfo { | 86 | struct commitinfo { |
76 | struct commit *commit; | 87 | struct commit *commit; |
77 | char *author; | 88 | char *author; |
78 | char *author_email; | 89 | char *author_email; |
@@ -120,33 +131,24 @@ struct cgit_query { | |||
120 | char *sha2; | 131 | char *sha2; |
121 | char *path; | 132 | char *path; |
122 | char *name; | 133 | char *name; |
123 | char *mimetype; | 134 | char *mimetype; |
124 | char *url; | 135 | char *url; |
125 | char *period; | 136 | char *period; |
126 | int ofs; | 137 | int ofs; |
127 | int nohead; | 138 | int nohead; |
128 | char *sort; | 139 | char *sort; |
129 | int showmsg; | 140 | int showmsg; |
130 | }; | 141 | }; |
131 | 142 | ||
132 | struct cgit_filter { | ||
133 | char *cmd; | ||
134 | char **argv; | ||
135 | int old_stdout; | ||
136 | int pipe_fh[2]; | ||
137 | int pid; | ||
138 | int exitstatus; | ||
139 | }; | ||
140 | |||
141 | struct cgit_config { | 143 | struct cgit_config { |
142 | char *agefile; | 144 | char *agefile; |
143 | char *cache_root; | 145 | char *cache_root; |
144 | char *clone_prefix; | 146 | char *clone_prefix; |
145 | char *css; | 147 | char *css; |
146 | char *favicon; | 148 | char *favicon; |
147 | char *footer; | 149 | char *footer; |
148 | char *head_include; | 150 | char *head_include; |
149 | char *header; | 151 | char *header; |
150 | char *index_header; | 152 | char *index_header; |
151 | char *index_info; | 153 | char *index_info; |
152 | char *logo; | 154 | char *logo; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 2efd6aa..ffb3e0f 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -229,24 +229,27 @@ virtual-root:: | |||
229 | will also cause cgit to generate 'virtual urls', i.e. urls like | 229 | will also cause cgit to generate 'virtual urls', i.e. urls like |
230 | '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default | 230 | '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default |
231 | value: none. | 231 | value: none. |
232 | NOTE: cgit has recently learned how to use PATH_INFO to achieve the | 232 | NOTE: cgit has recently learned how to use PATH_INFO to achieve the |
233 | same kind of virtual urls, so this option will probably be deprecated. | 233 | same kind of virtual urls, so this option will probably be deprecated. |
234 | 234 | ||
235 | REPOSITORY SETTINGS | 235 | REPOSITORY SETTINGS |
236 | ------------------- | 236 | ------------------- |
237 | repo.clone-url:: | 237 | repo.clone-url:: |
238 | A list of space-separated urls which can be used to clone this repo. | 238 | A list of space-separated urls which can be used to clone this repo. |
239 | Default value: none. | 239 | Default value: none. |
240 | 240 | ||
241 | repo.commit-filter:: | ||
242 | Override the default commit-filter. Default value: <commit-filter>. | ||
243 | |||
241 | repo.defbranch:: | 244 | repo.defbranch:: |
242 | The name of the default branch for this repository. If no such branch | 245 | The name of the default branch for this repository. If no such branch |
243 | exists in the repository, the first branch name (when sorted) is used | 246 | exists in the repository, the first branch name (when sorted) is used |
244 | as default instead. Default value: "master". | 247 | as default instead. Default value: "master". |
245 | 248 | ||
246 | repo.desc:: | 249 | repo.desc:: |
247 | The value to show as repository description. Default value: none. | 250 | The value to show as repository description. Default value: none. |
248 | 251 | ||
249 | repo.enable-log-filecount:: | 252 | repo.enable-log-filecount:: |
250 | A flag which can be used to disable the global setting | 253 | A flag which can be used to disable the global setting |
251 | `enable-log-filecount'. Default value: none. | 254 | `enable-log-filecount'. Default value: none. |
252 | 255 | ||
@@ -269,24 +272,27 @@ repo.owner:: | |||
269 | repo.path:: | 272 | repo.path:: |
270 | An absolute path to the repository directory. For non-bare repositories | 273 | An absolute path to the repository directory. For non-bare repositories |
271 | this is the .git-directory. Default value: none. | 274 | this is the .git-directory. Default value: none. |
272 | 275 | ||
273 | repo.readme:: | 276 | repo.readme:: |
274 | A path (relative to <repo.path>) which specifies a file to include | 277 | A path (relative to <repo.path>) which specifies a file to include |
275 | verbatim as the "About" page for this repo. Default value: none. | 278 | verbatim as the "About" page for this repo. Default value: none. |
276 | 279 | ||
277 | repo.snapshots:: | 280 | repo.snapshots:: |
278 | A mask of allowed snapshot-formats for this repo, restricted by the | 281 | A mask of allowed snapshot-formats for this repo, restricted by the |
279 | "snapshots" global setting. Default value: <snapshots>. | 282 | "snapshots" global setting. Default value: <snapshots>. |
280 | 283 | ||
284 | repo.source-filter:: | ||
285 | Override the default source-filter. Default value: <source-filter>. | ||
286 | |||
281 | repo.url:: | 287 | repo.url:: |
282 | The relative url used to access the repository. This must be the first | 288 | The relative url used to access the repository. This must be the first |
283 | setting specified for each repo. Default value: none. | 289 | setting specified for each repo. Default value: none. |
284 | 290 | ||
285 | 291 | ||
286 | EXAMPLE CGITRC FILE | 292 | EXAMPLE CGITRC FILE |
287 | ------------------- | 293 | ------------------- |
288 | 294 | ||
289 | .... | 295 | .... |
290 | # Enable caching of up to 1000 output entriess | 296 | # Enable caching of up to 1000 output entriess |
291 | cache-size=1000 | 297 | cache-size=1000 |
292 | 298 | ||
@@ -53,24 +53,26 @@ struct cgit_repo *cgit_add_repo(const char *url) | |||
53 | ret->path = NULL; | 53 | ret->path = NULL; |
54 | ret->desc = "[no description]"; | 54 | ret->desc = "[no description]"; |
55 | ret->owner = NULL; | 55 | ret->owner = NULL; |
56 | ret->group = ctx.cfg.repo_group; | 56 | ret->group = ctx.cfg.repo_group; |
57 | ret->defbranch = "master"; | 57 | ret->defbranch = "master"; |
58 | ret->snapshots = ctx.cfg.snapshots; | 58 | ret->snapshots = ctx.cfg.snapshots; |
59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; | 59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; | 60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
61 | ret->max_stats = ctx.cfg.max_stats; | 61 | ret->max_stats = ctx.cfg.max_stats; |
62 | ret->module_link = ctx.cfg.module_link; | 62 | ret->module_link = ctx.cfg.module_link; |
63 | ret->readme = NULL; | 63 | ret->readme = NULL; |
64 | ret->mtime = -1; | 64 | ret->mtime = -1; |
65 | ret->commit_filter = ctx.cfg.commit_filter; | ||
66 | ret->source_filter = ctx.cfg.source_filter; | ||
65 | return ret; | 67 | return ret; |
66 | } | 68 | } |
67 | 69 | ||
68 | struct cgit_repo *cgit_get_repoinfo(const char *url) | 70 | struct cgit_repo *cgit_get_repoinfo(const char *url) |
69 | { | 71 | { |
70 | int i; | 72 | int i; |
71 | struct cgit_repo *repo; | 73 | struct cgit_repo *repo; |
72 | 74 | ||
73 | for (i=0; i<cgit_repolist.count; i++) { | 75 | for (i=0; i<cgit_repolist.count; i++) { |
74 | repo = &cgit_repolist.repos[i]; | 76 | repo = &cgit_repolist.repos[i]; |
75 | if (!strcmp(repo->url, url)) | 77 | if (!strcmp(repo->url, url)) |
76 | return repo; | 78 | return repo; |
diff --git a/ui-commit.c b/ui-commit.c index ee0e139..5815b58 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -80,35 +80,35 @@ void cgit_print_commit(char *hex) | |||
80 | sha1_to_hex(p->item->object.sha1), NULL); | 80 | sha1_to_hex(p->item->object.sha1), NULL); |
81 | html(")</td></tr>"); | 81 | html(")</td></tr>"); |
82 | parents++; | 82 | parents++; |
83 | } | 83 | } |
84 | if (ctx.repo->snapshots) { | 84 | if (ctx.repo->snapshots) { |
85 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 85 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
86 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, | 86 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, |
87 | hex, ctx.repo->snapshots); | 87 | hex, ctx.repo->snapshots); |
88 | html("</td></tr>"); | 88 | html("</td></tr>"); |
89 | } | 89 | } |
90 | html("</table>\n"); | 90 | html("</table>\n"); |
91 | html("<div class='commit-subject'>"); | 91 | html("<div class='commit-subject'>"); |
92 | if (ctx.cfg.commit_filter) | 92 | if (ctx.repo->commit_filter) |
93 | cgit_open_filter(ctx.cfg.commit_filter); | 93 | cgit_open_filter(ctx.repo->commit_filter); |
94 | html_txt(info->subject); | 94 | html_txt(info->subject); |
95 | if (ctx.cfg.commit_filter) | 95 | if (ctx.repo->commit_filter) |
96 | cgit_close_filter(ctx.cfg.commit_filter); | 96 | cgit_close_filter(ctx.repo->commit_filter); |
97 | show_commit_decorations(commit); | 97 | show_commit_decorations(commit); |
98 | html("</div>"); | 98 | html("</div>"); |
99 | html("<div class='commit-msg'>"); | 99 | html("<div class='commit-msg'>"); |
100 | if (ctx.cfg.commit_filter) | 100 | if (ctx.repo->commit_filter) |
101 | cgit_open_filter(ctx.cfg.commit_filter); | 101 | cgit_open_filter(ctx.repo->commit_filter); |
102 | html_txt(info->msg); | 102 | html_txt(info->msg); |
103 | if (ctx.cfg.commit_filter) | 103 | if (ctx.repo->commit_filter) |
104 | cgit_close_filter(ctx.cfg.commit_filter); | 104 | cgit_close_filter(ctx.repo->commit_filter); |
105 | html("</div>"); | 105 | html("</div>"); |
106 | if (parents < 3) { | 106 | if (parents < 3) { |
107 | if (parents) | 107 | if (parents) |
108 | tmp = sha1_to_hex(commit->parents->item->object.sha1); | 108 | tmp = sha1_to_hex(commit->parents->item->object.sha1); |
109 | else | 109 | else |
110 | tmp = NULL; | 110 | tmp = NULL; |
111 | cgit_print_diff(ctx.qry.sha1, tmp, NULL); | 111 | cgit_print_diff(ctx.qry.sha1, tmp, NULL); |
112 | } | 112 | } |
113 | cgit_free_commitinfo(info); | 113 | cgit_free_commitinfo(info); |
114 | } | 114 | } |
@@ -13,30 +13,30 @@ | |||
13 | 13 | ||
14 | char *curr_rev; | 14 | char *curr_rev; |
15 | char *match_path; | 15 | char *match_path; |
16 | int header = 0; | 16 | int header = 0; |
17 | 17 | ||
18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) | 18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) |
19 | { | 19 | { |
20 | unsigned long lineno, idx; | 20 | unsigned long lineno, idx; |
21 | const char *numberfmt = | 21 | const char *numberfmt = |
22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; | 22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; |
23 | 23 | ||
24 | html("<table summary='blob content' class='blob'>\n"); | 24 | html("<table summary='blob content' class='blob'>\n"); |
25 | if (ctx.cfg.source_filter) { | 25 | if (ctx.repo->source_filter) { |
26 | html("<tr><td class='lines'><pre><code>"); | 26 | html("<tr><td class='lines'><pre><code>"); |
27 | ctx.cfg.source_filter->argv[1] = xstrdup(name); | 27 | ctx.repo->source_filter->argv[1] = xstrdup(name); |
28 | cgit_open_filter(ctx.cfg.source_filter); | 28 | cgit_open_filter(ctx.repo->source_filter); |
29 | write(STDOUT_FILENO, buf, size); | 29 | write(STDOUT_FILENO, buf, size); |
30 | cgit_close_filter(ctx.cfg.source_filter); | 30 | cgit_close_filter(ctx.repo->source_filter); |
31 | html("</code></pre></td></tr></table>\n"); | 31 | html("</code></pre></td></tr></table>\n"); |
32 | return; | 32 | return; |
33 | } | 33 | } |
34 | 34 | ||
35 | html("<tr><td class='linenumbers'><pre>"); | 35 | html("<tr><td class='linenumbers'><pre>"); |
36 | idx = 0; | 36 | idx = 0; |
37 | lineno = 0; | 37 | lineno = 0; |
38 | 38 | ||
39 | if (size) { | 39 | if (size) { |
40 | htmlf(numberfmt, ++lineno); | 40 | htmlf(numberfmt, ++lineno); |
41 | while(idx < size - 1) { // skip absolute last newline | 41 | while(idx < size - 1) { // skip absolute last newline |
42 | if (buf[idx] == '\n') | 42 | if (buf[idx] == '\n') |