diff: introduce diff.submodule configuration variable

Introduce a diff.submodule configuration variable corresponding to the '--submodule' command-line option of 'git diff'. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Nov 13, 2012 at 21:12 UTC c47ef57caaa2b17d32b343fbe652f33b31c81362
4 files changed +65 -6
Documentation/diff-config.txt
+7
@@ -107,6 +107,13 @@ diff.suppressBlankEmpty::
107 A boolean to inhibit the standard behavior of printing a space
108 before each empty output line. Defaults to false.
109
110 +diff.submodule::
111 + Specify the format in which differences in submodules are
112 + shown. The "log" format lists the commits in the range like
113 + linkgit:git-submodule[1] `summary` does. The "short" format
114 + format just shows the names of the commits at the beginning
115 + and end of the range. Defaults to short.
116 +
117 diff.wordRegex::
118 A POSIX Extended Regular Expression used to determine what is a "word"
119 when performing word-by-word difference calculations. Character
Documentation/diff-options.txt
+2 -1
@@ -170,7 +170,8 @@ any of those replacements occurred.
170 the commits in the range like linkgit:git-submodule[1] `summary` does.
171 Omitting the `--submodule` option or specifying `--submodule=short`,
172 uses the 'short' format. This format just shows the names of the commits
173 - at the beginning and end of the range.
173 + at the beginning and end of the range. Can be tweaked via the
174 + `diff.submodule` configuration variable.
175
176 --color[=<when>]::
177 Show colored diff.
diff.c
+28 -4
@@ -121,6 +121,17 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
121 return ret;
122 }
123
124 +static int parse_submodule_params(struct diff_options *options, const char *value)
125 +{
126 + if (!strcmp(value, "log"))
127 + DIFF_OPT_SET(options, SUBMODULE_LOG);
128 + else if (!strcmp(value, "short"))
129 + DIFF_OPT_CLR(options, SUBMODULE_LOG);
130 + else
131 + return -1;
132 + return 0;
133 +}
134 +
135 static int git_config_rename(const char *var, const char *value)
136 {
137 if (!value)
@@ -176,6 +187,13 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
187 if (!strcmp(var, "diff.ignoresubmodules"))
188 handle_ignore_submodules_arg(&default_diff_options, value);
189
190 + if (!strcmp(var, "diff.submodule")) {
191 + if (parse_submodule_params(&default_diff_options, value))
192 + warning(_("Unknown value for 'diff.submodule' config variable: '%s'"),
193 + value);
194 + return 0;
195 + }
196 +
197 if (git_color_config(var, value, cb) < 0)
198 return -1;
199
@@ -3473,6 +3491,14 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
3491 return 1;
3492 }
3493
3494 +static int parse_submodule_opt(struct diff_options *options, const char *value)
3495 +{
3496 + if (parse_submodule_params(options, value))
3497 + die(_("Failed to parse --submodule option parameter: '%s'"),
3498 + value);
3499 + return 1;
3500 +}
3501 +
3502 int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3503 {
3504 const char *arg = av[0];
@@ -3653,10 +3679,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3679 handle_ignore_submodules_arg(options, arg + 20);
3680 } else if (!strcmp(arg, "--submodule"))
3681 DIFF_OPT_SET(options, SUBMODULE_LOG);
3656 - else if (!prefixcmp(arg, "--submodule=")) {
3657 - if (!strcmp(arg + 12, "log"))
3658 - DIFF_OPT_SET(options, SUBMODULE_LOG);
3659 - }
3682 + else if (!prefixcmp(arg, "--submodule="))
3683 + return parse_submodule_opt(options, arg + 12);
3684
3685 /* misc options */
3686 else if (!strcmp(arg, "-z"))
t/t4041-diff-submodule-option.sh
+28 -1
@@ -33,6 +33,7 @@ test_create_repo sm1 &&
33 add_file . foo >/dev/null
34
35 head1=$(add_file sm1 foo1 foo2)
36 +fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
37
38 test_expect_success 'added submodule' "
39 git add sm1 &&
@@ -43,6 +44,33 @@ EOF
44 test_cmp expected actual
45 "
46
47 +test_expect_success 'added submodule, set diff.submodule' "
48 + git config diff.submodule log &&
49 + git add sm1 &&
50 + git diff --cached >actual &&
51 + cat >expected <<-EOF &&
52 +Submodule sm1 0000000...$head1 (new submodule)
53 +EOF
54 + git config --unset diff.submodule &&
55 + test_cmp expected actual
56 +"
57 +
58 +test_expect_success '--submodule=short overrides diff.submodule' "
59 + test_config diff.submodule log &&
60 + git add sm1 &&
61 + git diff --submodule=short --cached >actual &&
62 + cat >expected <<-EOF &&
63 +diff --git a/sm1 b/sm1
64 +new file mode 160000
65 +index 0000000..a2c4dab
66 +--- /dev/null
67 ++++ b/sm1
68 +@@ -0,0 +1 @@
69 ++Subproject commit $fullhead1
70 +EOF
71 + test_cmp expected actual
72 +"
73 +
74 commit_file sm1 &&
75 head2=$(add_file sm1 foo3)
76
@@ -73,7 +101,6 @@ EOF
101 test_cmp expected actual
102 "
103
76 -fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
104 fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
105 test_expect_success 'modified submodule(forward) --submodule=short' "
106 git diff --submodule=short >actual &&