Skip to content

Commit

Permalink
Fix word diff in the stage, stash and blame views
Browse files Browse the repository at this point in the history
Also remove `--root` argument when not relevant and `-M` which is
redundant with `-C`.

Fixes #1207
  • Loading branch information
koutcher committed Jun 24, 2022
1 parent d308b74 commit 13bcb40
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
21 changes: 11 additions & 10 deletions include/tig/git.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
10 changes: 5 additions & 5 deletions src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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)
Expand Down Expand Up @@ -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
};
Expand Down
5 changes: 2 additions & 3 deletions src/stash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down

0 comments on commit 13bcb40

Please sign in to comment.