Skip to content

Commit

Permalink
diff: introduce diff.submodule configuration variable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ramkumar Ramachandra authored and Junio C Hamano committed Nov 19, 2012
1 parent 22bc70f commit c47ef57
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Documentation/diff-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ diff.suppressBlankEmpty::
A boolean to inhibit the standard behavior of printing a space
before each empty output line. Defaults to false.

diff.submodule::
Specify the format in which differences in submodules are
shown. The "log" format lists the commits in the range like
linkgit:git-submodule[1] `summary` does. The "short" format
format just shows the names of the commits at the beginning
and end of the range. Defaults to short.

diff.wordRegex::
A POSIX Extended Regular Expression used to determine what is a "word"
when performing word-by-word difference calculations. Character
Expand Down
3 changes: 2 additions & 1 deletion Documentation/diff-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ any of those replacements occurred.
the commits in the range like linkgit:git-submodule[1] `summary` does.
Omitting the `--submodule` option or specifying `--submodule=short`,
uses the 'short' format. This format just shows the names of the commits
at the beginning and end of the range.
at the beginning and end of the range. Can be tweaked via the
`diff.submodule` configuration variable.

--color[=<when>]::
Show colored diff.
Expand Down
32 changes: 28 additions & 4 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
return ret;
}

static int parse_submodule_params(struct diff_options *options, const char *value)
{
if (!strcmp(value, "log"))
DIFF_OPT_SET(options, SUBMODULE_LOG);
else if (!strcmp(value, "short"))
DIFF_OPT_CLR(options, SUBMODULE_LOG);
else
return -1;
return 0;
}

static int git_config_rename(const char *var, const char *value)
{
if (!value)
Expand Down Expand Up @@ -176,6 +187,13 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "diff.ignoresubmodules"))
handle_ignore_submodules_arg(&default_diff_options, value);

if (!strcmp(var, "diff.submodule")) {
if (parse_submodule_params(&default_diff_options, value))
warning(_("Unknown value for 'diff.submodule' config variable: '%s'"),
value);
return 0;
}

if (git_color_config(var, value, cb) < 0)
return -1;

Expand Down Expand Up @@ -3473,6 +3491,14 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
return 1;
}

static int parse_submodule_opt(struct diff_options *options, const char *value)
{
if (parse_submodule_params(options, value))
die(_("Failed to parse --submodule option parameter: '%s'"),
value);
return 1;
}

int diff_opt_parse(struct diff_options *options, const char **av, int ac)
{
const char *arg = av[0];
Expand Down Expand Up @@ -3653,10 +3679,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
handle_ignore_submodules_arg(options, arg + 20);
} else if (!strcmp(arg, "--submodule"))
DIFF_OPT_SET(options, SUBMODULE_LOG);
else if (!prefixcmp(arg, "--submodule=")) {
if (!strcmp(arg + 12, "log"))
DIFF_OPT_SET(options, SUBMODULE_LOG);
}
else if (!prefixcmp(arg, "--submodule="))
return parse_submodule_opt(options, arg + 12);

/* misc options */
else if (!strcmp(arg, "-z"))
Expand Down
29 changes: 28 additions & 1 deletion t/t4041-diff-submodule-option.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test_create_repo sm1 &&
add_file . foo >/dev/null

head1=$(add_file sm1 foo1 foo2)
fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)

test_expect_success 'added submodule' "
git add sm1 &&
Expand All @@ -43,6 +44,33 @@ EOF
test_cmp expected actual
"

test_expect_success 'added submodule, set diff.submodule' "
git config diff.submodule log &&
git add sm1 &&
git diff --cached >actual &&
cat >expected <<-EOF &&
Submodule sm1 0000000...$head1 (new submodule)
EOF
git config --unset diff.submodule &&
test_cmp expected actual
"

test_expect_success '--submodule=short overrides diff.submodule' "
test_config diff.submodule log &&
git add sm1 &&
git diff --submodule=short --cached >actual &&
cat >expected <<-EOF &&
diff --git a/sm1 b/sm1
new file mode 160000
index 0000000..a2c4dab
--- /dev/null
+++ b/sm1
@@ -0,0 +1 @@
+Subproject commit $fullhead1
EOF
test_cmp expected actual
"

commit_file sm1 &&
head2=$(add_file sm1 foo3)

Expand Down Expand Up @@ -73,7 +101,6 @@ EOF
test_cmp expected actual
"

fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
test_expect_success 'modified submodule(forward) --submodule=short' "
git diff --submodule=short >actual &&
Expand Down

0 comments on commit c47ef57

Please sign in to comment.