From 13bcb402230a3ff7e668966cda9e5d125711a4d4 Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Fri, 24 Jun 2022 19:05:33 +0200 Subject: [PATCH] Fix word diff in the stage, stash and blame views Also remove `--root` argument when not relevant and `-M` which is redundant with `-C`. Fixes #1207 --- include/tig/git.h | 21 +++++++++++---------- src/blame.c | 1 + src/stage.c | 10 +++++----- src/stash.c | 5 ++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/tig/git.h b/include/tig/git.h index e60e8d467..7c5f0930d 100644 --- a/include/tig/git.h +++ b/include/tig/git.h @@ -25,14 +25,15 @@ #define GIT_DIFF_STAGED_INITIAL(encoding_arg, context_arg, space_arg, new_name) \ GIT_DIFF_INITIAL(encoding_arg, "--cached", context_arg, space_arg, "", new_name) -#define GIT_DIFF_STAGED(encoding_arg, context_arg, space_arg, old_name, new_name) \ - "git", "diff-index", (encoding_arg), "--root", "--textconv", "--patch-with-stat", "-C", "-M", \ - "--cached", "--diff-filter=ACDMRTXB", DIFF_ARGS, "%(cmdlineargs)", (context_arg), (space_arg), "HEAD", \ - "--", (old_name), (new_name), NULL +#define GIT_DIFF_STAGED(encoding_arg, context_arg, space_arg, word_diff_arg, old_name, new_name) \ + "git", "diff-index", (encoding_arg), "--textconv", "--patch-with-stat", "-C", \ + "--cached", "--diff-filter=ACDMRTXB", DIFF_ARGS, "%(cmdlineargs)", (context_arg), \ + (space_arg), (word_diff_arg), "HEAD", "--", (old_name), (new_name), NULL -#define GIT_DIFF_UNSTAGED(encoding_arg, context_arg, space_arg, old_name, new_name) \ - "git", "diff-files", (encoding_arg), "--root", "--textconv", "--patch-with-stat", "-C", "-M", \ - DIFF_ARGS, "%(cmdlineargs)", (context_arg), (space_arg), "--", (old_name), (new_name), NULL +#define GIT_DIFF_UNSTAGED(encoding_arg, context_arg, space_arg, word_diff_arg, old_name, new_name) \ + "git", "diff-files", (encoding_arg), "--textconv", "--patch-with-stat", "-C", \ + DIFF_ARGS, "%(cmdlineargs)", (context_arg), (space_arg), (word_diff_arg), \ + "--", (old_name), (new_name), NULL /* Don't show staged unmerged entries. */ #define GIT_DIFF_STAGED_FILES(output_arg) \ @@ -42,9 +43,9 @@ #define GIT_DIFF_UNSTAGED_FILES(output_arg) \ "git", "diff-files", (output_arg), "%(cmdlineargs)", NULL -#define GIT_DIFF_BLAME(encoding_arg, context_arg, space_arg, new_name) \ - "git", "diff-files", (encoding_arg), "--root", "--textconv", "--patch-with-stat", "-C", "-M", \ - (context_arg), (space_arg), "--", (new_name), NULL +#define GIT_DIFF_BLAME(encoding_arg, context_arg, space_arg, word_diff_arg, new_name) \ + "git", "diff-files", (encoding_arg), "--textconv", "--patch-with-stat", "-C", \ + (context_arg), (space_arg), (word_diff_arg), "--", (new_name), NULL #define GIT_DIFF_BLAME_NO_PARENT(encoding_arg, context_arg, space_arg, new_name) \ GIT_DIFF_INITIAL(encoding_arg, "", context_arg, space_arg, "/dev/null", new_name) diff --git a/src/blame.c b/src/blame.c index b1df603d8..0da0cb9e2 100644 --- a/src/blame.c +++ b/src/blame.c @@ -436,6 +436,7 @@ blame_request(struct view *view, enum request request, struct line *line) GIT_DIFF_BLAME(encoding_arg, diff_context_arg(), ignore_space_arg(), + word_diff_arg(), blame->commit->filename) }; const char *diff_no_parent_argv[] = { diff --git a/src/stage.c b/src/stage.c index c5b4b7864..7a9896f5f 100644 --- a/src/stage.c +++ b/src/stage.c @@ -454,7 +454,7 @@ find_deleted_line_in_head(struct view *view, struct line *line) { "git", "ls-tree", "-z", "HEAD", view->env->file, NULL }; const char *diff_argv[] = { - "git", "diff", "--root", file_in_head_pathspec, file_in_index_pathspec, + "git", "diff", file_in_head_pathspec, file_in_index_pathspec, "--no-color", NULL }; @@ -468,7 +468,7 @@ find_deleted_line_in_head(struct view *view, struct line *line) { } else { // The file might might be renamed in the index. Find its old name. struct status file_status; const char *diff_index_argv[] = { - "git", "diff-index", "--root", "--cached", "-C", + "git", "diff-index", "--cached", "-C", "--diff-filter=ACR", "-z", "HEAD", NULL }; if (!io_run(&io, IO_RD, repo.exec_dir, NULL, diff_index_argv) || io.status) @@ -702,16 +702,16 @@ stage_open(struct view *view, enum open_flags flags) }; const char *index_show_argv[] = { GIT_DIFF_STAGED(encoding_arg, diff_context_arg(), ignore_space_arg(), - stage_status.old.name, stage_status.new.name) + word_diff_arg(), stage_status.old.name, stage_status.new.name) }; const char *files_show_argv[] = { GIT_DIFF_UNSTAGED(encoding_arg, diff_context_arg(), ignore_space_arg(), - stage_status.old.name, stage_status.new.name) + word_diff_arg(), stage_status.old.name, stage_status.new.name) }; /* Diffs for unmerged entries are empty when passing the new * path, so leave out the new path. */ const char *files_unmerged_argv[] = { - "git", "diff-files", encoding_arg, "--root", "--textconv", "--patch-with-stat", + "git", "diff-files", encoding_arg, "--textconv", "--patch-with-stat", DIFF_ARGS, diff_context_arg(), ignore_space_arg(), "--", stage_status.old.name, NULL }; diff --git a/src/stash.c b/src/stash.c index ee26cdf10..43eb0be13 100644 --- a/src/stash.c +++ b/src/stash.c @@ -81,9 +81,8 @@ stash_request(struct view *view, enum request request, struct line *line) strcmp(view->env->stash, diff->ref)) { const char *diff_argv[] = { "git", "stash", "show", encoding_arg, "--pretty=fuller", - "--root", "--patch-with-stat", - show_notes_arg(), diff_context_arg(), - ignore_space_arg(), DIFF_ARGS, + "--patch-with-stat", diff_context_arg(), + ignore_space_arg(), word_diff_arg(), DIFF_ARGS, "--no-color", "%(stash)", NULL };