summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2009-08-09 11:46:01 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-08-09 11:46:01 (UTC)
commitdb6303b58883c4417f5bcc0c1ee34fed6553dca3 (patch) (unidiff)
treeef7775ade9eef57c5a878f9588fe545a7da2c952
parent17e3ff42646f182911fd0e5d872082977538db9e (diff)
parent97b3d252629a8a3b9d356c2532dec7611438e4b9 (diff)
downloadcgit-db6303b58883c4417f5bcc0c1ee34fed6553dca3.zip
cgit-db6303b58883c4417f5bcc0c1ee34fed6553dca3.tar.gz
cgit-db6303b58883c4417f5bcc0c1ee34fed6553dca3.tar.bz2
Merge branch 'lh/plugins'
Conflicts: cgit.c cgit.h
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c23
-rw-r--r--cgit.h16
-rw-r--r--cgitrc.5.txt20
-rw-r--r--shared.c37
-rw-r--r--ui-commit.c8
-rw-r--r--ui-snapshot.c35
-rw-r--r--ui-tree.c18
7 files changed, 125 insertions, 32 deletions
diff --git a/cgit.c b/cgit.c
index aa1107a..dbec196 100644
--- a/cgit.c
+++ b/cgit.c
@@ -20,16 +20,31 @@ const char *cgit_version = CGIT_VERSION;
20void add_mimetype(const char *name, const char *value) 20void add_mimetype(const char *name, const char *value)
21{ 21{
22 struct string_list_item *item; 22 struct string_list_item *item;
23 23
24 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); 24 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes);
25 item->util = xstrdup(value); 25 item->util = xstrdup(value);
26} 26}
27 27
28struct cgit_filter *new_filter(const char *cmd, int extra_args)
29{
30 struct cgit_filter *f;
31
32 if (!cmd || !cmd[0])
33 return NULL;
34
35 f = xmalloc(sizeof(struct cgit_filter));
36 f->cmd = xstrdup(cmd);
37 f->argv = xmalloc((2 + extra_args) * sizeof(char *));
38 f->argv[0] = f->cmd;
39 f->argv[1] = NULL;
40 return f;
41}
42
28void config_cb(const char *name, const char *value) 43void config_cb(const char *name, const char *value)
29{ 44{
30 if (!strcmp(name, "root-title")) 45 if (!strcmp(name, "root-title"))
31 ctx.cfg.root_title = xstrdup(value); 46 ctx.cfg.root_title = xstrdup(value);
32 else if (!strcmp(name, "root-desc")) 47 else if (!strcmp(name, "root-desc"))
33 ctx.cfg.root_desc = xstrdup(value); 48 ctx.cfg.root_desc = xstrdup(value);
34 else if (!strcmp(name, "root-readme")) 49 else if (!strcmp(name, "root-readme"))
35 ctx.cfg.root_readme = xstrdup(value); 50 ctx.cfg.root_readme = xstrdup(value);
@@ -80,26 +95,30 @@ void config_cb(const char *name, const char *value)
80 else if (!strcmp(name, "cache-root-ttl")) 95 else if (!strcmp(name, "cache-root-ttl"))
81 ctx.cfg.cache_root_ttl = atoi(value); 96 ctx.cfg.cache_root_ttl = atoi(value);
82 else if (!strcmp(name, "cache-repo-ttl")) 97 else if (!strcmp(name, "cache-repo-ttl"))
83 ctx.cfg.cache_repo_ttl = atoi(value); 98 ctx.cfg.cache_repo_ttl = atoi(value);
84 else if (!strcmp(name, "cache-static-ttl")) 99 else if (!strcmp(name, "cache-static-ttl"))
85 ctx.cfg.cache_static_ttl = atoi(value); 100 ctx.cfg.cache_static_ttl = atoi(value);
86 else if (!strcmp(name, "cache-dynamic-ttl")) 101 else if (!strcmp(name, "cache-dynamic-ttl"))
87 ctx.cfg.cache_dynamic_ttl = atoi(value); 102 ctx.cfg.cache_dynamic_ttl = atoi(value);
103 else if (!strcmp(name, "commit-filter"))
104 ctx.cfg.commit_filter = new_filter(value, 0);
88 else if (!strcmp(name, "embedded")) 105 else if (!strcmp(name, "embedded"))
89 ctx.cfg.embedded = atoi(value); 106 ctx.cfg.embedded = atoi(value);
90 else if (!strcmp(name, "max-message-length")) 107 else if (!strcmp(name, "max-message-length"))
91 ctx.cfg.max_msg_len = atoi(value); 108 ctx.cfg.max_msg_len = atoi(value);
92 else if (!strcmp(name, "max-repodesc-length")) 109 else if (!strcmp(name, "max-repodesc-length"))
93 ctx.cfg.max_repodesc_len = atoi(value); 110 ctx.cfg.max_repodesc_len = atoi(value);
94 else if (!strcmp(name, "max-repo-count")) 111 else if (!strcmp(name, "max-repo-count"))
95 ctx.cfg.max_repo_count = atoi(value); 112 ctx.cfg.max_repo_count = atoi(value);
96 else if (!strcmp(name, "max-commit-count")) 113 else if (!strcmp(name, "max-commit-count"))
97 ctx.cfg.max_commit_count = atoi(value); 114 ctx.cfg.max_commit_count = atoi(value);
115 else if (!strcmp(name, "source-filter"))
116 ctx.cfg.source_filter = new_filter(value, 1);
98 else if (!strcmp(name, "summary-log")) 117 else if (!strcmp(name, "summary-log"))
99 ctx.cfg.summary_log = atoi(value); 118 ctx.cfg.summary_log = atoi(value);
100 else if (!strcmp(name, "summary-branches")) 119 else if (!strcmp(name, "summary-branches"))
101 ctx.cfg.summary_branches = atoi(value); 120 ctx.cfg.summary_branches = atoi(value);
102 else if (!strcmp(name, "summary-tags")) 121 else if (!strcmp(name, "summary-tags"))
103 ctx.cfg.summary_tags = atoi(value); 122 ctx.cfg.summary_tags = atoi(value);
104 else if (!strcmp(name, "agefile")) 123 else if (!strcmp(name, "agefile"))
105 ctx.cfg.agefile = xstrdup(value); 124 ctx.cfg.agefile = xstrdup(value);
@@ -134,16 +153,20 @@ void config_cb(const char *name, const char *value)
134 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) 153 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
135 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 154 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
136 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) 155 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
137 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 156 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
138 else if (ctx.repo && !strcmp(name, "repo.max-stats")) 157 else if (ctx.repo && !strcmp(name, "repo.max-stats"))
139 ctx.repo->max_stats = cgit_find_stats_period(value, NULL); 158 ctx.repo->max_stats = cgit_find_stats_period(value, NULL);
140 else if (ctx.repo && !strcmp(name, "repo.module-link")) 159 else if (ctx.repo && !strcmp(name, "repo.module-link"))
141 ctx.repo->module_link= xstrdup(value); 160 ctx.repo->module_link= xstrdup(value);
161 else if (ctx.repo && !strcmp(name, "repo.commit-filter"))
162 ctx.repo->commit_filter = new_filter(value, 0);
163 else if (ctx.repo && !strcmp(name, "repo.source-filter"))
164 ctx.repo->source_filter = new_filter(value, 1);
142 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { 165 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
143 if (*value == '/') 166 if (*value == '/')
144 ctx.repo->readme = xstrdup(value); 167 ctx.repo->readme = xstrdup(value);
145 else 168 else
146 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); 169 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
147 } else if (!strcmp(name, "include")) 170 } else if (!strcmp(name, "include"))
148 parse_configfile(value, config_cb); 171 parse_configfile(value, config_cb);
149} 172}
diff --git a/cgit.h b/cgit.h
index 1194eb0..b8557ac 100644
--- a/cgit.h
+++ b/cgit.h
@@ -44,32 +44,43 @@
44 * Default encoding 44 * Default encoding
45 */ 45 */
46#define PAGE_ENCODING "UTF-8" 46#define PAGE_ENCODING "UTF-8"
47 47
48typedef void (*configfn)(const char *name, const char *value); 48typedef void (*configfn)(const char *name, const char *value);
49typedef void (*filepair_fn)(struct diff_filepair *pair); 49typedef void (*filepair_fn)(struct diff_filepair *pair);
50typedef void (*linediff_fn)(char *line, int len); 50typedef void (*linediff_fn)(char *line, int len);
51 51
52struct cgit_filter {
53 char *cmd;
54 char **argv;
55 int old_stdout;
56 int pipe_fh[2];
57 int pid;
58 int exitstatus;
59};
60
52struct cgit_repo { 61struct cgit_repo {
53 char *url; 62 char *url;
54 char *name; 63 char *name;
55 char *path; 64 char *path;
56 char *desc; 65 char *desc;
57 char *owner; 66 char *owner;
58 char *defbranch; 67 char *defbranch;
59 char *group; 68 char *group;
60 char *module_link; 69 char *module_link;
61 char *readme; 70 char *readme;
62 char *clone_url; 71 char *clone_url;
63 int snapshots; 72 int snapshots;
64 int enable_log_filecount; 73 int enable_log_filecount;
65 int enable_log_linecount; 74 int enable_log_linecount;
66 int max_stats; 75 int max_stats;
67 time_t mtime; 76 time_t mtime;
77 struct cgit_filter *commit_filter;
78 struct cgit_filter *source_filter;
68}; 79};
69 80
70struct cgit_repolist { 81struct cgit_repolist {
71 int length; 82 int length;
72 int count; 83 int count;
73 struct cgit_repo *repos; 84 struct cgit_repo *repos;
74}; 85};
75 86
@@ -172,16 +183,18 @@ struct cgit_config {
172 int noplainemail; 183 int noplainemail;
173 int noheader; 184 int noheader;
174 int renamelimit; 185 int renamelimit;
175 int snapshots; 186 int snapshots;
176 int summary_branches; 187 int summary_branches;
177 int summary_log; 188 int summary_log;
178 int summary_tags; 189 int summary_tags;
179 struct string_list mimetypes; 190 struct string_list mimetypes;
191 struct cgit_filter *commit_filter;
192 struct cgit_filter *source_filter;
180}; 193};
181 194
182struct cgit_page { 195struct cgit_page {
183 time_t modified; 196 time_t modified;
184 time_t expires; 197 time_t expires;
185 size_t size; 198 size_t size;
186 char *mimetype; 199 char *mimetype;
187 char *charset; 200 char *charset;
@@ -246,10 +259,13 @@ extern char *fmt(const char *format,...);
246extern struct commitinfo *cgit_parse_commit(struct commit *commit); 259extern struct commitinfo *cgit_parse_commit(struct commit *commit);
247extern struct taginfo *cgit_parse_tag(struct tag *tag); 260extern struct taginfo *cgit_parse_tag(struct tag *tag);
248extern void cgit_parse_url(const char *url); 261extern void cgit_parse_url(const char *url);
249 262
250extern const char *cgit_repobasename(const char *reponame); 263extern const char *cgit_repobasename(const char *reponame);
251 264
252extern int cgit_parse_snapshots_mask(const char *str); 265extern int cgit_parse_snapshots_mask(const char *str);
253 266
267extern int cgit_open_filter(struct cgit_filter *filter);
268extern int cgit_close_filter(struct cgit_filter *filter);
269
254 270
255#endif /* CGIT_H */ 271#endif /* CGIT_H */
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 0412f64..dc63637 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -50,16 +50,22 @@ cache-static-ttl::
50 "5". 50 "5".
51 51
52clone-prefix:: 52clone-prefix::
53 Space-separated list of common prefixes which, when combined with a 53 Space-separated list of common prefixes which, when combined with a
54 repository url, generates valid clone urls for the repository. This 54 repository url, generates valid clone urls for the repository. This
55 setting is only used if `repo.clone-url` is unspecified. Default value: 55 setting is only used if `repo.clone-url` is unspecified. Default value:
56 none. 56 none.
57 57
58commit-filter::
59 Specifies a command which will be invoked to format commit messages.
60 The command will get the message on its STDIN, and the STDOUT from the
61 command will be included verbatim as the commit message, i.e. this can
62 be used to implement bugtracker integration. Default value: none.
63
58css:: 64css::
59 Url which specifies the css document to include in all cgit pages. 65 Url which specifies the css document to include in all cgit pages.
60 Default value: "/cgit.css". 66 Default value: "/cgit.css".
61 67
62embedded:: 68embedded::
63 Flag which, when set to "1", will make cgit generate a html fragment 69 Flag which, when set to "1", will make cgit generate a html fragment
64 suitable for embedding in other html pages. Default value: none. See 70 suitable for embedding in other html pages. Default value: none. See
65 also: "noheader". 71 also: "noheader".
@@ -201,16 +207,24 @@ snapshots::
201 supported by cgit. The value is a space-separated list of zero or more 207 supported by cgit. The value is a space-separated list of zero or more
202 of the following values: 208 of the following values:
203 "tar" uncompressed tar-file 209 "tar" uncompressed tar-file
204 "tar.gz"gzip-compressed tar-file 210 "tar.gz"gzip-compressed tar-file
205 "tar.bz2"bzip-compressed tar-file 211 "tar.bz2"bzip-compressed tar-file
206 "zip" zip-file 212 "zip" zip-file
207 Default value: none. 213 Default value: none.
208 214
215source-filter::
216 Specifies a command which will be invoked to format plaintext blobs
217 in the tree view. The command will get the blob content on its STDIN
218 and the name of the blob as its only command line argument. The STDOUT
219 from the command will be included verbatim as the blob contents, i.e.
220 this can be used to implement e.g. syntax highlighting. Default value:
221 none.
222
209summary-branches:: 223summary-branches::
210 Specifies the number of branches to display in the repository "summary" 224 Specifies the number of branches to display in the repository "summary"
211 view. Default value: "10". 225 view. Default value: "10".
212 226
213summary-log:: 227summary-log::
214 Specifies the number of log entries to display in the repository 228 Specifies the number of log entries to display in the repository
215 "summary" view. Default value: "10". 229 "summary" view. Default value: "10".
216 230
@@ -227,16 +241,19 @@ virtual-root::
227 same kind of virtual urls, so this option will probably be deprecated. 241 same kind of virtual urls, so this option will probably be deprecated.
228 242
229REPOSITORY SETTINGS 243REPOSITORY SETTINGS
230------------------- 244-------------------
231repo.clone-url:: 245repo.clone-url::
232 A list of space-separated urls which can be used to clone this repo. 246 A list of space-separated urls which can be used to clone this repo.
233 Default value: none. 247 Default value: none.
234 248
249repo.commit-filter::
250 Override the default commit-filter. Default value: <commit-filter>.
251
235repo.defbranch:: 252repo.defbranch::
236 The name of the default branch for this repository. If no such branch 253 The name of the default branch for this repository. If no such branch
237 exists in the repository, the first branch name (when sorted) is used 254 exists in the repository, the first branch name (when sorted) is used
238 as default instead. Default value: "master". 255 as default instead. Default value: "master".
239 256
240repo.desc:: 257repo.desc::
241 The value to show as repository description. Default value: none. 258 The value to show as repository description. Default value: none.
242 259
@@ -267,16 +284,19 @@ repo.path::
267repo.readme:: 284repo.readme::
268 A path (relative to <repo.path>) which specifies a file to include 285 A path (relative to <repo.path>) which specifies a file to include
269 verbatim as the "About" page for this repo. Default value: none. 286 verbatim as the "About" page for this repo. Default value: none.
270 287
271repo.snapshots:: 288repo.snapshots::
272 A mask of allowed snapshot-formats for this repo, restricted by the 289 A mask of allowed snapshot-formats for this repo, restricted by the
273 "snapshots" global setting. Default value: <snapshots>. 290 "snapshots" global setting. Default value: <snapshots>.
274 291
292repo.source-filter::
293 Override the default source-filter. Default value: <source-filter>.
294
275repo.url:: 295repo.url::
276 The relative url used to access the repository. This must be the first 296 The relative url used to access the repository. This must be the first
277 setting specified for each repo. Default value: none. 297 setting specified for each repo. Default value: none.
278 298
279 299
280EXAMPLE CGITRC FILE 300EXAMPLE CGITRC FILE
281------------------- 301-------------------
282 302
diff --git a/shared.c b/shared.c
index cce0af4..783604b 100644
--- a/shared.c
+++ b/shared.c
@@ -57,16 +57,18 @@ struct cgit_repo *cgit_add_repo(const char *url)
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
68struct cgit_repo *cgit_get_repoinfo(const char *url) 70struct 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
@@ -350,8 +352,43 @@ int cgit_parse_snapshots_mask(const char *str)
350 rv |= f->bit; 352 rv |= f->bit;
351 break; 353 break;
352 } 354 }
353 } 355 }
354 str += tl; 356 str += tl;
355 } 357 }
356 return rv; 358 return rv;
357} 359}
360
361int cgit_open_filter(struct cgit_filter *filter)
362{
363
364 filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
365 "Unable to duplicate STDOUT");
366 chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess");
367 filter->pid = chk_non_negative(fork(), "Unable to create subprocess");
368 if (filter->pid == 0) {
369 close(filter->pipe_fh[1]);
370 chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
371 "Unable to use pipe as STDIN");
372 execvp(filter->cmd, filter->argv);
373 die("Unable to exec subprocess %s: %s (%d)", filter->cmd,
374 strerror(errno), errno);
375 }
376 close(filter->pipe_fh[0]);
377 chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO),
378 "Unable to use pipe as STDOUT");
379 close(filter->pipe_fh[1]);
380 return 0;
381}
382
383int cgit_close_filter(struct cgit_filter *filter)
384{
385 chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO),
386 "Unable to restore STDOUT");
387 close(filter->old_stdout);
388 if (filter->pid < 0)
389 return 0;
390 waitpid(filter->pid, &filter->exitstatus, 0);
391 if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus))
392 return 0;
393 die("Subprocess %s exited abnormally", filter->cmd);
394}
diff --git a/ui-commit.c b/ui-commit.c
index 9fdb8ee..d6b73ee 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -88,21 +88,29 @@ void cgit_print_commit(char *hex)
88 if (ctx.repo->snapshots) { 88 if (ctx.repo->snapshots) {
89 html("<tr><th>download</th><td colspan='2' class='sha1'>"); 89 html("<tr><th>download</th><td colspan='2' class='sha1'>");
90 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, 90 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
91 hex, ctx.repo->snapshots); 91 hex, ctx.repo->snapshots);
92 html("</td></tr>"); 92 html("</td></tr>");
93 } 93 }
94 html("</table>\n"); 94 html("</table>\n");
95 html("<div class='commit-subject'>"); 95 html("<div class='commit-subject'>");
96 if (ctx.repo->commit_filter)
97 cgit_open_filter(ctx.repo->commit_filter);
96 html_txt(info->subject); 98 html_txt(info->subject);
99 if (ctx.repo->commit_filter)
100 cgit_close_filter(ctx.repo->commit_filter);
97 show_commit_decorations(commit); 101 show_commit_decorations(commit);
98 html("</div>"); 102 html("</div>");
99 html("<div class='commit-msg'>"); 103 html("<div class='commit-msg'>");
104 if (ctx.repo->commit_filter)
105 cgit_open_filter(ctx.repo->commit_filter);
100 html_txt(info->msg); 106 html_txt(info->msg);
107 if (ctx.repo->commit_filter)
108 cgit_close_filter(ctx.repo->commit_filter);
101 html("</div>"); 109 html("</div>");
102 if (parents < 3) { 110 if (parents < 3) {
103 if (parents) 111 if (parents)
104 tmp = sha1_to_hex(commit->parents->item->object.sha1); 112 tmp = sha1_to_hex(commit->parents->item->object.sha1);
105 else 113 else
106 tmp = NULL; 114 tmp = NULL;
107 cgit_print_diff(ctx.qry.sha1, tmp, NULL); 115 cgit_print_diff(ctx.qry.sha1, tmp, NULL);
108 } 116 }
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 5372f5d..4136b3e 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -7,47 +7,26 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13static int write_compressed_tar_archive(struct archiver_args *args,const char *filter) 13static int write_compressed_tar_archive(struct archiver_args *args,const char *filter)
14{ 14{
15 int rw[2];
16 pid_t gzpid;
17 int stdout2;
18 int status;
19 int rv; 15 int rv;
16 struct cgit_filter f;
20 17
21 stdout2 = chk_non_negative(dup(STDIN_FILENO), "Preserving STDOUT before compressing"); 18 f.cmd = xstrdup(filter);
22 chk_zero(pipe(rw), "Opening pipe from compressor subprocess"); 19 f.argv = malloc(2 * sizeof(char *));
23 gzpid = chk_non_negative(fork(), "Forking compressor subprocess"); 20 f.argv[0] = f.cmd;
24 if(gzpid==0) { 21 f.argv[1] = NULL;
25 /* child */ 22 cgit_open_filter(&f);
26 chk_zero(close(rw[1]), "Closing write end of pipe in child");
27 chk_zero(close(STDIN_FILENO), "Closing STDIN");
28 chk_non_negative(dup2(rw[0],STDIN_FILENO), "Redirecting compressor input to stdin");
29 execlp(filter,filter,NULL);
30 _exit(-1);
31 }
32 /* parent */
33 chk_zero(close(rw[0]), "Closing read end of pipe");
34 chk_non_negative(dup2(rw[1],STDOUT_FILENO), "Redirecting output to compressor");
35
36 rv = write_tar_archive(args); 23 rv = write_tar_archive(args);
37 24 cgit_close_filter(&f);
38 chk_zero(close(STDOUT_FILENO), "Closing STDOUT redirected to compressor");
39 chk_non_negative(dup2(stdout2,STDOUT_FILENO), "Restoring uncompressed STDOUT");
40 chk_zero(close(stdout2), "Closing uncompressed STDOUT");
41 chk_zero(close(rw[1]), "Closing write end of pipe in parent");
42 chk_positive(waitpid(gzpid,&status,0), "Waiting on compressor process");
43 if(! ( WIFEXITED(status) && WEXITSTATUS(status)==0 ) )
44 cgit_print_error("Failed to compress archive");
45
46 return rv; 25 return rv;
47} 26}
48 27
49static int write_tar_gzip_archive(struct archiver_args *args) 28static int write_tar_gzip_archive(struct archiver_args *args)
50{ 29{
51 return write_compressed_tar_archive(args,"gzip"); 30 return write_compressed_tar_archive(args,"gzip");
52} 31}
53 32
diff --git a/ui-tree.c b/ui-tree.c
index 61fcf5a..c608754 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -10,23 +10,33 @@
10#include "cgit.h" 10#include "cgit.h"
11#include "html.h" 11#include "html.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13 13
14char *curr_rev; 14char *curr_rev;
15char *match_path; 15char *match_path;
16int header = 0; 16int header = 0;
17 17
18static void print_text_buffer(char *buf, unsigned long size) 18static 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.repo->source_filter) {
26 html("<tr><td class='lines'><pre><code>");
27 ctx.repo->source_filter->argv[1] = xstrdup(name);
28 cgit_open_filter(ctx.repo->source_filter);
29 write(STDOUT_FILENO, buf, size);
30 cgit_close_filter(ctx.repo->source_filter);
31 html("</code></pre></td></tr></table>\n");
32 return;
33 }
34
25 html("<tr><td class='linenumbers'><pre>"); 35 html("<tr><td class='linenumbers'><pre>");
26 idx = 0; 36 idx = 0;
27 lineno = 0; 37 lineno = 0;
28 38
29 if (size) { 39 if (size) {
30 htmlf(numberfmt, ++lineno); 40 htmlf(numberfmt, ++lineno);
31 while(idx < size - 1) { // skip absolute last newline 41 while(idx < size - 1) { // skip absolute last newline
32 if (buf[idx] == '\n') 42 if (buf[idx] == '\n')
@@ -60,17 +70,17 @@ static void print_binary_buffer(char *buf, unsigned long size)
60 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; 70 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.';
61 ascii[idx] = '\0'; 71 ascii[idx] = '\0';
62 html_txt(ascii); 72 html_txt(ascii);
63 html("</td></tr>\n"); 73 html("</td></tr>\n");
64 } 74 }
65 html("</table>\n"); 75 html("</table>\n");
66} 76}
67 77
68static void print_object(const unsigned char *sha1, char *path) 78static void print_object(const unsigned char *sha1, char *path, const char *basename)
69{ 79{
70 enum object_type type; 80 enum object_type type;
71 char *buf; 81 char *buf;
72 unsigned long size; 82 unsigned long size;
73 83
74 type = sha1_object_info(sha1, &size); 84 type = sha1_object_info(sha1, &size);
75 if (type == OBJ_BAD) { 85 if (type == OBJ_BAD) {
76 cgit_print_error(fmt("Bad object name: %s", 86 cgit_print_error(fmt("Bad object name: %s",
@@ -88,17 +98,17 @@ static void print_object(const unsigned char *sha1, char *path)
88 html(" ("); 98 html(" (");
89 cgit_plain_link("plain", NULL, NULL, ctx.qry.head, 99 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
90 curr_rev, path); 100 curr_rev, path);
91 htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1)); 101 htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
92 102
93 if (buffer_is_binary(buf, size)) 103 if (buffer_is_binary(buf, size))
94 print_binary_buffer(buf, size); 104 print_binary_buffer(buf, size);
95 else 105 else
96 print_text_buffer(buf, size); 106 print_text_buffer(basename, buf, size);
97} 107}
98 108
99 109
100static int ls_item(const unsigned char *sha1, const char *base, int baselen, 110static int ls_item(const unsigned char *sha1, const char *base, int baselen,
101 const char *pathname, unsigned int mode, int stage, 111 const char *pathname, unsigned int mode, int stage,
102 void *cbdata) 112 void *cbdata)
103{ 113{
104 char *name; 114 char *name;
@@ -214,17 +224,17 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
214 if (strcmp(match_path, buffer)) 224 if (strcmp(match_path, buffer))
215 return READ_TREE_RECURSIVE; 225 return READ_TREE_RECURSIVE;
216 226
217 if (S_ISDIR(mode)) { 227 if (S_ISDIR(mode)) {
218 state = 1; 228 state = 1;
219 ls_head(); 229 ls_head();
220 return READ_TREE_RECURSIVE; 230 return READ_TREE_RECURSIVE;
221 } else { 231 } else {
222 print_object(sha1, buffer); 232 print_object(sha1, buffer, pathname);
223 return 0; 233 return 0;
224 } 234 }
225 } 235 }
226 ls_item(sha1, base, baselen, pathname, mode, stage, NULL); 236 ls_item(sha1, base, baselen, pathname, mode, stage, NULL);
227 return 0; 237 return 0;
228} 238}
229 239
230 240