git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/5] diff: introduce diff.submoduleFormat configuration variable

From
Jens Lehmann <jens.lehmann@web.de>
Date
Oct 2, 2012, 19:44 UTC
Message-ID
<506B4418.2050700@web.de>
In-Reply-To
<1349196670-2844-5-git-send-email-artagnon@gmail.com>
Am 02.10.2012 18:51, schrieb Ramkumar Ramachandra:
> Introduce a diff.submoduleFormat configuration variable corresponding
> to the '--submodule' command-line option of 'git diff'.

Nice. Maybe a better name would be "diff.submodule", as this sets the default for the "--submodule" option of diff?

And I think you should also test in t4041 that "--submodule=short" overrides the config setting.

Show 112 quoted lines
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
>  Documentation/diff-config.txt    |    7 +++++++
>  Documentation/diff-options.txt   |    3 ++-
>  diff.c                           |   25 ++++++++++++++++---------
>  t/t4041-diff-submodule-option.sh |   10 ++++++++++
>  4 files changed, 35 insertions(+), 10 deletions(-)
> 
> diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
> index 04574f9..e445cc8 100644
> --- a/Documentation/diff-config.txt
> +++ b/Documentation/diff-config.txt
> @@ -103,6 +103,13 @@ diff.suppressBlankEmpty::
>  	A boolean to inhibit the standard behavior of printing a space
>  	before each empty output line. Defaults to false.
>  
> +diff.submoduleFormat::
> +	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
> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
> index cf4b216..034c4e7 100644
> --- a/Documentation/diff-options.txt
> +++ b/Documentation/diff-options.txt
> @@ -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.submoduleFormat` configuration variable.
>  
>  --color[=<when>]::
>  	Show colored diff.
> diff --git a/diff.c b/diff.c
> index 8ea40f9..4cb8dd2 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -28,6 +28,7 @@ static int diff_suppress_blank_empty;
>  static int diff_use_color_default = -1;
>  static const char *diff_word_regex_cfg;
>  static const char *external_diff_cmd_cfg;
> +static const char *submodule_format_cfg;
>  int diff_auto_refresh_index = 1;
>  static int diff_mnemonic_prefix;
>  static int diff_no_prefix;
> @@ -161,6 +162,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
>  		diff_stat_graph_width = git_config_int(var, value);
>  		return 0;
>  	}
> +	if (!strcmp(var, "diff.submoduleformat"))
> +		return git_config_string(&submodule_format_cfg, var, value);
>  	if (!strcmp(var, "diff.external"))
>  		return git_config_string(&external_diff_cmd_cfg, var, value);
>  	if (!strcmp(var, "diff.wordregex"))
> @@ -2227,15 +2230,19 @@ static void builtin_diff(const char *name_a,
>  		line_prefix = msgbuf->buf;
>  	}
>  
> -	if (DIFF_OPT_TST(o, SUBMODULE_LOG) &&
> -			(!one->mode || S_ISGITLINK(one->mode)) &&
> -			(!two->mode || S_ISGITLINK(two->mode))) {
> -		const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
> -		const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
> -		show_submodule_summary(o->file, one ? one->path : two->path,
> -				one->sha1, two->sha1, two->dirty_submodule,
> -				del, add, reset);
> -		return;
> +	if (!DIFF_OPT_TST(o, SUBMODULE_SHORT) &&
> +		((!one->mode || S_ISGITLINK(one->mode)) &&
> +			(!two->mode || S_ISGITLINK(two->mode)))) {
> +		if (DIFF_OPT_TST(o, SUBMODULE_LOG) ||
> +			(submodule_format_cfg &&
> +				!strcmp(submodule_format_cfg, "log"))) {
> +			const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
> +			const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
> +			show_submodule_summary(o->file, one ? one->path : two->path,
> +					one->sha1, two->sha1, two->dirty_submodule,
> +					del, add, reset);
> +			return;
> +		}
>  	}
>  
>  	if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
> diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> index 6c01d0c..ed4f3a8 100755
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -43,6 +43,16 @@ EOF
>  	test_cmp expected actual
>  "
>  
> +test_expect_success 'added submodule, set diff.submoduleFormat' "
> +	git config diff.submoduleFormat log &&
> +	git add sm1 &&
> +	git diff --cached >actual &&
> +	cat >expected <<-EOF &&
> +Submodule sm1 0000000...$head1 (new submodule)
> +EOF
> +	test_cmp expected actual
> +"
> +
>  commit_file sm1 &&
>  head2=$(add_file sm1 foo3)
>  
> 
Previous: Ramkumar RamachandraNext: Jens Lehmann
Message 10 of 14 in “submodule: introduce diff.submoduleFormat”
  1. 0/5 submodule: introduce diff.submoduleFormatRamkumar Ramachandra, Oct 2, 2012
  2. 1/5 Documentation: move diff.wordRegex from config.txt to diff-config.txtRamkumar Ramachandra, Oct 2, 2012
  3. 2/5 Documentation: sort diff-config.txt alphabeticallyRamkumar Ramachandra, Oct 2, 2012
  4. 3/5 diff: acknowledge --submodule=short command-line optionRamkumar Ramachandra, Oct 2, 2012
  5. Jens LehmannOct 2, 2012
  6. Ramkumar RamachandraOct 7, 2012
  7. Jens LehmannOct 7, 2012
  8. Jens LehmannOct 7, 2012
  9. 4/5 diff: introduce diff.submoduleFormat configuration variableRamkumar Ramachandra, Oct 2, 2012
  10. Jens LehmannOct 2, 2012
  11. Jens LehmannOct 3, 2012
  12. Ramkumar RamachandraOct 29, 2012
  13. Jens LehmannOct 30, 2012
  14. 5/5 submodule: display summary header in boldRamkumar Ramachandra, Oct 2, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.