summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.css66
-rw-r--r--ui-diff.c27
-rw-r--r--ui-ssdiff.c30
-rw-r--r--ui-ssdiff.h3
4 files changed, 96 insertions, 30 deletions
diff --git a/cgit.css b/cgit.css
index bf58b8a..3f37165 100644
--- a/cgit.css
+++ b/cgit.css
@@ -599,40 +599,94 @@ table.hgraph td {
599 599
600table.hgraph div.bar { 600table.hgraph div.bar {
601 background-color: #eee; 601 background-color: #eee;
602 height: 1em; 602 height: 1em;
603} 603}
604 604
605table.ssdiff {
606 width: 100%;
607}
608
609table.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
605table.ssdiff td.add { 618table.ssdiff td.add {
606 color: black; 619 color: black;
607 background: #afa; 620 background: #cfc;
621 min-width: 50%;
608} 622}
609 623
610table.ssdiff td.add_dark { 624table.ssdiff td.add_dark {
611 color: black; 625 color: black;
612 background: #9c9; 626 background: #aca;
627 min-width: 50%;
613} 628}
614 629
615table.ssdiff td.del { 630table.ssdiff td.del {
616 color: black; 631 color: black;
617 background: #faa; 632 background: #fcc;
633 min-width: 50%;
618} 634}
619 635
620table.ssdiff td.del_dark { 636table.ssdiff td.del_dark {
621 color: black; 637 color: black;
622 background: #c99; 638 background: #caa;
639 min-width: 50%;
623} 640}
624 641
625table.ssdiff td.changed { 642table.ssdiff td.changed {
626 color: black; 643 color: black;
627 background: #ffa; 644 background: #ffc;
645 min-width: 50%;
628} 646}
629 647
630table.ssdiff td.changed_dark { 648table.ssdiff td.changed_dark {
631 color: black; 649 color: black;
632 background: #cc9; 650 background: #cca;
651 min-width: 50%;
652}
653
654table.ssdiff td.lineno {
655 color: black;
656 background: #eee;
657 text-align: right;
658 width: 3em;
659 min-width: 3em;
633} 660}
634 661
635table.ssdiff td.hunk { 662table.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
669table.ssdiff td.head {
670 border-top: solid 1px #aaa;
671 border-bottom: solid 1px #aaa;
672}
673
674table.ssdiff td.head div.head {
675 font-weight: bold;
676 color: black;
677}
678
679table.ssdiff td.foot {
680 border-top: solid 1px #aaa;
681 border-left: none;
682 border-right: none;
683 border-bottom: none;
684}
685
686table.ssdiff td.space {
687 border: none;
688}
689
690table.ssdiff td.space div {
691 min-height: 3em;
692} \ No newline at end of file
diff --git a/ui-diff.c b/ui-diff.c
index 42e81ac..b21c2c1 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -243,14 +243,12 @@ static void header(unsigned char *sha1, char *path1, int mode1,
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
253static void print_ssdiff_link() 251static 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)
@@ -267,30 +265,32 @@ 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
295void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 295void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
296{ 296{
@@ -331,12 +331,17 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
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
@@ -37,28 +37,28 @@ static int line_from_hunk(char *line, char type)
37} 37}
38 38
39static char *replace_tabs(char *line) 39static 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);
@@ -103,30 +103,30 @@ static void deferred_new_add(char *line, int line_no)
103 103
104static void print_ssdiff_line(char *class, int old_line_no, char *old_line, 104static 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 }
@@ -246,19 +246,25 @@ void cgit_ssdiff_line_cb(char *line, int len)
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
252void cgit_ssdiff_header() 252void 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
260void cgit_ssdiff_header_end()
261{
262 html("</td><tr>");
257} 263}
258 264
259void cgit_ssdiff_footer() 265void 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
@@ -2,11 +2,12 @@
2#define UI_SSDIFF_H 2#define UI_SSDIFF_H
3 3
4extern void cgit_ssdiff_print_deferred_lines(); 4extern void cgit_ssdiff_print_deferred_lines();
5 5
6extern void cgit_ssdiff_line_cb(char *line, int len); 6extern void cgit_ssdiff_line_cb(char *line, int len);
7 7
8extern void cgit_ssdiff_header(); 8extern void cgit_ssdiff_header_begin();
9extern void cgit_ssdiff_header_end();
9 10
10extern void cgit_ssdiff_footer(); 11extern void cgit_ssdiff_footer();
11 12
12#endif /* UI_SSDIFF_H */ 13#endif /* UI_SSDIFF_H */