Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Write both halves of a side by side row one way
| -rw-r--r-- | source/ui-ssdiff.c | 57 |
1 file changed, 25 insertions, 32 deletions
diff --git a/source/ui-ssdiff.c b/source/ui-ssdiff.c index 61573d9..4bddb9d 100644 --- a/source/ui-ssdiff.c +++ b/source/ui-ssdiff.c @@ -184,6 +184,27 @@ static void print_lineno_cell(struct diff_filespec *file, const struct object_id strbuf_release(&path); } +/* + * mark is the class for the characters this side of the row does not share + * with the other. + */ +static void print_side(const char *class, struct diff_filespec *file, const struct object_id *rev, + int line_no, const char *line, const char *lcs, const char *mark) +{ + if (line_no > 0) + print_lineno_cell(file, rev, line_no); + else + html("<td class='lineno'></td>"); + htmlf("<td class='%s%s'>", class, line ? "" : "-dark"); + if (line) { + if (lcs) + print_line_with_lcs(mark, line, lcs); + else + html_txt(line); + } + html("</td>"); +} + static void print_row(const char *class, int old_line_no, char *old_line, int new_line_no, char *new_line, int highlight_chars) { @@ -197,38 +218,10 @@ static void print_row(const char *class, int old_line_no, char *old_line, if (highlight_chars && old_line && new_line) lcs = longest_common_subsequence(old_line, new_line); html("<tr>\n"); - if (old_line_no > 0) { - print_lineno_cell(current_filepair->one, old_rev_oid, old_line_no); - htmlf("<td class='%s'>", class); - } else if (old_line) { - htmlf("<td class='lineno'></td><td class='%s'>", class); - } else { - htmlf("<td class='lineno'></td><td class='%s-dark'>", class); - } - if (old_line) { - if (lcs) - print_line_with_lcs("del", old_line, lcs); - else - html_txt(old_line); - } - - html("</td>\n"); - if (new_line_no > 0) { - print_lineno_cell(current_filepair->two, new_rev_oid, new_line_no); - htmlf("<td class='%s'>", class); - } else if (new_line) { - htmlf("<td class='lineno'></td><td class='%s'>", class); - } else { - htmlf("<td class='lineno'></td><td class='%s-dark'>", class); - } - if (new_line) { - if (lcs) - print_line_with_lcs("add", new_line, lcs); - else - html_txt(new_line); - } - - html("</td></tr>\n"); + print_side(class, current_filepair->one, old_rev_oid, old_line_no, old_line, lcs, "del"); + html("\n"); + print_side(class, current_filepair->two, new_rev_oid, new_line_no, new_line, lcs, "add"); + html("</tr>\n"); free(lcs); free(new_line); free(old_line); |
