Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 1 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 2 | #include "ui-ssdiff.h" |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 3 | #include "html.h" |
| 4 | #include "ui-shared.h" |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 5 | #include "ui-diff.h" |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 6 | |
| 7 | extern int use_ssdiff; |
| 8 | |
| 9 | static int current_old_line, current_new_line; |
Jamie Couture | e19f7d7 | 2011-09-17 18:25:01 -0400 | [diff] [blame] | 10 | static int **L = NULL; |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 11 | |
| 12 | struct deferred_lines { |
| 13 | int line_no; |
| 14 | char *line; |
| 15 | struct deferred_lines *next; |
| 16 | }; |
| 17 | |
| 18 | static struct deferred_lines *deferred_old, *deferred_old_last; |
| 19 | static struct deferred_lines *deferred_new, *deferred_new_last; |
| 20 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 21 | static void create_or_reset_lcs_table(void) |
Jamie Couture | e19f7d7 | 2011-09-17 18:25:01 -0400 | [diff] [blame] | 22 | { |
| 23 | int i; |
| 24 | |
| 25 | if (L != NULL) { |
Jamie Couture | 6a575b8 | 2012-01-11 22:38:49 -0500 | [diff] [blame] | 26 | memset(*L, 0, sizeof(int) * MAX_SSDIFF_SIZE); |
Jamie Couture | e19f7d7 | 2011-09-17 18:25:01 -0400 | [diff] [blame] | 27 | return; |
| 28 | } |
| 29 | |
| 30 | // xcalloc will die if we ran out of memory; |
| 31 | // not very helpful for debugging |
| 32 | L = (int**)xcalloc(MAX_SSDIFF_M, sizeof(int *)); |
| 33 | *L = (int*)xcalloc(MAX_SSDIFF_SIZE, sizeof(int)); |
| 34 | |
| 35 | for (i = 1; i < MAX_SSDIFF_M; i++) { |
| 36 | L[i] = *L + i * MAX_SSDIFF_N; |
| 37 | } |
| 38 | } |
| 39 | |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 40 | static char *longest_common_subsequence(char *A, char *B) |
| 41 | { |
| 42 | int i, j, ri; |
| 43 | int m = strlen(A); |
| 44 | int n = strlen(B); |
Eric Wong | 19c3123 | 2012-01-04 08:59:15 +0000 | [diff] [blame] | 45 | int tmp1, tmp2; |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 46 | int lcs_length; |
| 47 | char *result; |
| 48 | |
Jamie Couture | e19f7d7 | 2011-09-17 18:25:01 -0400 | [diff] [blame] | 49 | // We bail if the lines are too long |
Eric Wong | 19c3123 | 2012-01-04 08:59:15 +0000 | [diff] [blame] | 50 | if (m >= MAX_SSDIFF_M || n >= MAX_SSDIFF_N) |
Jamie Couture | e19f7d7 | 2011-09-17 18:25:01 -0400 | [diff] [blame] | 51 | return NULL; |
| 52 | |
| 53 | create_or_reset_lcs_table(); |
| 54 | |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 55 | for (i = m; i >= 0; i--) { |
| 56 | for (j = n; j >= 0; j--) { |
| 57 | if (A[i] == '\0' || B[j] == '\0') { |
| 58 | L[i][j] = 0; |
| 59 | } else if (A[i] == B[j]) { |
| 60 | L[i][j] = 1 + L[i + 1][j + 1]; |
| 61 | } else { |
| 62 | tmp1 = L[i + 1][j]; |
| 63 | tmp2 = L[i][j + 1]; |
| 64 | L[i][j] = (tmp1 > tmp2 ? tmp1 : tmp2); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | lcs_length = L[0][0]; |
| 70 | result = xmalloc(lcs_length + 2); |
| 71 | memset(result, 0, sizeof(*result) * (lcs_length + 2)); |
| 72 | |
| 73 | ri = 0; |
| 74 | i = 0; |
| 75 | j = 0; |
| 76 | while (i < m && j < n) { |
| 77 | if (A[i] == B[j]) { |
| 78 | result[ri] = A[i]; |
| 79 | ri += 1; |
| 80 | i += 1; |
| 81 | j += 1; |
| 82 | } else if (L[i + 1][j] >= L[i][j + 1]) { |
| 83 | i += 1; |
| 84 | } else { |
| 85 | j += 1; |
| 86 | } |
| 87 | } |
Jamie Couture | e19f7d7 | 2011-09-17 18:25:01 -0400 | [diff] [blame] | 88 | |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 89 | return result; |
| 90 | } |
| 91 | |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 92 | static int line_from_hunk(char *line, char type) |
| 93 | { |
| 94 | char *buf1, *buf2; |
| 95 | int len; |
| 96 | |
| 97 | buf1 = strchr(line, type); |
| 98 | if (buf1 == NULL) |
| 99 | return 0; |
| 100 | buf1 += 1; |
| 101 | buf2 = strchr(buf1, ','); |
| 102 | if (buf2 == NULL) |
| 103 | return 0; |
| 104 | len = buf2 - buf1; |
| 105 | buf2 = xmalloc(len + 1); |
| 106 | strncpy(buf2, buf1, len); |
| 107 | buf2[len] = '\0'; |
| 108 | int res = atoi(buf2); |
| 109 | free(buf2); |
| 110 | return res; |
| 111 | } |
| 112 | |
| 113 | static char *replace_tabs(char *line) |
| 114 | { |
| 115 | char *prev_buf = line; |
| 116 | char *cur_buf; |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 117 | int linelen = strlen(line); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 118 | int n_tabs = 0; |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 119 | int i; |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 120 | char *result; |
| 121 | char *spaces = " "; |
| 122 | |
| 123 | if (linelen == 0) { |
| 124 | result = xmalloc(1); |
| 125 | result[0] = '\0'; |
| 126 | return result; |
| 127 | } |
| 128 | |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 129 | for (i = 0; i < linelen; i++) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 130 | if (line[i] == '\t') |
| 131 | n_tabs += 1; |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 132 | result = xmalloc(linelen + n_tabs * 8 + 1); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 133 | result[0] = '\0'; |
| 134 | |
| 135 | while (1) { |
| 136 | cur_buf = strchr(prev_buf, '\t'); |
| 137 | if (!cur_buf) { |
| 138 | strcat(result, prev_buf); |
| 139 | break; |
| 140 | } else { |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 141 | strncat(result, prev_buf, cur_buf - prev_buf); |
Julius Plenz | 225c8ab | 2012-11-15 17:35:06 +0100 | [diff] [blame] | 142 | strncat(result, spaces, 8 - (strlen(result) % 8)); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 143 | } |
| 144 | prev_buf = cur_buf + 1; |
| 145 | } |
| 146 | return result; |
| 147 | } |
| 148 | |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 149 | static int calc_deferred_lines(struct deferred_lines *start) |
| 150 | { |
| 151 | struct deferred_lines *item = start; |
| 152 | int result = 0; |
| 153 | while (item) { |
| 154 | result += 1; |
| 155 | item = item->next; |
| 156 | } |
| 157 | return result; |
| 158 | } |
| 159 | |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 160 | static void deferred_old_add(char *line, int line_no) |
| 161 | { |
| 162 | struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines)); |
| 163 | item->line = xstrdup(line); |
| 164 | item->line_no = line_no; |
| 165 | item->next = NULL; |
| 166 | if (deferred_old) { |
| 167 | deferred_old_last->next = item; |
| 168 | deferred_old_last = item; |
| 169 | } else { |
| 170 | deferred_old = deferred_old_last = item; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static void deferred_new_add(char *line, int line_no) |
| 175 | { |
| 176 | struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines)); |
| 177 | item->line = xstrdup(line); |
| 178 | item->line_no = line_no; |
| 179 | item->next = NULL; |
| 180 | if (deferred_new) { |
| 181 | deferred_new_last->next = item; |
| 182 | deferred_new_last = item; |
| 183 | } else { |
| 184 | deferred_new = deferred_new_last = item; |
| 185 | } |
| 186 | } |
| 187 | |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 188 | static void print_part_with_lcs(char *class, char *line, char *lcs) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 189 | { |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 190 | int line_len = strlen(line); |
| 191 | int i, j; |
| 192 | char c[2] = " "; |
| 193 | int same = 1; |
| 194 | |
| 195 | j = 0; |
| 196 | for (i = 0; i < line_len; i++) { |
| 197 | c[0] = line[i]; |
| 198 | if (same) { |
| 199 | if (line[i] == lcs[j]) |
| 200 | j += 1; |
| 201 | else { |
| 202 | same = 0; |
| 203 | htmlf("<span class='%s'>", class); |
| 204 | } |
| 205 | } else if (line[i] == lcs[j]) { |
| 206 | same = 1; |
| 207 | htmlf("</span>"); |
| 208 | j += 1; |
| 209 | } |
| 210 | html_txt(c); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | static void print_ssdiff_line(char *class, |
| 215 | int old_line_no, |
| 216 | char *old_line, |
| 217 | int new_line_no, |
| 218 | char *new_line, int individual_chars) |
| 219 | { |
| 220 | char *lcs = NULL; |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 221 | |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 222 | if (old_line) |
| 223 | old_line = replace_tabs(old_line + 1); |
| 224 | if (new_line) |
| 225 | new_line = replace_tabs(new_line + 1); |
| 226 | if (individual_chars && old_line && new_line) |
| 227 | lcs = longest_common_subsequence(old_line, new_line); |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 228 | html("<tr>\n"); |
| 229 | if (old_line_no > 0) { |
| 230 | struct diff_filespec *old_file = cgit_get_current_old_file(); |
| 231 | char *lineno_str = fmt("n%d", old_line_no); |
Julius Plenz | c6fe94e | 2012-10-30 13:56:01 +0100 | [diff] [blame] | 232 | char *id_str = fmt("id=%s#%s", is_null_sha1(old_file->sha1)?"HEAD":sha1_to_hex(old_rev_sha1), lineno_str); |
Peter Wu | 4468ec1 | 2013-10-03 12:17:23 +0200 | [diff] [blame] | 233 | html("<td class='lineno'><a href='"); |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 234 | html(cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str)); |
Peter Wu | 4468ec1 | 2013-10-03 12:17:23 +0200 | [diff] [blame] | 235 | htmlf("' id='%s'>%s</a>", lineno_str, lineno_str + 1); |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 236 | html("</td>"); |
| 237 | htmlf("<td class='%s'>", class); |
| 238 | } else if (old_line) |
Ragnar Ouchterlony | 4a198e4 | 2009-09-16 18:56:26 +0200 | [diff] [blame] | 239 | htmlf("<td class='lineno'></td><td class='%s'>", class); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 240 | else |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 241 | htmlf("<td class='lineno'></td><td class='%s_dark'>", class); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 242 | if (old_line) { |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 243 | if (lcs) |
| 244 | print_part_with_lcs("del", old_line, lcs); |
| 245 | else |
| 246 | html_txt(old_line); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 247 | } |
| 248 | |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 249 | html("</td>\n"); |
| 250 | if (new_line_no > 0) { |
| 251 | struct diff_filespec *new_file = cgit_get_current_new_file(); |
| 252 | char *lineno_str = fmt("n%d", new_line_no); |
Julius Plenz | c6fe94e | 2012-10-30 13:56:01 +0100 | [diff] [blame] | 253 | char *id_str = fmt("id=%s#%s", is_null_sha1(new_file->sha1)?"HEAD":sha1_to_hex(new_rev_sha1), lineno_str); |
Peter Wu | 4468ec1 | 2013-10-03 12:17:23 +0200 | [diff] [blame] | 254 | html("<td class='lineno'><a href='"); |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 255 | html(cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str)); |
Peter Wu | 4468ec1 | 2013-10-03 12:17:23 +0200 | [diff] [blame] | 256 | htmlf("' id='%s'>%s</a>", lineno_str, lineno_str + 1); |
Bernhard Reutner-Fischer | e52040b | 2010-12-23 12:47:55 +0100 | [diff] [blame] | 257 | html("</td>"); |
| 258 | htmlf("<td class='%s'>", class); |
| 259 | } else if (new_line) |
Ragnar Ouchterlony | 4a198e4 | 2009-09-16 18:56:26 +0200 | [diff] [blame] | 260 | htmlf("<td class='lineno'></td><td class='%s'>", class); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 261 | else |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 262 | htmlf("<td class='lineno'></td><td class='%s_dark'>", class); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 263 | if (new_line) { |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 264 | if (lcs) |
| 265 | print_part_with_lcs("add", new_line, lcs); |
| 266 | else |
| 267 | html_txt(new_line); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | html("</td></tr>"); |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 271 | if (lcs) |
| 272 | free(lcs); |
| 273 | if (new_line) |
| 274 | free(new_line); |
| 275 | if (old_line) |
| 276 | free(old_line); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 277 | } |
| 278 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 279 | static void print_deferred_old_lines(void) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 280 | { |
| 281 | struct deferred_lines *iter_old, *tmp; |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 282 | iter_old = deferred_old; |
| 283 | while (iter_old) { |
| 284 | print_ssdiff_line("del", iter_old->line_no, |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 285 | iter_old->line, -1, NULL, 0); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 286 | tmp = iter_old->next; |
| 287 | free(iter_old); |
| 288 | iter_old = tmp; |
| 289 | } |
| 290 | } |
| 291 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 292 | static void print_deferred_new_lines(void) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 293 | { |
| 294 | struct deferred_lines *iter_new, *tmp; |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 295 | iter_new = deferred_new; |
| 296 | while (iter_new) { |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 297 | print_ssdiff_line("add", -1, NULL, |
| 298 | iter_new->line_no, iter_new->line, 0); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 299 | tmp = iter_new->next; |
| 300 | free(iter_new); |
| 301 | iter_new = tmp; |
| 302 | } |
| 303 | } |
| 304 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 305 | static void print_deferred_changed_lines(void) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 306 | { |
| 307 | struct deferred_lines *iter_old, *iter_new, *tmp; |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 308 | int n_old_lines = calc_deferred_lines(deferred_old); |
| 309 | int n_new_lines = calc_deferred_lines(deferred_new); |
| 310 | int individual_chars = (n_old_lines == n_new_lines ? 1 : 0); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 311 | |
| 312 | iter_old = deferred_old; |
| 313 | iter_new = deferred_new; |
| 314 | while (iter_old || iter_new) { |
| 315 | if (iter_old && iter_new) |
| 316 | print_ssdiff_line("changed", iter_old->line_no, |
| 317 | iter_old->line, |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 318 | iter_new->line_no, iter_new->line, |
| 319 | individual_chars); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 320 | else if (iter_old) |
| 321 | print_ssdiff_line("changed", iter_old->line_no, |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 322 | iter_old->line, -1, NULL, 0); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 323 | else if (iter_new) |
| 324 | print_ssdiff_line("changed", -1, NULL, |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 325 | iter_new->line_no, iter_new->line, 0); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 326 | if (iter_old) { |
| 327 | tmp = iter_old->next; |
| 328 | free(iter_old); |
| 329 | iter_old = tmp; |
| 330 | } |
| 331 | |
| 332 | if (iter_new) { |
| 333 | tmp = iter_new->next; |
| 334 | free(iter_new); |
| 335 | iter_new = tmp; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 340 | void cgit_ssdiff_print_deferred_lines(void) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 341 | { |
| 342 | if (!deferred_old && !deferred_new) |
| 343 | return; |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 344 | if (deferred_old && !deferred_new) |
| 345 | print_deferred_old_lines(); |
| 346 | else if (!deferred_old && deferred_new) |
| 347 | print_deferred_new_lines(); |
| 348 | else |
| 349 | print_deferred_changed_lines(); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 350 | deferred_old = deferred_old_last = NULL; |
| 351 | deferred_new = deferred_new_last = NULL; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * print a single line returned from xdiff |
| 356 | */ |
| 357 | void cgit_ssdiff_line_cb(char *line, int len) |
| 358 | { |
| 359 | char c = line[len - 1]; |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 360 | line[len - 1] = '\0'; |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 361 | if (line[0] == '@') { |
| 362 | current_old_line = line_from_hunk(line, '-'); |
| 363 | current_new_line = line_from_hunk(line, '+'); |
| 364 | } |
| 365 | |
| 366 | if (line[0] == ' ') { |
| 367 | if (deferred_old || deferred_new) |
| 368 | cgit_ssdiff_print_deferred_lines(); |
| 369 | print_ssdiff_line("ctx", current_old_line, line, |
Ragnar Ouchterlony | 735e15e | 2009-10-25 18:13:22 +0100 | [diff] [blame] | 370 | current_new_line, line, 0); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 371 | current_old_line += 1; |
| 372 | current_new_line += 1; |
| 373 | } else if (line[0] == '+') { |
| 374 | deferred_new_add(line, current_new_line); |
| 375 | current_new_line += 1; |
| 376 | } else if (line[0] == '-') { |
| 377 | deferred_old_add(line, current_old_line); |
| 378 | current_old_line += 1; |
| 379 | } else if (line[0] == '@') { |
| 380 | html("<tr><td colspan='4' class='hunk'>"); |
| 381 | html_txt(line); |
| 382 | html("</td></tr>"); |
| 383 | } else { |
| 384 | html("<tr><td colspan='4' class='ctx'>"); |
| 385 | html_txt(line); |
| 386 | html("</td></tr>"); |
| 387 | } |
| 388 | line[len - 1] = c; |
| 389 | } |
| 390 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 391 | void cgit_ssdiff_header_begin(void) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 392 | { |
Ragnar Ouchterlony | 4a198e4 | 2009-09-16 18:56:26 +0200 | [diff] [blame] | 393 | current_old_line = -1; |
| 394 | current_new_line = -1; |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 395 | html("<tr><td class='space' colspan='4'><div></div></td></tr>"); |
| 396 | html("<tr><td class='head' colspan='4'>"); |
| 397 | } |
| 398 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 399 | void cgit_ssdiff_header_end(void) |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 400 | { |
| 401 | html("</td><tr>"); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 402 | } |
| 403 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 404 | void cgit_ssdiff_footer(void) |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 405 | { |
| 406 | if (deferred_old || deferred_new) |
| 407 | cgit_ssdiff_print_deferred_lines(); |
Ragnar Ouchterlony | 207cc34 | 2009-09-15 19:44:37 +0200 | [diff] [blame] | 408 | html("<tr><td class='foot' colspan='4'></td></tr>"); |
Ragnar Ouchterlony | 40e174d | 2009-09-13 19:36:35 +0200 | [diff] [blame] | 409 | } |