@@ -123,9 +123,6 @@ struct config_display_options {
123
123
.key_delim = ' ', \
124
124
}
125
125
126
- static int use_key_regexp ;
127
- static int do_all ;
128
-
129
126
#define TYPE_BOOL 1
130
127
#define TYPE_INT 2
131
128
#define TYPE_BOOL_OR_INT 3
@@ -319,6 +316,9 @@ static int format_config(const struct config_display_options *opts,
319
316
return 0 ;
320
317
}
321
318
319
+ #define GET_VALUE_ALL (1 << 0)
320
+ #define GET_VALUE_KEY_REGEXP (1 << 1)
321
+
322
322
struct collect_config_data {
323
323
const struct config_display_options * display_opts ;
324
324
struct strbuf_list * values ;
@@ -327,6 +327,7 @@ struct collect_config_data {
327
327
regex_t * regexp ;
328
328
regex_t * key_regexp ;
329
329
int do_not_match ;
330
+ unsigned get_value_flags ;
330
331
unsigned flags ;
331
332
};
332
333
@@ -337,9 +338,11 @@ static int collect_config(const char *key_, const char *value_,
337
338
struct strbuf_list * values = data -> values ;
338
339
const struct key_value_info * kvi = ctx -> kvi ;
339
340
340
- if (!use_key_regexp && strcmp (key_ , data -> key ))
341
+ if (!(data -> get_value_flags & GET_VALUE_KEY_REGEXP ) &&
342
+ strcmp (key_ , data -> key ))
341
343
return 0 ;
342
- if (use_key_regexp && regexec (data -> key_regexp , key_ , 0 , NULL , 0 ))
344
+ if ((data -> get_value_flags & GET_VALUE_KEY_REGEXP ) &&
345
+ regexec (data -> key_regexp , key_ , 0 , NULL , 0 ))
343
346
return 0 ;
344
347
if ((data -> flags & CONFIG_FLAGS_FIXED_VALUE ) &&
345
348
strcmp (data -> value_pattern , (value_ ?value_ :"" )))
@@ -357,19 +360,21 @@ static int collect_config(const char *key_, const char *value_,
357
360
358
361
static int get_value (const struct config_location_options * opts ,
359
362
const struct config_display_options * display_opts ,
360
- const char * key_ , const char * regex_ , unsigned flags )
363
+ const char * key_ , const char * regex_ ,
364
+ unsigned get_value_flags , unsigned flags )
361
365
{
362
366
int ret = CONFIG_GENERIC_ERROR ;
363
367
struct strbuf_list values = {NULL };
364
368
struct collect_config_data data = {
365
369
.display_opts = display_opts ,
366
370
.values = & values ,
371
+ .get_value_flags = get_value_flags ,
367
372
.flags = flags ,
368
373
};
369
374
char * key = NULL ;
370
375
int i ;
371
376
372
- if (use_key_regexp ) {
377
+ if (get_value_flags & GET_VALUE_KEY_REGEXP ) {
373
378
char * tl ;
374
379
375
380
/*
@@ -441,7 +446,7 @@ static int get_value(const struct config_location_options *opts,
441
446
442
447
for (i = 0 ; i < values .nr ; i ++ ) {
443
448
struct strbuf * buf = values .items + i ;
444
- if (do_all || i == values .nr - 1 )
449
+ if (( get_value_flags & GET_VALUE_ALL ) || i == values .nr - 1 )
445
450
fwrite (buf -> buf , 1 , buf -> len , stdout );
446
451
strbuf_release (buf );
447
452
}
@@ -848,11 +853,12 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
848
853
struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT ;
849
854
const char * value_pattern = NULL , * url = NULL ;
850
855
int flags = 0 ;
856
+ unsigned get_value_flags = 0 ;
851
857
struct option opts [] = {
852
858
CONFIG_LOCATION_OPTIONS (location_opts ),
853
859
OPT_GROUP (N_ ("Filter options" )),
854
- OPT_BOOL (0 , "all" , & do_all , N_ ("return all values for multi-valued config options" )),
855
- OPT_BOOL (0 , "regexp" , & use_key_regexp , N_ ("interpret the name as a regular expression" )),
860
+ OPT_BIT (0 , "all" , & get_value_flags , N_ ("return all values for multi-valued config options" ), GET_VALUE_ALL ),
861
+ OPT_BIT (0 , "regexp" , & get_value_flags , N_ ("interpret the name as a regular expression" ), GET_VALUE_KEY_REGEXP ),
856
862
OPT_STRING (0 , "value" , & value_pattern , N_ ("pattern" ), N_ ("show config with values matching the pattern" )),
857
863
OPT_BIT (0 , "fixed-value" , & flags , N_ ("use string equality when comparing values to value pattern" ), CONFIG_FLAGS_FIXED_VALUE ),
858
864
OPT_STRING (0 , "url" , & url , N_ ("URL" ), N_ ("show config matching the given URL" )),
@@ -872,9 +878,12 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
872
878
873
879
if ((flags & CONFIG_FLAGS_FIXED_VALUE ) && !value_pattern )
874
880
die (_ ("--fixed-value only applies with 'value-pattern'" ));
875
- if (display_opts .default_value && (do_all || url ))
881
+ if (display_opts .default_value &&
882
+ ((get_value_flags & GET_VALUE_ALL ) || url ))
876
883
die (_ ("--default= cannot be used with --all or --url=" ));
877
- if (url && (do_all || use_key_regexp || value_pattern ))
884
+ if (url && ((get_value_flags & GET_VALUE_ALL ) ||
885
+ (get_value_flags & GET_VALUE_KEY_REGEXP ) ||
886
+ value_pattern ))
878
887
die (_ ("--url= cannot be used with --all, --regexp or --value" ));
879
888
880
889
location_options_init (& location_opts , prefix );
@@ -885,7 +894,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
885
894
if (url )
886
895
ret = get_urlmatch (& location_opts , & display_opts , argv [0 ], url );
887
896
else
888
- ret = get_value (& location_opts , & display_opts , argv [0 ], value_pattern , flags );
897
+ ret = get_value (& location_opts , & display_opts , argv [0 ], value_pattern ,
898
+ get_value_flags , flags );
889
899
890
900
location_options_release (& location_opts );
891
901
return ret ;
@@ -1290,19 +1300,19 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
1290
1300
}
1291
1301
else if (actions == ACTION_GET ) {
1292
1302
check_argc (argc , 1 , 2 );
1293
- ret = get_value (& location_opts , & display_opts , argv [0 ], argv [1 ], flags );
1303
+ ret = get_value (& location_opts , & display_opts , argv [0 ], argv [1 ],
1304
+ 0 , flags );
1294
1305
}
1295
1306
else if (actions == ACTION_GET_ALL ) {
1296
- do_all = 1 ;
1297
1307
check_argc (argc , 1 , 2 );
1298
- ret = get_value (& location_opts , & display_opts , argv [0 ], argv [1 ], flags );
1308
+ ret = get_value (& location_opts , & display_opts , argv [0 ], argv [1 ],
1309
+ GET_VALUE_ALL , flags );
1299
1310
}
1300
1311
else if (actions == ACTION_GET_REGEXP ) {
1301
1312
display_opts .show_keys = 1 ;
1302
- use_key_regexp = 1 ;
1303
- do_all = 1 ;
1304
1313
check_argc (argc , 1 , 2 );
1305
- ret = get_value (& location_opts , & display_opts , argv [0 ], argv [1 ], flags );
1314
+ ret = get_value (& location_opts , & display_opts , argv [0 ], argv [1 ],
1315
+ GET_VALUE_ALL |GET_VALUE_KEY_REGEXP , flags );
1306
1316
}
1307
1317
else if (actions == ACTION_GET_URLMATCH ) {
1308
1318
check_argc (argc , 2 , 2 );
0 commit comments