config: support mixed-case aliases
PATCH 1/1 config: support mixed-case aliases
To support mixed-case aliases like:
bM = branch -M
bD = branch -D
add an argument to git_config_with_options() to block the tolower() calls on key characters.
Signed-off-by Ramkumar Ramachandra <[email protected]>
---
The static variable is somewhat disturbing, but it's the most obvious choice to avoid refactoring config.c heavily. What do you think?
alias.c | 2 +- builtin/config.c | 8 ++++---- cache.h | 2 +- config.c | 13 ++++++++++--- t/t1300-repo-config.sh | 7 +++++++ 5 files changed, 23 insertions(+), 9 deletions(-)
alias.c +1 -1
@@ -18,7 +18,7 @@ char *alias_lookup(const char *alias) { alias_key = alias; alias_val =NULL ; -git_config (alias_lookup_cb,NULL ); +git_config_with_options (alias_lookup_cb,NULL ,NULL ,1 ,1 );return alias_val; }
builtin/config.c +4 -4
@@ -218,7 +218,7 @@ static int get_value(const char *key_, const char *regex_) }git_config_with_options (collect_config, &values, - given_config_file, respect_includes); + given_config_file, respect_includes,0 ); ret = !values.nr;
@@ -302,7 +302,7 @@ static void get_color(const char *def_color) get_color_found =0 ; parsed_color[0 ] ='\0' ;git_config_with_options (git_get_color_config,NULL , - given_config_file, respect_includes); + given_config_file, respect_includes,0 );if (!get_color_found && def_color)color_parse (def_color,"command line" , parsed_color);
@@ -330,7 +330,7 @@ static int get_colorbool(int print) get_colorbool_found =-1 ; get_diff_color_found =-1 ;git_config_with_options (git_get_colorbool_config,NULL , - given_config_file, respect_includes); + given_config_file, respect_includes,0 );if (get_colorbool_found <0 ) {if (!strcmp (get_colorbool_slot,"color.diff" ))
@@ -438,7 +438,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)check_argc (argc,0 ,0 );if (git_config_with_options (show_all_config,NULL , given_config_file, - respect_includes) <0 ) { + respect_includes,0 ) <0 ) {if (given_config_file)die_errno ("unable to read config file '%s'" , given_config_file);
cache.h +1 -1
@@ -1161,7 +1161,7 @@ extern void git_config_push_parameter(const char *text);extern int git_config_from_parameters (config_fn_t fn,void *data);extern int git_config (config_fn_t fn,void *);extern int git_config_with_options (config_fn_t fn,void *, -const char *filename,int respect_includes); +const char *filename,int respect_includes,int respect_mixedcase);extern int git_config_early (config_fn_t fn,void *,const char *repo_config);extern int git_parse_ulong (const char *,unsigned long *);extern int git_config_int (const char *,const char *);
config.c +10 -3
@@ -23,6 +23,7 @@ typedef struct config_file {static config_file *cf;static int zlib_compression_seen; +static int allow_mixedcase_keys;#define MAX_INCLUDE_DEPTH 10 static const char include_depth_advice[] =
@@ -270,7 +271,9 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)break ;if (!iskeychar (c))break ; -strbuf_addch (name,tolower (c)); +if (!allow_mixedcase_keys) + c =tolower (c); +strbuf_addch (name, c); }while (c ==' ' || c =='\t' )
@@ -1005,7 +1008,8 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) }int git_config_with_options (config_fn_t fn,void *data, -const char *filename,int respect_includes) +const char *filename,int respect_includes, +int respect_mixedcase) {char *repo_config =NULL ;int ret;
@@ -1018,6 +1022,9 @@ int git_config_with_options(config_fn_t fn, void *data, data = &inc; } +/* For mixed-case aliases */ + allow_mixedcase_keys = respect_mixedcase ?1 :0 ; +/* * If we have a specific filename, use it. Otherwise, follow the * regular lookup sequence.
@@ -1034,7 +1041,7 @@ int git_config_with_options(config_fn_t fn, void *data,int git_config (config_fn_t fn,void *data) { -return git_config_with_options (fn, data,NULL ,1 ); +return git_config_with_options (fn, data,NULL ,1 ,0 ); }/*
t/t1300-repo-config.sh +7 -0
@@ -1021,6 +1021,13 @@ test_expect_success 'git -c works with aliases of builtins' ' test_cmp expect actual ' +test_expect_success 'git -c works with mixed-case aliases of builtins' ' + git config alias.checkConfig "-c foo.check=bar config foo.check" && + echo bar >expect && + git checkConfig >actual && + test_cmp expect actual +' + test_expect_success 'git -c does not split values on equals' ' echo "value with = in it" >expect && git -c core.foo="value with = in it" config core.foo >actual &&
Signature · 1 line
1.8.3.1.436.gbdff0e3.dirty