From dd76eccc975616d7f7bd9e6ff4d24060a6c272bc Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 30 Jul 2014 23:17:53 -0400 Subject: [PATCH] Add workaround for git pretty.format settings that break the log view This overrides any pretty.format setting that contains color definitions to use the 'medium' format. The fix adds the setting 'log-options' for implementing the workaround. The option can be configured in `tigrc` and works similar to `blame-options`. Finally, in order to test the feature the semantics of `:toggle ` (note no arguments) has been changed to simply clear the entries in the . Fixes #225 --- NEWS.adoc | 6 +++ include/tig/options.h | 1 + src/argv.c | 4 ++ src/log.c | 4 +- src/options.c | 4 ++ src/prompt.c | 6 +++ test/log/pretty-format-test | 123 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100755 test/log/pretty-format-test diff --git a/NEWS.adoc b/NEWS.adoc index 2e3acb4..9a55f0d 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -17,6 +17,8 @@ Improvement: - Expose settings holding command line argument lists: `file-args`, `rev-args`, and `cmdline-args`. They are mainly intended for testing purposes but also allows to change the filtering arguments dynamically. (GH #306) + - Add `log-options` setting for specifying default log view options. + Example: `set log-options = --pretty=fuller`. Bug fixes: @@ -30,6 +32,10 @@ Bug fixes: - Fix commit title overflow drawing for multibyte text. (GH #307) - Fix installation directory permissions. - Handle binary files matches reported by git-grep. + - Toggling of "args"-typed options without any arguments will clear the current + arguments. Example: `:toggle blame-options`. + - Detect custom `pretty.format` settings that break the log view and fallback + to use the `medium` format. (GH #225) tig-2.0.2 --------- diff --git a/include/tig/options.h b/include/tig/options.h index 572aac2..64f248d 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -42,6 +42,7 @@ _(ignore_case, bool, VIEW_NO_FLAGS) \ _(ignore_space, enum ignore_space, VIEW_DIFF_LIKE) \ _(line_graphics, enum graphic, VIEW_NO_FLAGS) \ + _(log_options, const char **, VIEW_LOG_LIKE) \ _(log_view, const char **, VIEW_NO_FLAGS) \ _(main_view, const char **, VIEW_NO_FLAGS) \ _(mouse, bool, VIEW_NO_FLAGS) \ diff --git a/src/argv.c b/src/argv.c index ace4bd2..60742f6 100644 --- a/src/argv.c +++ b/src/argv.c @@ -334,6 +334,10 @@ argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_a if (!format_append_argv(&format, dst_argv, opt_blame_options)) break; + } else if (!strcmp(arg, "%(logargs)")) { + if (!format_append_argv(&format, dst_argv, opt_log_options)) + break; + } else if (!strcmp(arg, "%(cmdlineargs)")) { if (!format_append_argv(&format, dst_argv, opt_cmdline_args)) break; diff --git a/src/log.c b/src/log.c index 79f2479..1606f87 100644 --- a/src/log.c +++ b/src/log.c @@ -65,8 +65,8 @@ log_open(struct view *view, enum open_flags flags) { const char *log_argv[] = { "git", "log", encoding_arg, commit_order_arg(), "--cc", - "--stat", "%(cmdlineargs)", "%(revargs)", "--no-color", - "--", "%(fileargs)", NULL + "--stat", "%(logargs)", "%(cmdlineargs)", "%(revargs)", + "--no-color", "--", "%(fileargs)", NULL }; return begin_update(view, NULL, log_argv, flags); diff --git a/src/options.c b/src/options.c index 3ec167b..1c9844b 100644 --- a/src/options.c +++ b/src/options.c @@ -1075,6 +1075,10 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen else if (!strcmp(name, "diff.context")) { if (!find_option_info_by_value(&opt_diff_context)->seen) opt_diff_context = -atoi(value); + + } else if (!strcmp(name, "format.pretty")) { + if (!prefixcmp(value, "format:") && strstr(value, "%C(")) + argv_append(&opt_log_options, "--pretty=medium"); } return OK; diff --git a/src/prompt.c b/src/prompt.c index 17bce77..0dcad7a 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -628,6 +628,12 @@ prompt_toggle_option(struct view *view, const char *argv[], const char *prefix, bool found = TRUE; int i; + if (argv_size(argv) <= 2) { + argv_free(*opt); + (*opt)[0] = NULL; + return SUCCESS; + } + for (i = 2; argv[i]; i++) { if (!find_arg(*opt, argv[i])) { found = FALSE; diff --git a/test/log/pretty-format-test b/test/log/pretty-format-test new file mode 100755 index 0000000..79f4341 --- /dev/null +++ b/test/log/pretty-format-test @@ -0,0 +1,123 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh + +export LINES=20 + +tigrc < +Date: 2010-04-07 + + Commit 10 E + +commit 2843bfd58b98c7e23ab91e51ffa4db4f8e27c9a4 +Author: Jørgen Thygesen Brahe +Date: 2010-03-29 + + Commit 10 D + +commit 8d53d6a41f8540749c0db5d0b53e48d2f178dce4 +Author: 作者 +Date: 2010-03-21 + + Commit 10 C +[log] 5cb3412a5e06e506840495b91acc885037a48b72 - line 1 of 301 5% +EOF + +assert_equals 'log-pretty-raw.screen' < 1270618660 +0000 +committer Committer 1270618660 +0000 + + Commit 10 E + +commit 2843bfd58b98c7e23ab91e51ffa4db4f8e27c9a4 +tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 +parent 8d53d6a41f8540749c0db5d0b53e48d2f178dce4 +author Jørgen Thygesen Brahe 1269882930 +0000 +committer Committer 1269882930 +0000 + + Commit 10 D + +commit 8d53d6a41f8540749c0db5d0b53e48d2f178dce4 +[log] 5cb3412a5e06e506840495b91acc885037a48b72 - line 1 of 400 4% +EOF + +assert_equals 'log-pretty-full.screen' < +Commit: Committer + + Commit 10 E + +commit 2843bfd58b98c7e23ab91e51ffa4db4f8e27c9a4 +Author: Jørgen Thygesen Brahe +Commit: Committer + + Commit 10 D + +commit 8d53d6a41f8540749c0db5d0b53e48d2f178dce4 +Author: 作者 +Commit: Committer + + Commit 10 C +[log] 5cb3412a5e06e506840495b91acc885037a48b72 - line 1 of 301 5% +EOF + +assert_equals 'log-pretty-fuller.screen' < +AuthorDate: Wed Apr 7 05:37:40 2010 +0000 +Commit: Committer +CommitDate: Wed Apr 7 05:37:40 2010 +0000 + + Commit 10 E + +commit 2843bfd58b98c7e23ab91e51ffa4db4f8e27c9a4 +Author: Jørgen Thygesen Brahe +AuthorDate: Mon Mar 29 17:15:30 2010 +0000 +Commit: Committer +CommitDate: Mon Mar 29 17:15:30 2010 +0000 + + Commit 10 D + +commit 8d53d6a41f8540749c0db5d0b53e48d2f178dce4 +[log] 5cb3412a5e06e506840495b91acc885037a48b72 - line 1 of 401 4% +EOF -- 2.11.4.GIT