author | Ragnar Ouchterlony <ragnar@lysator.liu.se> | 2009-09-15 17:44:37 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-09-16 18:17:56 (UTC) |
commit | 207cc34711039329b41345f716bf421a88a6fd0a (patch) (unidiff) | |
tree | 5fb56c7e5c105c9045e52abd971013270db23368 | |
parent | c358aa3dfebf4fc1f3005dd960aa5c1c020eed76 (diff) | |
download | cgit-207cc34711039329b41345f716bf421a88a6fd0a.zip cgit-207cc34711039329b41345f716bf421a88a6fd0a.tar.gz cgit-207cc34711039329b41345f716bf421a88a6fd0a.tar.bz2 |
Polishing of how the side-by-side diff looks.
Aligned all different files, so that all side-by-side tables look
the same. Also made sure that the tables take up the whole browser
width.
Also various changes to the css to make things easier on the eye.
Signed-off-by: Ragnar Ouchterlony <ragnar@lysator.liu.se>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.css | 66 | ||||
-rw-r--r-- | ui-diff.c | 27 | ||||
-rw-r--r-- | ui-ssdiff.c | 30 | ||||
-rw-r--r-- | ui-ssdiff.h | 3 |
4 files changed, 96 insertions, 30 deletions
@@ -597,42 +597,96 @@ table.hgraph td { | |||
597 | padding: 2px 2px; | 597 | padding: 2px 2px; |
598 | } | 598 | } |
599 | 599 | ||
600 | table.hgraph div.bar { | 600 | table.hgraph div.bar { |
601 | background-color: #eee; | 601 | background-color: #eee; |
602 | height: 1em; | 602 | height: 1em; |
603 | } | 603 | } |
604 | 604 | ||
605 | table.ssdiff { | ||
606 | width: 100%; | ||
607 | } | ||
608 | |||
609 | table.ssdiff td { | ||
610 | font-size: 75%; | ||
611 | font-family: monospace; | ||
612 | white-space: pre; | ||
613 | padding: 1px 4px 1px 4px; | ||
614 | border-left: solid 1px #aaa; | ||
615 | border-right: solid 1px #aaa; | ||
616 | } | ||
617 | |||
605 | table.ssdiff td.add { | 618 | table.ssdiff td.add { |
606 | color: black; | 619 | color: black; |
607 | background: #afa; | 620 | background: #cfc; |
621 | min-width: 50%; | ||
608 | } | 622 | } |
609 | 623 | ||
610 | table.ssdiff td.add_dark { | 624 | table.ssdiff td.add_dark { |
611 | color: black; | 625 | color: black; |
612 | background: #9c9; | 626 | background: #aca; |
627 | min-width: 50%; | ||
613 | } | 628 | } |
614 | 629 | ||
615 | table.ssdiff td.del { | 630 | table.ssdiff td.del { |
616 | color: black; | 631 | color: black; |
617 | background: #faa; | 632 | background: #fcc; |
633 | min-width: 50%; | ||
618 | } | 634 | } |
619 | 635 | ||
620 | table.ssdiff td.del_dark { | 636 | table.ssdiff td.del_dark { |
621 | color: black; | 637 | color: black; |
622 | background: #c99; | 638 | background: #caa; |
639 | min-width: 50%; | ||
623 | } | 640 | } |
624 | 641 | ||
625 | table.ssdiff td.changed { | 642 | table.ssdiff td.changed { |
626 | color: black; | 643 | color: black; |
627 | background: #ffa; | 644 | background: #ffc; |
645 | min-width: 50%; | ||
628 | } | 646 | } |
629 | 647 | ||
630 | table.ssdiff td.changed_dark { | 648 | table.ssdiff td.changed_dark { |
631 | color: black; | 649 | color: black; |
632 | background: #cc9; | 650 | background: #cca; |
651 | min-width: 50%; | ||
652 | } | ||
653 | |||
654 | table.ssdiff td.lineno { | ||
655 | color: black; | ||
656 | background: #eee; | ||
657 | text-align: right; | ||
658 | width: 3em; | ||
659 | min-width: 3em; | ||
633 | } | 660 | } |
634 | 661 | ||
635 | table.ssdiff td.hunk { | 662 | table.ssdiff td.hunk { |
636 | color: #black; | 663 | color: #black; |
637 | background: #ccf; | 664 | background: #ccf; |
665 | border-top: solid 1px #aaa; | ||
666 | border-bottom: solid 1px #aaa; | ||
638 | } | 667 | } |
668 | |||
669 | table.ssdiff td.head { | ||
670 | border-top: solid 1px #aaa; | ||
671 | border-bottom: solid 1px #aaa; | ||
672 | } | ||
673 | |||
674 | table.ssdiff td.head div.head { | ||
675 | font-weight: bold; | ||
676 | color: black; | ||
677 | } | ||
678 | |||
679 | table.ssdiff td.foot { | ||
680 | border-top: solid 1px #aaa; | ||
681 | border-left: none; | ||
682 | border-right: none; | ||
683 | border-bottom: none; | ||
684 | } | ||
685 | |||
686 | table.ssdiff td.space { | ||
687 | border: none; | ||
688 | } | ||
689 | |||
690 | table.ssdiff td.space div { | ||
691 | min-height: 3em; | ||
692 | } \ No newline at end of file | ||
@@ -241,18 +241,16 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
241 | html("<br/>+++ b/"); | 241 | html("<br/>+++ b/"); |
242 | if (mode2 != 0) | 242 | if (mode2 != 0) |
243 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, | 243 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
244 | sha1_to_hex(new_rev_sha1), path2); | 244 | sha1_to_hex(new_rev_sha1), path2); |
245 | else | 245 | else |
246 | html_txt(path2); | 246 | html_txt(path2); |
247 | } | 247 | } |
248 | html("</div>"); | 248 | html("</div>"); |
249 | if (use_ssdiff) | ||
250 | cgit_ssdiff_header(); | ||
251 | } | 249 | } |
252 | 250 | ||
253 | static void print_ssdiff_link() | 251 | static void print_ssdiff_link() |
254 | { | 252 | { |
255 | if (!strcmp(ctx.qry.page, "diff")) { | 253 | if (!strcmp(ctx.qry.page, "diff")) { |
256 | if (use_ssdiff) | 254 | if (use_ssdiff) |
257 | cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head, | 255 | cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head, |
258 | ctx.qry.sha1, ctx.qry.sha2, NULL, 1); | 256 | ctx.qry.sha1, ctx.qry.sha2, NULL, 1); |
@@ -265,34 +263,36 @@ static void print_ssdiff_link() | |||
265 | 263 | ||
266 | static void filepair_cb(struct diff_filepair *pair) | 264 | static void filepair_cb(struct diff_filepair *pair) |
267 | { | 265 | { |
268 | unsigned long old_size = 0; | 266 | unsigned long old_size = 0; |
269 | unsigned long new_size = 0; | 267 | unsigned long new_size = 0; |
270 | int binary = 0; | 268 | int binary = 0; |
271 | linediff_fn print_line_fn = print_line; | 269 | linediff_fn print_line_fn = print_line; |
272 | 270 | ||
273 | header(pair->one->sha1, pair->one->path, pair->one->mode, | ||
274 | pair->two->sha1, pair->two->path, pair->two->mode); | ||
275 | if (use_ssdiff) { | 271 | if (use_ssdiff) { |
276 | cgit_ssdiff_header(); | 272 | cgit_ssdiff_header_begin(); |
277 | print_line_fn = cgit_ssdiff_line_cb; | 273 | print_line_fn = cgit_ssdiff_line_cb; |
278 | } | 274 | } |
275 | header(pair->one->sha1, pair->one->path, pair->one->mode, | ||
276 | pair->two->sha1, pair->two->path, pair->two->mode); | ||
277 | if (use_ssdiff) | ||
278 | cgit_ssdiff_header_end(); | ||
279 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | 279 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
280 | if (S_ISGITLINK(pair->one->mode)) | 280 | if (S_ISGITLINK(pair->one->mode)) |
281 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | 281 | print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
282 | if (S_ISGITLINK(pair->two->mode)) | 282 | if (S_ISGITLINK(pair->two->mode)) |
283 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | 283 | print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
284 | return; | 284 | return; |
285 | } | 285 | } |
286 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | 286 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
287 | &new_size, &binary, print_line_fn)) | 287 | &new_size, &binary, print_line_fn)) |
288 | cgit_print_error("Error running diff"); | 288 | cgit_print_error("Error running diff"); |
289 | if (binary) | 289 | if (binary) |
290 | html("Binary files differ"); | 290 | print_line_fn(" Binary files differ", 20); |
291 | if (use_ssdiff) | 291 | if (use_ssdiff) |
292 | cgit_ssdiff_footer(); | 292 | cgit_ssdiff_footer(); |
293 | } | 293 | } |
294 | 294 | ||
295 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) | 295 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) |
296 | { | 296 | { |
297 | enum object_type type; | 297 | enum object_type type; |
298 | unsigned long size; | 298 | unsigned long size; |
@@ -329,14 +329,19 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi | |||
329 | } | 329 | } |
330 | 330 | ||
331 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | 331 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) |
332 | use_ssdiff = 1; | 332 | use_ssdiff = 1; |
333 | 333 | ||
334 | print_ssdiff_link(); | 334 | print_ssdiff_link(); |
335 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1); | 335 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1); |
336 | 336 | ||
337 | html("<table summary='diff' class='diff'>"); | 337 | if (use_ssdiff) { |
338 | html("<tr><td>"); | 338 | html("<table summary='ssdiff' class='ssdiff'>"); |
339 | } else { | ||
340 | html("<table summary='diff' class='diff'>"); | ||
341 | html("<tr><td>"); | ||
342 | } | ||
339 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); | 343 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); |
340 | html("</td></tr>"); | 344 | if (!use_ssdiff) |
345 | html("</td></tr>"); | ||
341 | html("</table>"); | 346 | html("</table>"); |
342 | } | 347 | } |
diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 3591ab4..8215051 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c | |||
@@ -35,32 +35,32 @@ static int line_from_hunk(char *line, char type) | |||
35 | free(buf2); | 35 | free(buf2); |
36 | return res; | 36 | return res; |
37 | } | 37 | } |
38 | 38 | ||
39 | static char *replace_tabs(char *line) | 39 | static char *replace_tabs(char *line) |
40 | { | 40 | { |
41 | char *prev_buf = line; | 41 | char *prev_buf = line; |
42 | char *cur_buf; | 42 | char *cur_buf; |
43 | int linelen = strlen(line); | 43 | int linelen = strlen(line); |
44 | int n_tabs = 0; | 44 | int n_tabs = 0; |
45 | int i; | 45 | int i; |
46 | char *result; | 46 | char *result; |
47 | char *spaces = " "; | 47 | char *spaces = " "; |
48 | 48 | ||
49 | if (linelen == 0) { | 49 | if (linelen == 0) { |
50 | result = xmalloc(1); | 50 | result = xmalloc(1); |
51 | result[0] = '\0'; | 51 | result[0] = '\0'; |
52 | return result; | 52 | return result; |
53 | } | 53 | } |
54 | 54 | ||
55 | for (i = 0; i < linelen; i++) | 55 | for (i = 0; i < linelen; i++) |
56 | if (line[i] == '\t') | 56 | if (line[i] == '\t') |
57 | n_tabs += 1; | 57 | n_tabs += 1; |
58 | result = xmalloc(linelen + n_tabs * 8 + 1); | 58 | result = xmalloc(linelen + n_tabs * 8 + 1); |
59 | result[0] = '\0'; | 59 | result[0] = '\0'; |
60 | 60 | ||
61 | while (1) { | 61 | while (1) { |
62 | cur_buf = strchr(prev_buf, '\t'); | 62 | cur_buf = strchr(prev_buf, '\t'); |
63 | if (!cur_buf) { | 63 | if (!cur_buf) { |
64 | strcat(result, prev_buf); | 64 | strcat(result, prev_buf); |
65 | break; | 65 | break; |
66 | } else { | 66 | } else { |
@@ -101,34 +101,34 @@ static void deferred_new_add(char *line, int line_no) | |||
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
104 | static void print_ssdiff_line(char *class, int old_line_no, char *old_line, | 104 | static void print_ssdiff_line(char *class, int old_line_no, char *old_line, |
105 | int new_line_no, char *new_line) | 105 | int new_line_no, char *new_line) |
106 | { | 106 | { |
107 | html("<tr>"); | 107 | html("<tr>"); |
108 | if (old_line_no > 0) | 108 | if (old_line_no > 0) |
109 | htmlf("<td class='%s'>%d </td><td class='%s'>", class, | 109 | htmlf("<td class='lineno'>%d</td><td class='%s'>", |
110 | old_line_no, class); | 110 | old_line_no, class); |
111 | else | 111 | else |
112 | htmlf("<td class='%s_dark'> </td><td class='%s_dark'>", class, class); | 112 | htmlf("<td class='lineno'></td><td class='%s_dark'>", class); |
113 | 113 | ||
114 | if (old_line) { | 114 | if (old_line) { |
115 | old_line = replace_tabs(old_line + 1); | 115 | old_line = replace_tabs(old_line + 1); |
116 | html_txt(old_line); | 116 | html_txt(old_line); |
117 | free(old_line); | 117 | free(old_line); |
118 | } | 118 | } |
119 | 119 | ||
120 | html(" </td>"); | 120 | html("</td>"); |
121 | 121 | ||
122 | if (new_line_no > 0) | 122 | if (new_line_no > 0) |
123 | htmlf("<td class='%s'> %d </td><td class='%s'>", class, | 123 | htmlf("<td class='lineno'>%d</td><td class='%s'>", |
124 | new_line_no, class); | 124 | new_line_no, class); |
125 | else | 125 | else |
126 | htmlf("<td class='%s_dark'> </td><td class='%s_dark'>", class, class); | 126 | htmlf("<td class='lineno'></td><td class='%s_dark'>", class); |
127 | 127 | ||
128 | if (new_line) { | 128 | if (new_line) { |
129 | new_line = replace_tabs(new_line + 1); | 129 | new_line = replace_tabs(new_line + 1); |
130 | html_txt(new_line); | 130 | html_txt(new_line); |
131 | free(new_line); | 131 | free(new_line); |
132 | } | 132 | } |
133 | 133 | ||
134 | html("</td></tr>"); | 134 | html("</td></tr>"); |
@@ -244,21 +244,27 @@ void cgit_ssdiff_line_cb(char *line, int len) | |||
244 | } else { | 244 | } else { |
245 | html("<tr><td colspan='4' class='ctx'>"); | 245 | html("<tr><td colspan='4' class='ctx'>"); |
246 | html_txt(line); | 246 | html_txt(line); |
247 | html("</td></tr>"); | 247 | html("</td></tr>"); |
248 | } | 248 | } |
249 | line[len - 1] = c; | 249 | line[len - 1] = c; |
250 | } | 250 | } |
251 | 251 | ||
252 | void cgit_ssdiff_header() | 252 | void cgit_ssdiff_header_begin() |
253 | { | 253 | { |
254 | current_old_line = 0; | 254 | current_old_line = 0; |
255 | current_new_line = 0; | 255 | current_new_line = 0; |
256 | html("<table class='ssdiff'>"); | 256 | html("<tr><td class='space' colspan='4'><div></div></td></tr>"); |
257 | html("<tr><td class='head' colspan='4'>"); | ||
258 | } | ||
259 | |||
260 | void cgit_ssdiff_header_end() | ||
261 | { | ||
262 | html("</td><tr>"); | ||
257 | } | 263 | } |
258 | 264 | ||
259 | void cgit_ssdiff_footer() | 265 | void cgit_ssdiff_footer() |
260 | { | 266 | { |
261 | if (deferred_old || deferred_new) | 267 | if (deferred_old || deferred_new) |
262 | cgit_ssdiff_print_deferred_lines(); | 268 | cgit_ssdiff_print_deferred_lines(); |
263 | html("</table>"); | 269 | html("<tr><td class='foot' colspan='4'></td></tr>"); |
264 | } | 270 | } |
diff --git a/ui-ssdiff.h b/ui-ssdiff.h index a0b1efe..64b4b12 100644 --- a/ui-ssdiff.h +++ b/ui-ssdiff.h | |||
@@ -1,12 +1,13 @@ | |||
1 | #ifndef UI_SSDIFF_H | 1 | #ifndef UI_SSDIFF_H |
2 | #define UI_SSDIFF_H | 2 | #define UI_SSDIFF_H |
3 | 3 | ||
4 | extern void cgit_ssdiff_print_deferred_lines(); | 4 | extern void cgit_ssdiff_print_deferred_lines(); |
5 | 5 | ||
6 | extern void cgit_ssdiff_line_cb(char *line, int len); | 6 | extern void cgit_ssdiff_line_cb(char *line, int len); |
7 | 7 | ||
8 | extern void cgit_ssdiff_header(); | 8 | extern void cgit_ssdiff_header_begin(); |
9 | extern void cgit_ssdiff_header_end(); | ||
9 | 10 | ||
10 | extern void cgit_ssdiff_footer(); | 11 | extern void cgit_ssdiff_footer(); |
11 | 12 | ||
12 | #endif /* UI_SSDIFF_H */ | 13 | #endif /* UI_SSDIFF_H */ |