Diff options
Diffstat (limited to '')
| -rw-r--r-- | source/ui-diff.c | 55 |
1 file changed, 18 insertions, 37 deletions
diff --git a/source/ui-diff.c b/source/ui-diff.c index 0c6c288..736cdaf 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -54,7 +54,6 @@ static int bodies_usable; static linediff_fn render_line_fn; static int render_suppressed; -static struct diff_filepair *current_filepair; static const char *current_prefix; static int use_ssdiff; @@ -203,16 +202,22 @@ static void print_line(char *line, int len) html("</div>"); } -static void print_file_header(const struct object_id *old_oid, const char *old_path, unsigned old_mode, - const struct object_id *new_oid, const char *new_path, unsigned new_mode) +/* + * Opens the group end_file closes, in whichever view the page uses, and writes + * the header of the pair's diff into it. + */ +static void print_file_header(struct diff_filepair *pair) { + const struct object_id *old_oid = &pair->one->oid, *new_oid = &pair->two->oid; + const char *old_path = pair->one->path, *new_path = pair->two->path; + unsigned old_mode = pair->one->mode, new_mode = pair->two->mode; char old_abbrev[GIT_MAX_HEXSZ + 1], new_abbrev[GIT_MAX_HEXSZ + 1]; int subproject; subproject = (S_ISGITLINK(old_mode) || S_ISGITLINK(new_mode)); - // The side by side view opens its file group before the header row, - // so only the unified view opens one here. - if (!use_ssdiff) { + if (use_ssdiff) { + cgit_ssdiff_header_begin(pair); + } else { html("<div class='file' data-path='"); html_attr(new_path); html("'>"); @@ -260,12 +265,13 @@ static void print_file_header(const struct object_id *old_oid, const char *old_p html_txt(new_path); } html("</div>"); + if (use_ssdiff) + cgit_ssdiff_header_end(); } /* - * Closes the group print_file_header or cgit_ssdiff_header_begin opened. The - * side by side footer closes its own, so the unified view is the only one with - * work to do here. + * Closes the group print_file_header opened. The side by side footer closes its + * own, so the unified view is the only one with work to do here. */ static void end_file(void) { @@ -339,15 +345,8 @@ static void collect_body(struct diff_filepair *pair, struct fileinfo *item, int linediff_fn line_fn = use_ssdiff ? cgit_ssdiff_line_cb : print_line; size_t header_len; - current_filepair = pair; - html_capture_begin(body); - if (use_ssdiff) - cgit_ssdiff_header_begin(pair->two->path); - print_file_header(&pair->one->oid, pair->one->path, pair->one->mode, - &pair->two->oid, pair->two->path, pair->two->mode); - if (use_ssdiff) - cgit_ssdiff_header_end(); + print_file_header(pair); header_len = body->len; // Cleared for the whole file rather than in the branch below, because @@ -474,21 +473,13 @@ static void filepair_cb(struct diff_filepair *pair) size_t new_size = 0; int binary = 0; int idx; - linediff_fn line_fn = print_line; + linediff_fn line_fn = use_ssdiff ? cgit_ssdiff_line_cb : print_line; if (!show_filepair(pair)) return; idx = item_idx++; - current_filepair = pair; - if (use_ssdiff) { - cgit_ssdiff_header_begin(pair->two->path); - line_fn = cgit_ssdiff_line_cb; - } - print_file_header(&pair->one->oid, pair->one->path, pair->one->mode, - &pair->two->oid, pair->two->path, pair->two->mode); - if (use_ssdiff) - cgit_ssdiff_header_end(); + print_file_header(pair); if (over_line_cap(idx)) { print_truncated(items[idx].new_path); @@ -533,16 +524,6 @@ static void print_raw_patch(const struct object_id *old_tree_oid, const struct o diff_flush(&diffopt); } -struct diff_filespec *cgit_get_current_old_file(void) -{ - return current_filepair->one; -} - -struct diff_filespec *cgit_get_current_new_file(void) -{ - return current_filepair->two; -} - void cgit_print_diff_ctrls(void) { int i, selected; |
