Introduce diff.submodule
v3 cover Introduce diff.submodule
v1 is here: http://mid.gmane.org/[email protected]
v2 is here: http://mid.gmane.org/[email protected]
This version was prepared in response to Peff's review of v2. As suggested, I've created a separate function which both '--submodule' and 'diff.submodule' use to set/ unset SUBMODULE_OPT.
Ram
Ramkumar Ramachandra (3):
Documentation: move diff.wordRegex from config.txt to diff-config.txt
diff: introduce diff.submodule configuration variable
submodule: display summary header in bold
Documentation/config.txt | 6 ----- Documentation/diff-config.txt | 13 +++++++++++ Documentation/diff-options.txt | 3 +- cache.h | 1 + diff.c | 42 +++++++++++++++++++++++++++++++++---- submodule.c | 8 +++--- submodule.h | 2 +- t/t4041-diff-submodule-option.sh | 30 ++++++++++++++++++++++++++- 8 files changed, 87 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.8.1.362.g5d6df.dirty
PATCH v3 1/3 Documentation: move diff.wordRegex from config.txt to diff-config.txt
19299a8 (Documentation: Move diff.<driver>.* from config.txt to diff-config.txt, 2011-04-07) moved the diff configuration options to diff-config.txt, but forgot about diff.wordRegex, which was left behind in config.txt. Fix this.
--- Documentation/config.txt | 6 ------ Documentation/diff-config.txt | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-)
Documentation/config.txt +0 -6
@@ -962,12 +962,6 @@ difftool.<tool>.cmd:: difftool.prompt:: Prompt before each invocation of the diff tool. -diff.wordRegex:: - A POSIX Extended Regular Expression used to determine what is a "word" - when performing word-by-word difference calculations. Character - sequences that match the regular expression are "words", all other - characters are *ignorable* whitespace. - fetch.recurseSubmodules:: This option can be either set to a boolean value or to 'on-demand'. Setting it to a boolean changes the behavior of fetch and pull to
Documentation/diff-config.txt +6 -0
@@ -107,6 +107,12 @@ diff.suppressBlankEmpty:: A boolean to inhibit the standard behavior of printing a space before each empty output line. Defaults to false. +diff.wordRegex:: + A POSIX Extended Regular Expression used to determine what is a "word" + when performing word-by-word difference calculations. Character + sequences that match the regular expression are "words", all other + characters are *ignorable* whitespace. + diff.<driver>.command:: The custom diff driver command. See linkgit:gitattributes[5] for details.
Signature · 1 line
1.7.8.1.362.g5d6df.dirty
PATCH v3 2/3 diff: introduce diff.submodule configuration variable
In reply to Ramkumar RamachandraIntroduce a diff.submodule configuration variable corresponding to the '--submodule' command-line option of 'git diff'.
--- Documentation/diff-config.txt | 7 ++++++ Documentation/diff-options.txt | 3 +- cache.h | 1 + diff.c | 40 ++++++++++++++++++++++++++++++++++--- t/t4041-diff-submodule-option.sh | 30 +++++++++++++++++++++++++++- 5 files changed, 75 insertions(+), 6 deletions(-)
Documentation/diff-config.txt +7 -0
@@ -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
Documentation/diff-options.txt +2 -1
@@ -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.
cache.h +1 -0
@@ -1221,6 +1221,7 @@ int add_files_to_cache(const char *prefix, const char **pathspec, int flags);/* diff.c */ extern int diff_auto_refresh_index; +extern const char *submodule_format_cfg;/* match-trees.c */ void shift_tree (const unsigned char *,const unsigned char *,unsigned char *,int );
diff.c +36 -4
@@ -30,6 +30,7 @@ static int diff_use_color_default = -1;static int diff_context_default =3 ;static const char *diff_word_regex_cfg;static const char *external_diff_cmd_cfg; +const char *submodule_format_cfg;int diff_auto_refresh_index =1 ;static int diff_mnemonic_prefix;static int diff_no_prefix;
@@ -123,6 +124,20 @@ static int parse_dirstat_params(struct diff_options *options, const char *paramsreturn ret; } +static int parse_submodule_params (struct diff_options *options,const char *value, +struct strbuf *errmsg) +{ +if (!strcmp (value,"log" )) +DIFF_OPT_SET (options,SUBMODULE_LOG ); +else if (!strcmp (value,"short" )) +DIFF_OPT_CLR (options,SUBMODULE_LOG ); +else { +strbuf_addf (errmsg,_ ("'%s'" ), value); +return 1 ; + } +return 0 ; +} +static int git_config_rename (const char *var,const char *value) {if (!value)
@@ -223,6 +238,15 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)return 0 ; } +if (!strcmp (var,"diff.submodule" )) { +struct strbuf errmsg =STRBUF_INIT ; +if (parse_submodule_params (&default_diff_options, value, &errmsg)) +warning (_ ("Unknown value for 'diff.submodule' config variable: %s" ), + errmsg.buf); +strbuf_release (&errmsg); +return 0 ; + } +if (!prefixcmp (var,"submodule." ))return parse_submodule_config_option (var, value);
@@ -3475,6 +3499,16 @@ 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 *params) +{ +struct strbuf errmsg =STRBUF_INIT ; +if (parse_submodule_params (options, params, &errmsg)) +die (_ ("Failed to parse --submodule option parameter: %s" ), + errmsg.buf); +strbuf_release (&errmsg); +return 1 ; +} +int diff_opt_parse (struct diff_options *options,const char **av,int ac) {const char *arg = av[0 ];
@@ -3655,10 +3689,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" ))
t/t4041-diff-submodule-option.sh +29 -1
@@ -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 &&
@@ -43,6 +44,34 @@ 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' " + git 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 + git config --unset diff.submodule && + test_cmp expected actual +" + commit_file sm1 && head2=$(add_file sm1 foo3)
@@ -73,7 +102,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 &&
Signature · 1 line
1.7.8.1.362.g5d6df.dirty
PATCH v3 3/3 submodule: display summary header in bold
In reply to Ramkumar RamachandraCurrently, 'git diff --submodule' displays output with a bold diff header for non-submodules. So this part is in bold:
diff --git a/file1 b/file1
index 30b2f6c..2638038 100644
--- a/file1
+++ b/file1For submodules, the header looks like this:
Submodule submodule1 012b072..248d0fd:
Unfortunately, it's easy to miss in the output because it's not bold. Change this.
--- diff.c | 2 +- submodule.c | 8 ++++---- submodule.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
diff.c +1 -1
@@ -2267,7 +2267,7 @@ static void builtin_diff(const char *name_a,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); + set, del, add, reset);return ; }
submodule.c +4 -4
@@ -258,7 +258,7 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)void show_submodule_summary (FILE *f,const char *path,unsigned char one[20 ],unsigned char two[20 ], -unsigned dirty_submodule, +unsigned dirty_submodule,const char *set,const char *del,const char *add,const char *reset) {struct rev_info rev;
@@ -292,15 +292,15 @@ void show_submodule_summary(FILE *f, const char *path,return ; } -strbuf_addf (&sb,"Submodule %s %s.." , path, +strbuf_addf (&sb,"%sSubmodule %s %s.." , set, path,find_unique_abbrev (one,DEFAULT_ABBREV ));if (!fast_backward && !fast_forward)strbuf_addch (&sb,'.' );strbuf_addf (&sb,"%s" ,find_unique_abbrev (two,DEFAULT_ABBREV ));if (message) -strbuf_addf (&sb," %s\n" , message); +strbuf_addf (&sb," %s%s\n" , message, reset);else -strbuf_addf (&sb,"%s:\n" , fast_backward ?" (rewind)" :"" ); +strbuf_addf (&sb,"%s:%s\n" , fast_backward ?" (rewind)" :"" , reset);fwrite (sb.buf, sb.len,1 , f);if (!message) {
submodule.h +1 -1
@@ -20,7 +20,7 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);int parse_fetch_recurse_submodules_arg (const char *opt,const char *arg);void show_submodule_summary (FILE *f,const char *path,unsigned char one[20 ],unsigned char two[20 ], -unsigned dirty_submodule, +unsigned dirty_submodule,const char *set,const char *del,const char *add,const char *reset);void set_config_fetch_recurse_submodules (int value);void check_for_new_submodule_commits (unsigned char new_sha1[20 ]);
Signature · 1 line
1.7.8.1.362.g5d6df.dirty
Re: [PATCH 2/3] diff: introduce diff.submodule configuration variable
In reply to Ramkumar Ramachandradiff.c static int parse_dirstat_params(struct diff_options *options, const char *params · line 139
Quoted 13 lines · Ramkumar Ramachandra
diff.c +13
-0+static int parse_submodule_params (struct diff_options *options,const char *value, +struct strbuf *errmsg) +{ +if (!strcmp (value,"log" )) +DIFF_OPT_SET (options,SUBMODULE_LOG ); +else if (!strcmp (value,"short" )) +DIFF_OPT_CLR (options,SUBMODULE_LOG ); +else { +strbuf_addf (errmsg,_ ("'%s'" ), value); +return 1 ; + } +return 0 ; +}
I think "-1" would be the more normal error return.
diff.c int git_diff_basic_config(const char *var, const char *value, void *cb) · line 241
Quoted 5 lines
diff.c +1
-0@@ -223,6 +238,15 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)return 0 ; } +if (!strcmp (var,"diff.submodule" )) {
Shouldn't this be in git_diff_ui_config so it does not affect scripts calling plumbing?
diff.c int git_diff_basic_config(const char *var, const char *value, void *cb) · line 248
Quoted 7 lines
diff.c +7
-0+struct strbuf errmsg =STRBUF_INIT ; +if (parse_submodule_params (&default_diff_options, value, &errmsg)) +warning (_ ("Unknown value for 'diff.submodule' config variable: %s" ), + errmsg.buf); +strbuf_release (&errmsg); +return 0 ; + }
Hmm. This strbuf error handling strikes me as very clunky, considering that it does not pass any useful information out of the parse function (it always just adds '$value' to the error string). Wouldn't it be simpler to just have parse_submodule_params return -1, and then let the caller warn or generate an error as appropriate?
-Peff
Re: [PATCH 2/3] diff: introduce diff.submodule configuration variable
Quoted 9 lines · Jeff King
diff.c int git_diff_basic_config(const char *var, const char *value, void *cb) · line 241
Quoted 5 lines · Ramkumar Ramachandra
diff.c +1
-0@@ -223,6 +238,15 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)return 0 ; } +if (!strcmp (var,"diff.submodule" )) {Shouldn't this be in
git_diff_ui_configso it does not affect scripts calling plumbing?
I honestly didn't understand the difference between git_diff_basic_config and git_diff_ui_config. The latter function calls the former function at the end of its body. Why are they two separate functions in the first place?
Btw, I just posted a follow-up.
Ram
Re: [PATCH 2/3] diff: introduce diff.submodule configuration variable
Quoted 11 lines · Ramkumar Ramachandra
Quoted 9 lines · Jeff King
diff.c int git_diff_basic_config(const char *var, const char *value, void *cb) · line 241
Quoted 5 lines · Ramkumar Ramachandra
diff.c +1
-0@@ -223,6 +238,15 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)return 0 ; } +if (!strcmp (var,"diff.submodule" )) {Shouldn't this be in
git_diff_ui_configso it does not affect scripts calling plumbing?
Quoted 4 lines
I honestly didn't understand the difference between
git_diff_basic_configandgit_diff_ui_config. The latter function calls the former function at the end of its body. Why are they two separate functions in the first place?
In case you meant s/didn't/don't/, git_diff_ui_config() should be called only by human-facing Porcelain commands where their behaviours can and should be affected by end user configuration variables.
When a configuration variable should not affect output from plumbing commands like diff-files, diff-index, and diff-tree, it must not be read in git_diff_basic_config(), but in git_diff_ui_config().
The output from "git format-patch" is consumed by "git apply" that expects "Subproject commit %s\n" with fully spelled object name, so your configuration must not affect the output of format-patch, either.
Re: [PATCH 3/3] submodule: display summary header in bold
In reply to Ramkumar RamachandraQuoted 8 lines · Ramkumar Ramachandra
Currently, 'git diff --submodule' displays output with a bold diff header for non-submodules. So this part is in bold:
diff --git a/file1 b/file1 index 30b2f6c..2638038 100644 --- a/file1 +++ b/file1
Quoted 6 lines
For submodules, the header looks like this:
Submodule submodule1 012b072..248d0fd:Unfortunately, it's easy to miss in the output because it's not bold. Change this.
Reading this, I was at first concerned that you were using "bold" and not DIFF_METAINFO. But:
diff.c static void builtin_diff(const char *name_a, · line 2270
Quoted 10 lines
diff.c +1
-1@@ -2267,7 +2267,7 @@ static void builtin_diff(const char *name_a,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); + set, del, add, reset);
This is correctly passing the DIFF_METAINFO color, which is in the "set" variable. Good. I looked at the output on a sample repository, and it is much easier to read (though I use magenta for my metainfo).
"set" is a terrible name for that variable (not your fault, of course). When you re-roll (and I think you need to because of the diff_ui thing in patch 2), would you mind throwing this cleanup in the middle?
-- >8 --
Subject: builtin_diff: rename "set" variable
Once upon a time the builtin_diff function used one color, and the color variables were called "set" and "reset". Nowadays it is a much longer function and we use several colors (e.g., "add", "del"). Rename "set" to "meta" to show that it is the color for showing diff meta-info (it still does not indicate that it is a "color", but at least it matches the scheme of the other color variables).
--- diff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff.c +6 -6
@@ -2222,7 +2222,7 @@ static void builtin_diff(const char *name_a,mmfile_t mf1, mf2;const char *lbl[2 ];char *a_one, *b_two; -const char *set =diff_get_color_opt (o,DIFF_METAINFO ); +const char *meta =diff_get_color_opt (o,DIFF_METAINFO );const char *reset =diff_get_color_opt (o,DIFF_RESET );const char *a_prefix, *b_prefix;struct userdiff_driver *textconv_one =NULL ;
@@ -2269,24 +2269,24 @@ static void builtin_diff(const char *name_a, b_two =quote_two (b_prefix, name_b + (*name_b =='/' )); lbl[0 ] =DIFF_FILE_VALID (one) ? a_one :"/dev/null" ; lbl[1 ] =DIFF_FILE_VALID (two) ? b_two :"/dev/null" ; -strbuf_addf (&header,"%s%sdiff --git %s %s%s\n" , line_prefix, set, a_one, b_two, reset); +strbuf_addf (&header,"%s%sdiff --git %s %s%s\n" , line_prefix, meta, a_one, b_two, reset);if (lbl[0 ][0 ] =='/' ) {/* /dev/null */ -strbuf_addf (&header,"%s%snew file mode %06o%s\n" , line_prefix, set, two->mode, reset); +strbuf_addf (&header,"%s%snew file mode %06o%s\n" , line_prefix, meta, two->mode, reset);if (xfrm_msg)strbuf_addstr (&header, xfrm_msg); must_show_header =1 ; }else if (lbl[1 ][0 ] =='/' ) { -strbuf_addf (&header,"%s%sdeleted file mode %06o%s\n" , line_prefix, set, one->mode, reset); +strbuf_addf (&header,"%s%sdeleted file mode %06o%s\n" , line_prefix, meta, one->mode, reset);if (xfrm_msg)strbuf_addstr (&header, xfrm_msg); must_show_header =1 ; }else {if (one->mode != two->mode) { -strbuf_addf (&header,"%s%sold mode %06o%s\n" , line_prefix, set, one->mode, reset); -strbuf_addf (&header,"%s%snew mode %06o%s\n" , line_prefix, set, two->mode, reset); +strbuf_addf (&header,"%s%sold mode %06o%s\n" , line_prefix, meta, one->mode, reset); +strbuf_addf (&header,"%s%snew mode %06o%s\n" , line_prefix, meta, two->mode, reset); must_show_header =1 ; }if (xfrm_msg)
Quoted 6 lines · Ramkumar Ramachandra
v1 is here: http://mid.gmane.org/[email protected]
v2 is here: http://mid.gmane.org/[email protected]This version was prepared in response to Peff's review of v2. As suggested, I've created a separate function which both '--submodule' and 'diff.submodule' use to set/ unset
SUBMODULE_OPT.
Junio, can we pick this up?
Ram