aboutsummaryrefslogtreecommitdiffstats
path: root/ui-diff.c
diff options
context:
space:
mode:
authorLars Hjemli2011-03-06 23:59:56 +0100
committerLars Hjemli2011-03-06 23:59:56 +0100
commit962a24892feb9e3d69542bcf0a219dc14836e921 (patch)
tree991b67cd914a708d83f08dd7f859a9cadbb74490 /ui-diff.c
parent1a64fd2f83affda41fb9903b7c299d35170bfc05 (diff)
downloadcgit-962a24892feb9e3d69542bcf0a219dc14836e921.tar.gz
cgit-962a24892feb9e3d69542bcf0a219dc14836e921.tar.bz2
cgit-962a24892feb9e3d69542bcf0a219dc14836e921.zip
ui-diff.c: create a control panel for diff options
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-diff.c')
-rw-r--r--ui-diff.c83
1 files changed, 54 insertions, 29 deletions
diff --git a/ui-diff.c b/ui-diff.c
index a7bc667..b7767b3 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -167,7 +167,7 @@ static void inspect_filepair(struct diff_filepair *pair)
167void cgit_print_diffstat(const unsigned char *old_sha1, 167void cgit_print_diffstat(const unsigned char *old_sha1,
168 const unsigned char *new_sha1, const char *prefix) 168 const unsigned char *new_sha1, const char *prefix)
169{ 169{
170 int i, save_context = ctx.qry.context; 170 int i;
171 171
172 html("<div class='diffstat-header'>"); 172 html("<div class='diffstat-header'>");
173 cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, 173 cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
@@ -177,19 +177,6 @@ void cgit_print_diffstat(const unsigned char *old_sha1,
177 html_txt(prefix); 177 html_txt(prefix);
178 html("')"); 178 html("')");
179 } 179 }
180 html(" (");
181 ctx.qry.context = (save_context > 0 ? save_context : 3) << 1;
182 cgit_self_link("more", NULL, NULL, &ctx);
183 html("/");
184 ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1;
185 cgit_self_link("less", NULL, NULL, &ctx);
186 ctx.qry.context = save_context;
187 html(" context)");
188 html(" (");
189 ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
190 cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx);
191 ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
192 html(" whitespace changes)");
193 html("</div>"); 180 html("</div>");
194 html("<table summary='diffstat' class='diffstat'>"); 181 html("<table summary='diffstat' class='diffstat'>");
195 max_changes = 0; 182 max_changes = 0;
@@ -278,19 +265,6 @@ static void header(unsigned char *sha1, char *path1, int mode1,
278 html("</div>"); 265 html("</div>");
279} 266}
280 267
281static void print_ssdiff_link()
282{
283 if (!strcmp(ctx.qry.page, "diff")) {
284 if (use_ssdiff)
285 cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head,
286 ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1);
287 else
288 cgit_diff_link("Side-by-side diff", NULL, NULL,
289 ctx.qry.head, ctx.qry.sha1,
290 ctx.qry.sha2, ctx.qry.path, 1);
291 }
292}
293
294static void filepair_cb(struct diff_filepair *pair) 268static void filepair_cb(struct diff_filepair *pair)
295{ 269{
296 unsigned long old_size = 0; 270 unsigned long old_size = 0;
@@ -330,7 +304,56 @@ static void filepair_cb(struct diff_filepair *pair)
330 cgit_ssdiff_footer(); 304 cgit_ssdiff_footer();
331} 305}
332 306
333void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 307void cgit_print_diff_ctrls()
308{
309 int i, curr;
310
311 html("<div class='cgit-panel'>");
312 html("<b>diff options</b>");
313 html("<form method='get' action='.'>");
314 cgit_add_hidden_formfields(1, 0, ctx.qry.page);
315 html("<table>");
316 html("<tr><td colspan='2'/></tr>");
317 html("<tr>");
318 html("<td class='label'>context:</td>");
319 html("<td class='ctrl'>");
320 html("<select name='context' onchange='this.form.submit();'>");
321 curr = ctx.qry.context;
322 if (!curr)
323 curr = 3;
324 for (i = 1; i <= 10; i++)
325 html_intoption(i, fmt("%d", i), curr);
326 for (i = 15; i <= 40; i += 5)
327 html_intoption(i, fmt("%d", i), curr);
328 html("</select>");
329 html("</td>");
330 html("</tr><tr>");
331 html("<td class='label'>space:</td>");
332 html("<td class='ctrl'>");
333 html("<select name='ignorews' onchange='this.form.submit();'>");
334 html_intoption(0, "include", ctx.qry.ignorews);
335 html_intoption(1, "ignore", ctx.qry.ignorews);
336 html("</select>");
337 html("</td>");
338 html("</tr><tr>");
339 html("<td class='label'>mode:</td>");
340 html("<td class='ctrl'>");
341 html("<select name='ss' onchange='this.form.submit();'>");
342 curr = ctx.qry.ssdiff;
343 if (!curr && ctx.cfg.ssdiff)
344 curr = 1;
345 html_intoption(0, "unified", curr);
346 html_intoption(1, "ssdiff", curr);
347 html("</select></td></tr>");
348 html("<tr><td/><td class='ctrl'>");
349 html("<noscript><input type='submit' value='reload'/></noscript>");
350 html("</td></tr></table>");
351 html("</form>");
352 html("</div>");
353}
354
355void cgit_print_diff(const char *new_rev, const char *old_rev,
356 const char *prefix, int show_ctrls)
334{ 357{
335 enum object_type type; 358 enum object_type type;
336 unsigned long size; 359 unsigned long size;
@@ -369,7 +392,9 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
369 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) 392 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
370 use_ssdiff = 1; 393 use_ssdiff = 1;
371 394
372 print_ssdiff_link(); 395 if (show_ctrls)
396 cgit_print_diff_ctrls();
397
373 cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); 398 cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
374 399
375 if (use_ssdiff) { 400 if (use_ssdiff) {