diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-01-13 11:56:50 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-01-14 10:00:07 (JST) |
commit | 800380dde797ae35d738a644acdae2fabb9a0d44 (patch) | |
tree | 4770bb2a3eb10021f5d527200ad61a2659a78bea | |
parent | f43b228d0bca5791be98ff3fbb2f8743219635b6 (diff) | |
download | cgit-800380dde797ae35d738a644acdae2fabb9a0d44.zip cgit-800380dde797ae35d738a644acdae2fabb9a0d44.tar.gz |
filter: return on null filter from open and close
So that we don't have to include the if(filter) open_filter(filter)
block everywhere, we introduce the guard in the function itself. This
should simplify quite a bit of code.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | filter.c | 4 | ||||
-rw-r--r-- | ui-commit.c | 18 | ||||
-rw-r--r-- | ui-repolist.c | 6 | ||||
-rw-r--r-- | ui-summary.c | 8 |
4 files changed, 14 insertions, 22 deletions
@@ -351,6 +351,8 @@ int cgit_open_filter(struct cgit_filter *filter, ...) | |||
351 | { | 351 | { |
352 | int result; | 352 | int result; |
353 | va_list ap; | 353 | va_list ap; |
354 | if (!filter) | ||
355 | return 0; | ||
354 | va_start(ap, filter); | 356 | va_start(ap, filter); |
355 | result = filter->open(filter, ap); | 357 | result = filter->open(filter, ap); |
356 | va_end(ap); | 358 | va_end(ap); |
@@ -359,6 +361,8 @@ int cgit_open_filter(struct cgit_filter *filter, ...) | |||
359 | 361 | ||
360 | int cgit_close_filter(struct cgit_filter *filter) | 362 | int cgit_close_filter(struct cgit_filter *filter) |
361 | { | 363 | { |
364 | if (!filter) | ||
365 | return 0; | ||
362 | return filter->close(filter); | 366 | return filter->close(filter); |
363 | } | 367 | } |
364 | 368 | ||
diff --git a/ui-commit.c b/ui-commit.c index aa1892f..5ac79c0 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -107,28 +107,22 @@ void cgit_print_commit(char *hex, const char *prefix) | |||
107 | } | 107 | } |
108 | html("</table>\n"); | 108 | html("</table>\n"); |
109 | html("<div class='commit-subject'>"); | 109 | html("<div class='commit-subject'>"); |
110 | if (ctx.repo->commit_filter) | 110 | cgit_open_filter(ctx.repo->commit_filter); |
111 | cgit_open_filter(ctx.repo->commit_filter); | ||
112 | html_txt(info->subject); | 111 | html_txt(info->subject); |
113 | if (ctx.repo->commit_filter) | 112 | cgit_close_filter(ctx.repo->commit_filter); |
114 | cgit_close_filter(ctx.repo->commit_filter); | ||
115 | show_commit_decorations(commit); | 113 | show_commit_decorations(commit); |
116 | html("</div>"); | 114 | html("</div>"); |
117 | html("<div class='commit-msg'>"); | 115 | html("<div class='commit-msg'>"); |
118 | if (ctx.repo->commit_filter) | 116 | cgit_open_filter(ctx.repo->commit_filter); |
119 | cgit_open_filter(ctx.repo->commit_filter); | ||
120 | html_txt(info->msg); | 117 | html_txt(info->msg); |
121 | if (ctx.repo->commit_filter) | 118 | cgit_close_filter(ctx.repo->commit_filter); |
122 | cgit_close_filter(ctx.repo->commit_filter); | ||
123 | html("</div>"); | 119 | html("</div>"); |
124 | if (notes.len != 0) { | 120 | if (notes.len != 0) { |
125 | html("<div class='notes-header'>Notes</div>"); | 121 | html("<div class='notes-header'>Notes</div>"); |
126 | html("<div class='notes'>"); | 122 | html("<div class='notes'>"); |
127 | if (ctx.repo->commit_filter) | 123 | cgit_open_filter(ctx.repo->commit_filter); |
128 | cgit_open_filter(ctx.repo->commit_filter); | ||
129 | html_txt(notes.buf); | 124 | html_txt(notes.buf); |
130 | if (ctx.repo->commit_filter) | 125 | cgit_close_filter(ctx.repo->commit_filter); |
131 | cgit_close_filter(ctx.repo->commit_filter); | ||
132 | html("</div>"); | 126 | html("</div>"); |
133 | html("<div class='notes-footer'></div>"); | 127 | html("<div class='notes-footer'></div>"); |
134 | } | 128 | } |
diff --git a/ui-repolist.c b/ui-repolist.c index 7b1fec3..f9cb21a 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -333,9 +333,7 @@ void cgit_print_site_readme() | |||
333 | { | 333 | { |
334 | if (!ctx.cfg.root_readme) | 334 | if (!ctx.cfg.root_readme) |
335 | return; | 335 | return; |
336 | if (ctx.cfg.about_filter) | 336 | cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); |
337 | cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); | ||
338 | html_include(ctx.cfg.root_readme); | 337 | html_include(ctx.cfg.root_readme); |
339 | if (ctx.cfg.about_filter) | 338 | cgit_close_filter(ctx.cfg.about_filter); |
340 | cgit_close_filter(ctx.cfg.about_filter); | ||
341 | } | 339 | } |
diff --git a/ui-summary.c b/ui-summary.c index 725f3ab..ddd8f1b 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -151,16 +151,12 @@ void cgit_print_repo_readme(char *path) | |||
151 | * filesystem, while applying the about-filter. | 151 | * filesystem, while applying the about-filter. |
152 | */ | 152 | */ |
153 | html("<div id='summary'>"); | 153 | html("<div id='summary'>"); |
154 | if (ctx.repo->about_filter) | 154 | cgit_open_filter(ctx.repo->about_filter, filename); |
155 | cgit_open_filter(ctx.repo->about_filter, filename); | ||
156 | |||
157 | if (ref) | 155 | if (ref) |
158 | cgit_print_file(filename, ref, 1); | 156 | cgit_print_file(filename, ref, 1); |
159 | else | 157 | else |
160 | html_include(filename); | 158 | html_include(filename); |
161 | 159 | cgit_close_filter(ctx.repo->about_filter); | |
162 | if (ctx.repo->about_filter) | ||
163 | cgit_close_filter(ctx.repo->about_filter); | ||
164 | 160 | ||
165 | html("</div>"); | 161 | html("</div>"); |
166 | if (free_filename) | 162 | if (free_filename) |