From ddccf47fa2f4369abcce0a0b293ef9d0775dbbaf Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Mon, 21 Jun 2021 20:32:43 +0200 Subject: [PATCH] Make word-diff a toggleable option Closes #1119 --- include/tig/options.h | 3 ++- src/diff.c | 4 ++-- src/options.c | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/tig/options.h b/include/tig/options.h index 79b212851..9fc1eecc2 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -39,6 +39,7 @@ typedef struct view_column *view_settings; _(diff_noprefix, bool, VIEW_NO_FLAGS) \ _(diff_options, const char **, VIEW_DIFF_LIKE) \ _(diff_highlight, const char *, VIEW_DIFF_LIKE) \ + _(word_diff, bool, VIEW_DIFF_LIKE) \ _(diff_view, view_settings, VIEW_NO_FLAGS) \ _(editor_line_number, bool, VIEW_NO_FLAGS) \ _(file_args, const char **, VIEW_NO_FLAGS) \ @@ -183,7 +184,6 @@ extern iconv_t opt_iconv_out; extern char opt_editor[SIZEOF_STR]; extern const char **opt_cmdline_args; extern bool opt_log_follow; -extern bool opt_word_diff; /* * Mapping between options and command argument mapping. @@ -197,6 +197,7 @@ const char *commit_order_arg_with_graph(enum graph_display graph_display); const char *log_custom_pretty_arg(); const char *use_mailmap_arg(); const char *diff_context_arg(); +const char *word_diff_arg(); const char *show_notes_arg(); /* diff --git a/src/diff.c b/src/diff.c index 732fc3f4a..2710a34be 100644 --- a/src/diff.c +++ b/src/diff.c @@ -29,8 +29,8 @@ diff_open(struct view *view, enum open_flags flags) "git", "show", encoding_arg, "--pretty=fuller", "--root", "--patch-with-stat", use_mailmap_arg(), show_notes_arg(), diff_context_arg(), ignore_space_arg(), - DIFF_ARGS, "%(cmdlineargs)", "--no-color", "%(commit)", - "--", "%(fileargs)", NULL + DIFF_ARGS, "%(cmdlineargs)", "--no-color", word_diff_arg(), + "%(commit)", "--", "%(fileargs)", NULL }; enum status_code code; diff --git a/src/options.c b/src/options.c index 0dfa98202..f5ee2bc2c 100644 --- a/src/options.c +++ b/src/options.c @@ -141,6 +141,12 @@ diff_context_arg() return opt_diff_context_arg; } +const char * +word_diff_arg() +{ + return opt_word_diff ? "--word-diff=plain" : "--word-diff=none"; +} + const char * use_mailmap_arg() { @@ -257,6 +263,8 @@ update_options_from_argv(const char *argv[]) if (!strcmp(flag, "--word-diff") || !strcmp(flag, "--word-diff=plain")) { opt_word_diff = true; + mark_option_seen(&opt_word_diff); + continue; } argv[flags_pos++] = flag;