Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Hand the side by side view its file pair
Diffstat (limited to 'source')
-rw-r--r--source/ui-diff.c55
-rw-r--r--source/ui-diff.h8
-rw-r--r--source/ui-ssdiff.c11
-rw-r--r--source/ui-ssdiff.h8
4 files changed, 32 insertions, 50 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;
diff --git a/source/ui-diff.h b/source/ui-diff.h
index 34f9599..359fad2 100644
--- a/source/ui-diff.h
+++ b/source/ui-diff.h
@@ -1,9 +1,8 @@
/*
* The page that shows what one revision changed against another, and the
* options panel that sits above it. The side by side renderer in ui-ssdiff
- * builds a link on every line number, so the two revisions being compared and
- * the file pair being rendered are published here for it rather than kept
- * private to the page.
+ * builds a link on every line number, so the two revisions being compared are
+ * published here for it rather than kept private to the page.
*/
#ifndef CGIT_UI_DIFF_H
@@ -20,9 +19,6 @@ extern void cgit_print_diff_ctrls(void);
extern void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix,
int show_ctrls, int raw);
-extern struct diff_filespec *cgit_get_current_old_file(void);
-extern struct diff_filespec *cgit_get_current_new_file(void);
-
extern struct object_id old_rev_oid[1];
extern struct object_id new_rev_oid[1];
diff --git a/source/ui-ssdiff.c b/source/ui-ssdiff.c
index afa25ea..75f8185 100644
--- a/source/ui-ssdiff.c
+++ b/source/ui-ssdiff.c
@@ -21,6 +21,8 @@ struct deferred_line {
struct deferred_line *next;
};
+// The pair being rendered, whose two sides the line number links lead into.
+static struct diff_filepair *current_filepair;
static int current_old_line, current_new_line;
static int **lcs_table;
static struct deferred_line *deferred_old, *deferred_old_last;
@@ -196,7 +198,7 @@ static void print_row(const char *class, int old_line_no, char *old_line,
lcs = longest_common_subsequence(old_line, new_line);
html("<tr>\n");
if (old_line_no > 0) {
- print_lineno_cell(cgit_get_current_old_file(), old_rev_oid, old_line_no);
+ 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);
@@ -212,7 +214,7 @@ static void print_row(const char *class, int old_line_no, char *old_line,
html("</td>\n");
if (new_line_no > 0) {
- print_lineno_cell(cgit_get_current_new_file(), new_rev_oid, new_line_no);
+ 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);
@@ -401,12 +403,13 @@ void cgit_ssdiff_line_cb(char *line, int len)
line[len - 1] = terminator;
}
-void cgit_ssdiff_header_begin(const char *path)
+void cgit_ssdiff_header_begin(struct diff_filepair *pair)
{
+ current_filepair = pair;
current_old_line = -1;
current_new_line = -1;
html("<tbody class='file' data-path='");
- html_attr(path);
+ html_attr(pair->two->path);
html("'>\n");
html("<tr><td class='space' colspan='4'></td></tr>\n");
html("<tr><td class='head' colspan='4'>");
diff --git a/source/ui-ssdiff.h b/source/ui-ssdiff.h
index 9417277..fb4b1e7 100644
--- a/source/ui-ssdiff.h
+++ b/source/ui-ssdiff.h
@@ -23,10 +23,12 @@
extern void cgit_ssdiff_line_cb(char *line, int len);
/*
- * Open the group of rows one file's diff occupies, header row included, and
- * close it again after the last line. path lands on the group as data-path.
+ * Open the group of rows a file pair's diff occupies, header row included, and
+ * close it again after the last line. The new path lands on the group as
+ * data-path, and the rows read the pair until the footer, so it has to live
+ * that long.
*/
-extern void cgit_ssdiff_header_begin(const char *path);
+extern void cgit_ssdiff_header_begin(struct diff_filepair *pair);
extern void cgit_ssdiff_header_end(void);
extern void cgit_ssdiff_footer(void);