Make support for multi-value configuration options more consistent
cover Make support for multi-value configuration options more consistent
This series adds support for optional placing of additional whitespace characters around the commas in the multi-value, comma-separated values for the "diff.dirstat" and "diff.wsErrorHighlight" configuration options, and the "--dirstat" and "--ws-error-highlight" command-line options.
This makes the way multi-(sub)value configuration options can be specified more consistent, because exactly the same additional whitespace characters are already allowed for some of the configuration options. It may also make the configuration files more readable to some users.
Dragan Simic (3):
diff: support additional whitespace in diff.{dirstat,wsErrorHighlight}
t4015: whitespace in diff.wsErrorHighlight and --ws-error-highlight
t4047: whitespace in diff.dirstat and --dirstat
builtin/gc.c | 4 ++-- diff.c | 14 ++++++++++---- notes.c | 2 +- refs/packed-backend.c | 2 +- string-list.c | 27 +++++++++++++++++++++------ string-list.h | 10 ++++++---- t/helper/test-hashmap.c | 2 +- t/helper/test-json-writer.c | 2 +- t/helper/test-oidmap.c | 2 +- t/helper/test-string-list.c | 4 ++-- t/t4015-diff-whitespace.sh | 36 ++++++++++++++++++++++++++++++++++-- t/t4047-diff-dirstat.sh | 33 ++++++++++++++++++++++++++++++--- 12 files changed, 110 insertions(+), 28 deletions(-)
PATCH 1/3 diff: support additional whitespace in diff.{dirstat,wsErrorHighlight}
Allow additional whitespace characters to be placed around the commas in the multi-(sub)value, comma-separated values for the "diff.dirstat" and "diff.wsErrorHighlight" configuration options. This makes the way multi-value configuration options can be specified more consistent, because exactly the same additional whitespace characters are already allowed for some of the configuration options, including "core.whitespace", "log.graphColors" and "color.blame.highlightRecent".
Besides improving the consistency of the configuration syntax, being able to include additional whitespace characters into the values of a couple more of the comma-separated configuration values may also make the configuration files more readable to some users.
This optional support for the additional whitespace around the commas also extends to the equivalent comma-separated values for the "--dirstat" and "--ws-error-highlight" command-line options.
--- builtin/gc.c | 4 ++-- diff.c | 14 ++++++++++---- notes.c | 2 +- refs/packed-backend.c | 2 +- string-list.c | 27 +++++++++++++++++++++------ string-list.h | 10 ++++++---- t/helper/test-hashmap.c | 2 +- t/helper/test-json-writer.c | 2 +- t/helper/test-oidmap.c | 2 +- t/helper/test-string-list.c | 4 ++-- 10 files changed, 46 insertions(+), 23 deletions(-)
builtin/gc.c +2 -2
@@ -1702,11 +1702,11 @@ static int get_schedule_cmd(const char **cmd, int *is_available)if (is_available) *is_available =0 ; -string_list_split_in_place (&list, testing,"," ,-1 ); +string_list_split_in_place (&list, testing,"," ,"" ,-1 );for_each_string_list_item (item, &list) {struct string_list pair =STRING_LIST_INIT_NODUP ; -if (string_list_split_in_place (&pair, item->string,":" ,2 ) !=2 ) +if (string_list_split_in_place (&pair, item->string,":" ,"" ,2 ) !=2 )continue ;if (!strcmp (*cmd, pair.items[0 ].string)) {
diff.c +10 -4
@@ -141,7 +141,7 @@ static int parse_dirstat_params(struct diff_options *options, const char *paramsint i;if (*params_copy) -string_list_split_in_place (¶ms, params_copy,"," ,-1 ); +string_list_split_in_place (¶ms, params_copy,"," ," \t\n\r" ,-1 );for (i =0 ; i < params.nr; i++) {const char *p = params.items[i].string;if (!strcmp (p,"changes" )) {
@@ -232,10 +232,16 @@ long parse_algorithm_value(const char *value)static int parse_one_token (const char **arg,const char *token) { +const char ignored[] =" \t\n\r" ;const char *rest; -if (skip_prefix (*arg, token, &rest) && (!*rest || *rest ==',' )) { - *arg = rest; -return 1 ; + + *arg +=strspn (*arg, ignored); +if (skip_prefix (*arg, token, &rest)) { + rest +=strspn (rest, ignored); +if (!*rest || *rest ==',' ) { + *arg = rest; +return 1 ; + } }return 0 ; }
notes.c +1 -1
@@ -962,7 +962,7 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,char *globs_copy =xstrdup (globs);int i; -string_list_split_in_place (&split, globs_copy,":" ,-1 ); +string_list_split_in_place (&split, globs_copy,":" ,"" ,-1 );string_list_remove_empty_items (&split,0 );for (i =0 ; i < split.nr; i++)
refs/packed-backend.c +1 -1
@@ -676,7 +676,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs) snapshot->buf, snapshot->eof - snapshot->buf); -string_list_split_in_place (&traits, p," " ,-1 ); +string_list_split_in_place (&traits, p," " ,"" ,-1 );if (unsorted_string_list_has_string (&traits,"fully-peeled" )) snapshot->peeled =PEELED_FULLY ;
string-list.c +21 -6
@@ -309,21 +309,36 @@ int string_list_split(struct string_list *list, const char *string, }int string_list_split_in_place (struct string_list *list,char *string, -const char *delim,int maxsplit) +const char *delim,const char *ignored, +int maxsplit) {int count =0 ; -char *p = string, *end; +char *p = string, *trim, *end; +size_t length =strlen (string);if (list->strdup_strings)die ("internal error in string_list_split_in_place(): " "list->strdup_strings must not be set" ); +for (;;) { count++; -if (maxsplit >=0 && count > maxsplit) { -string_list_append (list, p); -return count; +if (*ignored) { + trim = p +strspn (p, ignored); +while (p != trim) + *p++ ='\0' ; + } +if (maxsplit >=0 && count > maxsplit) + end =NULL ; +else + end =strpbrk (p, delim); +if (*ignored) { +if (end) + trim = end -1 ; +else + trim = string + length -1 ; +while (trim >= string &&strchr (ignored, *trim)) + *trim-- ='\0' ; } - end =strpbrk (p, delim);if (end) { *end ='\0' ;string_list_append (list, p);
string-list.h +6 -4
@@ -274,11 +274,13 @@ int string_list_split(struct string_list *list, const char *string,/* * Like string_list_split(), except that string is split in-place: the -* delimiter characters in string are overwritten with NULs, and the -* new string_list_items point into string (which therefore must not -* be modified or freed while the string_list is in use). +* delimiter characters in string and the optionally ignored characters +* that surround the substrings after splitting are overwritten with NULs, +* and the new string_list_items point into string (which therefore must +* not be modified or freed while the string_list is in use). * list->strdup_strings must *not* be set. */ int string_list_split_in_place (struct string_list *list,char *string, -const char *delim,int maxsplit); +const char *delim,const char *ignored, +int maxsplit);#endif /* STRING_LIST_H */
t/helper/test-hashmap.c +1 -1
@@ -167,7 +167,7 @@ int cmd__hashmap(int argc, const char **argv)/* break line into command and up to two parameters */ string_list_setlen (&parts,0 ); -string_list_split_in_place (&parts, line.buf,DELIM ,2 ); +string_list_split_in_place (&parts, line.buf,DELIM ,"" ,2 );string_list_remove_empty_items (&parts,0 );/* ignore empty lines */
t/helper/test-json-writer.c +1 -1
@@ -490,7 +490,7 @@ static int scripted(void)/* break line into command and zero or more tokens */ string_list_setlen (&parts,0 ); -string_list_split_in_place (&parts, line," " ,-1 ); +string_list_split_in_place (&parts, line," " ,"" ,-1 );string_list_remove_empty_items (&parts,0 );/* ignore empty lines */
t/helper/test-oidmap.c +1 -1
@@ -44,7 +44,7 @@ int cmd__oidmap(int argc UNUSED, const char **argv UNUSED)/* break line into command and up to two parameters */ string_list_setlen (&parts,0 ); -string_list_split_in_place (&parts, line.buf,DELIM ,2 ); +string_list_split_in_place (&parts, line.buf,DELIM ,"" ,2 );string_list_remove_empty_items (&parts,0 );/* ignore empty lines */
t/helper/test-string-list.c +2 -2
@@ -65,7 +65,7 @@ int cmd__string_list(int argc, const char **argv)const char *delim = argv[3 ];int maxsplit =atoi (argv[4 ]); - i =string_list_split_in_place (&list, s, delim, maxsplit); + i =string_list_split_in_place (&list, s, delim,"" , maxsplit);printf ("%d\n" , i);write_list (&list);string_list_clear (&list,0 );
@@ -111,7 +111,7 @@ int cmd__string_list(int argc, const char **argv)*/ if (sb.len && sb.buf[sb.len -1 ] =='\n' )strbuf_setlen (&sb, sb.len -1 ); -string_list_split_in_place (&list, sb.buf,"\n" ,-1 ); +string_list_split_in_place (&list, sb.buf,"\n" ,"" ,-1 );string_list_sort (&list);
PATCH 2/3 t4015: whitespace in diff.wsErrorHighlight and --ws-error-highlight
In reply to Dragan SimicAdd a few more tests to cover the support for optional placing of additional whitespace characters around the commas in the multi-value, comma-separated values for the "diff.wsErrorHighlight" configuration option and the "--ws-error-highlight" command-line option.
--- t/t4015-diff-whitespace.sh | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
t/t4015-diff-whitespace.sh +34 -2
@@ -1088,7 +1088,7 @@ test_expect_success 'ws-error-highlight test setup' ' ' -test_expect_success 'test --ws-error-highlight option' ' +test_expect_success 'test --ws-error-highlight option with no spaces' ' git diff --color --ws-error-highlight=default,old >current.raw && test_decode_color <current.raw >current &&
@@ -1104,7 +1104,23 @@ test_expect_success 'test --ws-error-highlight option' ' ' -test_expect_success 'test diff.wsErrorHighlight config' ' +test_expect_success 'test --ws-error-highlight option with spaces' ' + + git diff --color --ws-error-highlight="default, old" >current.raw && + test_decode_color <current.raw >current && + test_cmp expect.default-old current && + + git diff --color --ws-error-highlight="default , old" >current.raw && + test_decode_color <current.raw >current && + test_cmp expect.default-old current && + + git diff --color --ws-error-highlight=" default , old " >current.raw && + test_decode_color <current.raw >current && + test_cmp expect.default-old current + +' + +test_expect_success 'test diff.wsErrorHighlight config with no spaces' ' git -c diff.wsErrorHighlight=default,old diff --color >current.raw && test_decode_color <current.raw >current &&
@@ -1120,6 +1136,22 @@ test_expect_success 'test diff.wsErrorHighlight config' ' ' +test_expect_success 'test diff.wsErrorHighlight config with spaces' ' + + git -c "diff.wsErrorHighlight=default, old" diff --color >current.raw && + test_decode_color <current.raw >current && + test_cmp expect.default-old current && + + git -c "diff.wsErrorHighlight=default , old" diff --color >current.raw && + test_decode_color <current.raw >current && + test_cmp expect.default-old current && + + git -c "diff.wsErrorHighlight= default , old " diff --color >current.raw && + test_decode_color <current.raw >current && + test_cmp expect.default-old current + +' + test_expect_success 'option overrides diff.wsErrorHighlight' ' git -c diff.wsErrorHighlight=none \
PATCH 3/3 t4047: whitespace in diff.dirstat and --dirstat
In reply to Dragan SimicAdd a few more tests to cover the support for optional placing of additional whitespace characters around the commas in the multi-value, comma-separated values for the "diff.dirstat" configuration option and the "--dirstat" command-line option.
--- t/t4047-diff-dirstat.sh | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
t/t4047-diff-dirstat.sh +30 -3
@@ -707,24 +707,42 @@ test_expect_success '--dirstat-by-file --cumulative' ' test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC ' -test_expect_success '--dirstat=files,cumulative' ' +test_expect_success '--dirstat=files,cumulative with no spaces' ' git diff --dirstat=files,cumulative HEAD^..HEAD >actual_diff_dirstat && test_cmp expect_diff_dirstat actual_diff_dirstat && git diff --dirstat=files,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M && test_cmp expect_diff_dirstat_M actual_diff_dirstat_M && git diff --dirstat=files,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC && test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC ' -test_expect_success 'diff.dirstat=cumulative,files' ' +test_expect_success '--dirstat=files,cumulative with spaces' ' + git diff --dirstat="files, cumulative" HEAD^..HEAD >actual_diff_dirstat && + test_cmp expect_diff_dirstat actual_diff_dirstat && + git diff --dirstat="files , cumulative" -M HEAD^..HEAD >actual_diff_dirstat_M && + test_cmp expect_diff_dirstat_M actual_diff_dirstat_M && + git diff --dirstat=" files , cumulative " -C -C HEAD^..HEAD >actual_diff_dirstat_CC && + test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC +' + +test_expect_success 'diff.dirstat=cumulative,files with no spaces' ' git -c diff.dirstat=cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat && test_cmp expect_diff_dirstat actual_diff_dirstat && git -c diff.dirstat=cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M && test_cmp expect_diff_dirstat_M actual_diff_dirstat_M && git -c diff.dirstat=cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC && test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC ' +test_expect_success 'diff.dirstat=cumulative,files with spaces' ' + git -c "diff.dirstat= cumulative,files " diff --dirstat HEAD^..HEAD >actual_diff_dirstat && + test_cmp expect_diff_dirstat actual_diff_dirstat && + git -c "diff.dirstat= cumulative ,files" diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M && + test_cmp expect_diff_dirstat_M actual_diff_dirstat_M && + git -c "diff.dirstat= cumulative , files" diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC && + test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC +' + cat <<EOF >expect_diff_dirstat 27.2% dst/copy/ 27.2% dst/move/
@@ -766,15 +784,24 @@ test_expect_success '--dirstat=files,cumulative,10' ' test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC ' -test_expect_success 'diff.dirstat=10,cumulative,files' ' +test_expect_success 'diff.dirstat=10,cumulative,files with no spaces' ' git -c diff.dirstat=10,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat && test_cmp expect_diff_dirstat actual_diff_dirstat && git -c diff.dirstat=10,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M && test_cmp expect_diff_dirstat_M actual_diff_dirstat_M && git -c diff.dirstat=10,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC && test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC ' +test_expect_success 'diff.dirstat=10,cumulative,files with spaces' ' + git -c "diff.dirstat= 10,cumulative,files " diff --dirstat HEAD^..HEAD >actual_diff_dirstat && + test_cmp expect_diff_dirstat actual_diff_dirstat && + git -c "diff.dirstat=10, cumulative, files" diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M && + test_cmp expect_diff_dirstat_M actual_diff_dirstat_M && + git -c "diff.dirstat=10 , cumulative , files" diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC && + test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC +' + cat <<EOF >expect_diff_dirstat 27.2% dst/copy/ 27.2% dst/move/
Quoted 9 lines · Dragan Simic
This series adds support for optional placing of additional whitespace characters around the commas in the multi-value, comma-separated values for the "diff.dirstat" and "diff.wsErrorHighlight" configuration options, and the "--dirstat" and "--ws-error-highlight" command-line options.
This makes the way multi-(sub)value configuration options can be specified more consistent, because exactly the same additional whitespace characters are already allowed for some of the configuration options. It may also make the configuration files more readable to some users.
Meh, somehow I managed to forget to include the brief summary for the "what's cooking". Here's what might be used for that purpose:
* Allow additional whitespace around the commas in
"diff.dirstat=<multi-value>",
"diff.wsErrorHighlight=<multi-value>", "git diff
--dirstat=<multi-value>"
and "git diff --ws-error-highlight=<multi-value>".
Quoted 19 lines
Dragan Simic (3):
diff: support additional whitespace in
diff.{dirstat,wsErrorHighlight}
t4015: whitespace in diff.wsErrorHighlight and --ws-error-highlight
t4047: whitespace in diff.dirstat and --dirstatbuiltin/gc.c | 4 ++-- diff.c | 14 ++++++++++---- notes.c | 2 +- refs/packed-backend.c | 2 +- string-list.c | 27 +++++++++++++++++++++------ string-list.h | 10 ++++++---- t/helper/test-hashmap.c | 2 +- t/helper/test-json-writer.c | 2 +- t/helper/test-oidmap.c | 2 +- t/helper/test-string-list.c | 4 ++-- t/t4015-diff-whitespace.sh | 36 ++++++++++++++++++++++++++++++++++-- t/t4047-diff-dirstat.sh | 33 ++++++++++++++++++++++++++++++--- 12 files changed, 110 insertions(+), 28 deletions(-)
Hello all,
Quoted 9 lines · Dragan Simic
This series adds support for optional placing of additional whitespace characters around the commas in the multi-value, comma-separated values for the "diff.dirstat" and "diff.wsErrorHighlight" configuration options, and the "--dirstat" and "--ws-error-highlight" command-line options.
This makes the way multi-(sub)value configuration options can be specified more consistent, because exactly the same additional whitespace characters are already allowed for some of the configuration options. It may also make the configuration files more readable to some users.
Just a brief reminder about this patch series.
Quoted 19 lines
Dragan Simic (3):
diff: support additional whitespace in
diff.{dirstat,wsErrorHighlight}
t4015: whitespace in diff.wsErrorHighlight and --ws-error-highlight
t4047: whitespace in diff.dirstat and --dirstatbuiltin/gc.c | 4 ++-- diff.c | 14 ++++++++++---- notes.c | 2 +- refs/packed-backend.c | 2 +- string-list.c | 27 +++++++++++++++++++++------ string-list.h | 10 ++++++---- t/helper/test-hashmap.c | 2 +- t/helper/test-json-writer.c | 2 +- t/helper/test-oidmap.c | 2 +- t/helper/test-string-list.c | 4 ++-- t/t4015-diff-whitespace.sh | 36 ++++++++++++++++++++++++++++++++++-- t/t4047-diff-dirstat.sh | 33 ++++++++++++++++++++++++++++++--- 12 files changed, 110 insertions(+), 28 deletions(-)