diff options
author | Jason A. Donenfeld | 2013-05-25 14:50:19 +0200 |
---|---|---|
committer | Jason A. Donenfeld | 2013-05-25 20:33:28 +0200 |
commit | c0dfaf1c281d0697ce43131343d7a9f170a61ff9 (patch) | |
tree | e52a47596e72d9a7f1ebb19fd4fe5b3a39d95567 | |
parent | 3cb5d86dc68bab4883bf5a7cbc90f3e266237355 (diff) | |
download | cgit-c0dfaf1c281d0697ce43131343d7a9f170a61ff9.tar.gz cgit-c0dfaf1c281d0697ce43131343d7a9f170a61ff9.tar.bz2 cgit-c0dfaf1c281d0697ce43131343d7a9f170a61ff9.zip |
ui-summary: Pass filename to about-filter
This gives the about-filter API the same semantics as source-filter,
where the filter receives the filename so it can decide what to do next
with it.
While we're at it, plug a memory leak.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgitrc.5.txt | 8 | ||||
-rw-r--r-- | ui-repolist.c | 8 | ||||
-rw-r--r-- | ui-summary.c | 12 |
4 files changed, 22 insertions, 8 deletions
@@ -37,10 +37,10 @@ static struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) | |||
37 | 37 | ||
38 | switch (filtertype) { | 38 | switch (filtertype) { |
39 | case SOURCE: | 39 | case SOURCE: |
40 | case ABOUT: | ||
40 | extra_args = 1; | 41 | extra_args = 1; |
41 | break; | 42 | break; |
42 | 43 | ||
43 | case ABOUT: | ||
44 | case COMMIT: | 44 | case COMMIT: |
45 | default: | 45 | default: |
46 | extra_args = 0; | 46 | extra_args = 0; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 8a0a9c9..ea0bbe7 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -542,9 +542,11 @@ config files, e.g. "repo.desc" becomes "desc". | |||
542 | FILTER API | 542 | FILTER API |
543 | ---------- | 543 | ---------- |
544 | about filter:: | 544 | about filter:: |
545 | This filter is given no arguments. The about text that is to be | 545 | This filter is given a single parameter: the filename of the source |
546 | filtered is available on standard input and the filtered text is | 546 | file to filter. The filter can use the filename to determine (for |
547 | expected on standard output. | 547 | example) the type of syntax to follow when formatting the readme file. |
548 | The about text that is to be filtered is available on standard input | ||
549 | and the filtered text is expected on standard output. | ||
548 | 550 | ||
549 | commit filter:: | 551 | commit filter:: |
550 | This filter is given no arguments. The commit message text that is to | 552 | This filter is given no arguments. The commit message text that is to |
diff --git a/ui-repolist.c b/ui-repolist.c index 47ca997..2ab6e9e 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -332,9 +332,13 @@ void cgit_print_site_readme() | |||
332 | { | 332 | { |
333 | if (!ctx.cfg.root_readme) | 333 | if (!ctx.cfg.root_readme) |
334 | return; | 334 | return; |
335 | if (ctx.cfg.about_filter) | 335 | if (ctx.cfg.about_filter) { |
336 | ctx.cfg.about_filter->argv[1] = ctx.cfg.root_readme; | ||
336 | cgit_open_filter(ctx.cfg.about_filter); | 337 | cgit_open_filter(ctx.cfg.about_filter); |
338 | } | ||
337 | html_include(ctx.cfg.root_readme); | 339 | html_include(ctx.cfg.root_readme); |
338 | if (ctx.cfg.about_filter) | 340 | if (ctx.cfg.about_filter) { |
339 | cgit_close_filter(ctx.cfg.about_filter); | 341 | cgit_close_filter(ctx.cfg.about_filter); |
342 | ctx.cfg.about_filter->argv[1] = NULL; | ||
343 | } | ||
340 | } | 344 | } |
diff --git a/ui-summary.c b/ui-summary.c index abf914e..ffad4f2 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -98,6 +98,7 @@ void cgit_print_summary() | |||
98 | void cgit_print_repo_readme(char *path) | 98 | void cgit_print_repo_readme(char *path) |
99 | { | 99 | { |
100 | char *slash, *tmp, *colon, *ref; | 100 | char *slash, *tmp, *colon, *ref; |
101 | int free_filename = 0; | ||
101 | 102 | ||
102 | if (!ctx.repo->readme || !(*ctx.repo->readme)) | 103 | if (!ctx.repo->readme || !(*ctx.repo->readme)) |
103 | return; | 104 | return; |
@@ -134,6 +135,7 @@ void cgit_print_repo_readme(char *path) | |||
134 | return; | 135 | return; |
135 | slash = colon; | 136 | slash = colon; |
136 | } | 137 | } |
138 | free_filename = 1; | ||
137 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); | 139 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); |
138 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); | 140 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); |
139 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); | 141 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); |
@@ -144,13 +146,19 @@ void cgit_print_repo_readme(char *path) | |||
144 | * filesystem, while applying the about-filter. | 146 | * filesystem, while applying the about-filter. |
145 | */ | 147 | */ |
146 | html("<div id='summary'>"); | 148 | html("<div id='summary'>"); |
147 | if (ctx.repo->about_filter) | 149 | if (ctx.repo->about_filter) { |
150 | ctx.repo->about_filter->argv[1] = tmp; | ||
148 | cgit_open_filter(ctx.repo->about_filter); | 151 | cgit_open_filter(ctx.repo->about_filter); |
152 | } | ||
149 | if (ref) | 153 | if (ref) |
150 | cgit_print_file(tmp, ref); | 154 | cgit_print_file(tmp, ref); |
151 | else | 155 | else |
152 | html_include(tmp); | 156 | html_include(tmp); |
153 | if (ctx.repo->about_filter) | 157 | if (ctx.repo->about_filter) { |
154 | cgit_close_filter(ctx.repo->about_filter); | 158 | cgit_close_filter(ctx.repo->about_filter); |
159 | ctx.repo->about_filter->argv[1] = NULL; | ||
160 | } | ||
155 | html("</div>"); | 161 | html("</div>"); |
162 | if (free_filename) | ||
163 | free(tmp); | ||
156 | } | 164 | } |