diff options
Diffstat (limited to '')
| -rw-r--r-- | source/ui-diff.c | 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 46 insertions, 80 deletions
diff --git a/source/ui-diff.c b/source/ui-diff.c index 3c7d8d2..fb86a96 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -131,26 +131,21 @@ static void print_fileinfo(struct fileinfo *info) cgit_print_filemode(info->new_mode); } - if (info->old_mode != info->new_mode && - !is_null_oid(info->old_oid) && - !is_null_oid(info->new_oid)) { + if (info->old_mode != info->new_mode && !is_null_oid(info->old_oid) && !is_null_oid(info->new_oid)) { html("<span class='modechange'>["); cgit_print_filemode(info->old_mode); html("]</span>"); } htmlf("</td><td class='%s'>", class); - cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.oid, - ctx.qry.oid2, info->new_path); + cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, info->new_path); if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) { - htmlf(" (%s from ", - info->status == DIFF_STATUS_COPIED ? "copied" : "renamed"); + htmlf(" (%s from ", info->status == DIFF_STATUS_COPIED ? "copied" : "renamed"); html_txt(info->old_path); html(")"); } html("</td><td class='right'>"); if (info->binary) { - htmlf("bin</td><td class='graph'>%lu -> %lu bytes</td></tr>\n", - info->old_size, info->new_size); + htmlf("bin</td><td class='graph'>%lu -> %lu bytes</td></tr>\n", info->old_size, info->new_size); return; } htmlf("%d", info->added + info->removed); @@ -178,8 +173,7 @@ static void count_diff_lines(char *line, int len) } if (!render_line_fn || render_suppressed) return; - if (cap_diffs && ctx.cfg.max_diff_lines > 0 && - lines_added + lines_removed > ctx.cfg.max_diff_lines) { + if (cap_diffs && ctx.cfg.max_diff_lines > 0 && lines_added + lines_removed > ctx.cfg.max_diff_lines) { render_suppressed = 1; return; } @@ -190,8 +184,7 @@ static int show_filepair(struct diff_filepair *pair) { if (!current_prefix) return 1; - return starts_with(pair->one->path, current_prefix) || - starts_with(pair->two->path, current_prefix); + return starts_with(pair->one->path, current_prefix) || starts_with(pair->two->path, current_prefix); } /* @@ -224,13 +217,11 @@ static void print_line(char *line, int len) */ static char *abbrev_oid(const struct object_id *oid) { - return xstrdup(repo_find_unique_abbrev(the_repository, oid, - DEFAULT_ABBREV)); + return xstrdup(repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV)); } -static void print_file_header(const struct object_id *old_oid, char *old_path, - int old_mode, const struct object_id *new_oid, - char *new_path, int new_mode) +static void print_file_header(const struct object_id *old_oid, char *old_path, int old_mode, + const struct object_id *new_oid, char *new_path, int new_mode) { char *old_abbrev, *new_abbrev; int subproject; @@ -265,8 +256,7 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, } else html("<br>--- a/"); if (old_mode != 0) - cgit_tree_link(old_path, NULL, NULL, ctx.qry.head, - oid_to_hex(old_rev_oid), old_path); + cgit_tree_link(old_path, NULL, NULL, ctx.qry.head, oid_to_hex(old_rev_oid), old_path); else html_txt(old_path); if (is_null_oid(new_oid)) { @@ -275,8 +265,7 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, } else html("<br>+++ b/"); if (new_mode != 0) - cgit_tree_link(new_path, NULL, NULL, ctx.qry.head, - oid_to_hex(new_rev_oid), new_path); + cgit_tree_link(new_path, NULL, NULL, ctx.qry.head, oid_to_hex(new_rev_oid), new_path); else html_txt(new_path); } @@ -287,17 +276,14 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, * The length passed counts the terminator, because a renderer strips the last * byte of every line it is given. */ -static void print_subproject_lines(struct diff_filepair *pair, - linediff_fn line_fn) +static void print_subproject_lines(struct diff_filepair *pair, linediff_fn line_fn) { if (S_ISGITLINK(pair->one->mode)) { - char *text = cgit_fmt("-Subproject %s", - oid_to_hex(&pair->one->oid)); + char *text = cgit_fmt("-Subproject %s", oid_to_hex(&pair->one->oid)); line_fn(text, strlen(text) + 1); } if (S_ISGITLINK(pair->two->mode)) { - char *text = cgit_fmt("+Subproject %s", - oid_to_hex(&pair->two->oid)); + char *text = cgit_fmt("+Subproject %s", oid_to_hex(&pair->two->oid)); line_fn(text, strlen(text) + 1); } } @@ -317,8 +303,7 @@ static void print_truncated(const char *path) else html("<div class='truncated'>"); html("This diff is too large to be rendered inline. "); - cgit_diff_link("View it on its own page", NULL, NULL, ctx.qry.head, - ctx.qry.oid, ctx.qry.oid2, path); + cgit_diff_link("View it on its own page", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, path); html("."); if (use_ssdiff) { html("</td></tr>"); @@ -346,9 +331,8 @@ static struct fileinfo *reserve_item(void) * Renders one file's body into its own buffer, the way filepair_cb would have * written it straight out on a second walk. */ -static void collect_body(struct diff_filepair *pair, struct fileinfo *item, - int *binary, unsigned long *old_size, - unsigned long *new_size) +static void collect_body(struct diff_filepair *pair, struct fileinfo *item, int *binary, + unsigned long *old_size, unsigned long *new_size) { struct strbuf *body = &item->body; linediff_fn line_fn = use_ssdiff ? cgit_ssdiff_line_cb : print_line; @@ -360,7 +344,7 @@ static void collect_body(struct diff_filepair *pair, struct fileinfo *item, if (use_ssdiff) cgit_ssdiff_header_begin(); print_file_header(&pair->one->oid, pair->one->path, pair->one->mode, - &pair->two->oid, pair->two->path, pair->two->mode); + &pair->two->oid, pair->two->path, pair->two->mode); if (use_ssdiff) cgit_ssdiff_header_end(); header_len = body->len; @@ -376,15 +360,13 @@ static void collect_body(struct diff_filepair *pair, struct fileinfo *item, // than the two lines the body shows, so run that diff for // the count alone. render_line_fn = NULL; - cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, - new_size, binary, 0, ctx.qry.ignorews, - count_diff_lines); + cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, new_size, + binary, 0, ctx.qry.ignorews, count_diff_lines); print_subproject_lines(pair, line_fn); } else { render_line_fn = line_fn; - if (cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, - new_size, binary, ctx.qry.context, - ctx.qry.ignorews, count_diff_lines)) + if (cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, new_size, + binary, ctx.qry.context, ctx.qry.ignorews, count_diff_lines)) cgit_print_error("Error running diff"); render_line_fn = NULL; if (*binary) @@ -429,9 +411,8 @@ static void inspect_filepair(struct diff_filepair *pair) if (bodies_usable) collect_body(pair, item, &binary, &old_size, &new_size); else - cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, - &new_size, &binary, 0, ctx.qry.ignorews, - count_diff_lines); + cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, + &binary, 0, ctx.qry.ignorews, count_diff_lines); item->status = pair->status; oidcpy(item->old_oid, &pair->one->oid); @@ -451,14 +432,13 @@ static void inspect_filepair(struct diff_filepair *pair) total_rems += lines_removed; } -static void print_diffstat(const struct object_id *old_oid, - const struct object_id *new_oid, const char *prefix) +static void print_diffstat(const struct object_id *old_oid, const struct object_id *new_oid, + const char *prefix) { int i; html("<div class='diffstat-header'>"); - cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.oid, - ctx.qry.oid2, NULL); + cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, NULL); if (prefix) { html(" (limited to '"); html_txt(prefix); @@ -467,8 +447,7 @@ static void print_diffstat(const struct object_id *old_oid, html("</div>\n"); html("<table class='diffstat'>\n"); max_changes = 0; - cgit_diff_tree(old_oid, new_oid, inspect_filepair, prefix, - ctx.qry.ignorews); + cgit_diff_tree(old_oid, new_oid, inspect_filepair, prefix, ctx.qry.ignorews); for (i = 0; i < files; i++) print_fileinfo(&items[i]); html("</table>\n"); @@ -483,9 +462,8 @@ static void print_diffstat(const struct object_id *old_oid, static int over_line_cap(int idx) { return cap_diffs && ctx.cfg.max_diff_lines > 0 && - idx < files && !items[idx].binary && - items[idx].added + items[idx].removed > - (unsigned int)ctx.cfg.max_diff_lines; + idx < files && !items[idx].binary && + items[idx].added + items[idx].removed > (unsigned int)ctx.cfg.max_diff_lines; } static void filepair_cb(struct diff_filepair *pair) @@ -506,7 +484,7 @@ static void filepair_cb(struct diff_filepair *pair) 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); + &pair->two->oid, pair->two->path, pair->two->mode); if (use_ssdiff) cgit_ssdiff_header_end(); @@ -520,9 +498,8 @@ static void filepair_cb(struct diff_filepair *pair) cgit_ssdiff_footer(); return; } - if (cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, - &new_size, &binary, ctx.qry.context, - ctx.qry.ignorews, line_fn)) + if (cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, + &binary, ctx.qry.context, ctx.qry.ignorews, line_fn)) cgit_print_error("Error running diff"); if (binary) print_binary_differs(); @@ -530,8 +507,7 @@ static void filepair_cb(struct diff_filepair *pair) cgit_ssdiff_footer(); } -static void print_raw_patch(const struct object_id *old_tree_oid, - const struct object_id *new_tree_oid) +static void print_raw_patch(const struct object_id *old_tree_oid, const struct object_id *new_tree_oid) { struct diff_options diffopt; @@ -607,8 +583,8 @@ void cgit_print_diff_ctrls(void) html("</div>\n"); } -void cgit_print_diff(const char *new_rev, const char *old_rev, - const char *prefix, int show_ctrls, int raw) +void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix, + int show_ctrls, int raw) { struct commit *new_commit, *old_commit; const struct object_id *old_tree_oid, *new_tree_oid; @@ -631,22 +607,19 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; if (repo_get_oid(the_repository, new_rev, new_rev_oid)) { - cgit_print_error_page(404, "Not Found", - "Bad object name: %s", new_rev); + cgit_print_error_page(404, "Not Found", "Bad object name: %s", new_rev); return; } new_commit = lookup_commit_reference(the_repository, new_rev_oid); if (!new_commit || repo_parse_commit(the_repository, new_commit)) { - cgit_print_error_page(404, "Not Found", - "Bad commit: %s", oid_to_hex(new_rev_oid)); + cgit_print_error_page(404, "Not Found", "Bad commit: %s", oid_to_hex(new_rev_oid)); return; } new_tree_oid = get_commit_tree_oid(new_commit); if (old_rev) { if (repo_get_oid(the_repository, old_rev, old_rev_oid)) { - cgit_print_error_page(404, "Not Found", - "Bad object name: %s", old_rev); + cgit_print_error_page(404, "Not Found", "Bad object name: %s", old_rev); return; } } else if (new_commit->parents && new_commit->parents->item) { @@ -656,12 +629,9 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, } if (!is_null_oid(old_rev_oid)) { - old_commit = lookup_commit_reference(the_repository, - old_rev_oid); - if (!old_commit || - repo_parse_commit(the_repository, old_commit)) { - cgit_print_error_page(404, "Not Found", - "Bad commit: %s", oid_to_hex(old_rev_oid)); + old_commit = lookup_commit_reference(the_repository, old_rev_oid); + if (!old_commit || repo_parse_commit(the_repository, old_commit)) { + cgit_print_error_page(404, "Not Found", "Bad commit: %s", oid_to_hex(old_rev_oid)); return; } old_tree_oid = get_commit_tree_oid(old_commit); @@ -680,8 +650,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, // it came from, which for a side by side diff is several times the blob // itself, and the budget cannot help there because it is only reached // once a body is complete. - bodies_usable = difftype != DIFF_STATONLY && cap_diffs && - ctx.cfg.max_diff_lines > 0; + bodies_usable = difftype != DIFF_STATONLY && cap_diffs && ctx.cfg.max_diff_lines > 0; if (show_ctrls) { cgit_print_layout_start(); @@ -702,11 +671,9 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, return; } - if (cap_diffs && ctx.cfg.max_diff_files > 0 && - files > ctx.cfg.max_diff_files) { + if (cap_diffs && ctx.cfg.max_diff_files > 0 && files > ctx.cfg.max_diff_files) { html("<div class='truncated'>"); - html("This diff is too large to be rendered inline. " - "Follow a file above, or the "); + html("This diff is too large to be rendered inline. Follow a file above, or the "); cgit_patch_link("patch", NULL, NULL, NULL, ctx.qry.oid, NULL); html(" link for the whole commit."); html("</div>"); @@ -730,8 +697,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, release_bodies(); } else { item_idx = 0; - cgit_diff_tree(old_rev_oid, new_rev_oid, filepair_cb, prefix, - ctx.qry.ignorews); + cgit_diff_tree(old_rev_oid, new_rev_oid, filepair_cb, prefix, ctx.qry.ignorews); } if (!use_ssdiff) html("</td></tr>\n"); |
