From cbc0f81d96f05d8c88dd29a69d7571baa204f933 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 10 Jul 2017 03:03:42 -0400 Subject: [PATCH 1/2] strbuf: use designated initializers in STRBUF_INIT There are certain C99 features that might be nice to use in our code base, but we've hesitated to do so in order to avoid breaking compatibility with older compilers. But we don't actually know if people are even using pre-C99 compilers these days. One way to figure that out is to introduce a very small use of a feature, and see if anybody complains. The strbuf code is a good place to do this for a few reasons: - it always gets compiled, no matter which Makefile knobs have been tweaked. - it's very stable; this definition hasn't changed in a long time and is not likely to (so if we have to revert, it's unlikely to cause headaches) If this patch can survive a few releases without complaint, then we can feel more confident that designated initializers are widely supported by our user base. It also is an indication that other C99 features may be supported, but not a guarantee (e.g., gcc had designated initializers before C99 existed). And if we do get complaints, then we'll have gained some data and we can easily revert this patch. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- strbuf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strbuf.h b/strbuf.h index 2075384e0b..e705b94db5 100644 --- a/strbuf.h +++ b/strbuf.h @@ -68,7 +68,7 @@ struct strbuf { }; extern char strbuf_slopbuf[]; -#define STRBUF_INIT { 0, 0, strbuf_slopbuf } +#define STRBUF_INIT { .alloc = 0, .len = 0, .buf = strbuf_slopbuf } /** * Life Cycle Functions From 512f41cfac55c9dd2f6c47531ee6cbe803ed7ec2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Jul 2017 08:38:09 -0700 Subject: [PATCH 2/2] clean.c: use designated initializer This is another test balloon to see if we get complaints from people whose compilers do not support designated initializer for arrays. The use of the feature is not all that interesting for cases like the one this patch touches, where the initialized elements of the array is dense, but it would be nice if we can use the feature to initialize an array that has elements initialized to interesting values only sparsely. Signed-off-by: Junio C Hamano --- builtin/clean.c | 19 ++++++++++--------- t/t7301-clean-interactive.sh | 10 ++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/builtin/clean.c b/builtin/clean.c index 057fc97fe4..e2bb3c69ed 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -33,15 +33,6 @@ static const char *msg_skip_git_dir = N_("Skipping repository %s\n"); static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n"); static const char *msg_warn_remove_failed = N_("failed to remove %s"); -static int clean_use_color = -1; -static char clean_colors[][COLOR_MAXLEN] = { - GIT_COLOR_RESET, - GIT_COLOR_NORMAL, /* PLAIN */ - GIT_COLOR_BOLD_BLUE, /* PROMPT */ - GIT_COLOR_BOLD, /* HEADER */ - GIT_COLOR_BOLD_RED, /* HELP */ - GIT_COLOR_BOLD_RED, /* ERROR */ -}; enum color_clean { CLEAN_COLOR_RESET = 0, CLEAN_COLOR_PLAIN = 1, @@ -51,6 +42,16 @@ enum color_clean { CLEAN_COLOR_ERROR = 5 }; +static int clean_use_color = -1; +static char clean_colors[][COLOR_MAXLEN] = { + [CLEAN_COLOR_ERROR] = GIT_COLOR_BOLD_RED, + [CLEAN_COLOR_HEADER] = GIT_COLOR_BOLD, + [CLEAN_COLOR_HELP] = GIT_COLOR_BOLD_RED, + [CLEAN_COLOR_PLAIN] = GIT_COLOR_NORMAL, + [CLEAN_COLOR_PROMPT] = GIT_COLOR_BOLD_BLUE, + [CLEAN_COLOR_RESET] = GIT_COLOR_RESET, +}; + #define MENU_OPTS_SINGLETON 01 #define MENU_OPTS_IMMEDIATE 02 #define MENU_OPTS_LIST_ONLY 04 diff --git a/t/t7301-clean-interactive.sh b/t/t7301-clean-interactive.sh index 3ae394e934..556e1850e2 100755 --- a/t/t7301-clean-interactive.sh +++ b/t/t7301-clean-interactive.sh @@ -472,4 +472,14 @@ test_expect_success 'git clean -id with prefix and path (ask)' ' ' +test_expect_success 'git clean -i paints the header in HEADER color' ' + >a.out && + echo q | + git -c color.ui=always clean -i | + test_decode_color | + head -n 1 >header && + # not i18ngrep + grep "^" header +' + test_done