@@ -21,6 +21,7 @@ static char term = '\n';
2121
2222static int use_global_config , use_system_config , use_local_config ;
2323static const char * given_config_file ;
24+ static const char * given_config_blob ;
2425static int actions , types ;
2526static const char * get_color_slot , * get_colorbool_slot ;
2627static int end_null ;
@@ -53,6 +54,7 @@ static struct option builtin_config_options[] = {
5354 OPT_BOOLEAN (0 , "system" , & use_system_config , N_ ("use system config file" )),
5455 OPT_BOOLEAN (0 , "local" , & use_local_config , N_ ("use repository config file" )),
5556 OPT_STRING ('f' , "file" , & given_config_file , N_ ("file" ), N_ ("use given config file" )),
57+ OPT_STRING (0 , "blob" , & given_config_blob , N_ ("blob-id" ), N_ ("read config from given blob object" )),
5658 OPT_GROUP (N_ ("Action" )),
5759 OPT_BIT (0 , "get" , & actions , N_ ("get value: name [value-regex]" ), ACTION_GET ),
5860 OPT_BIT (0 , "get-all" , & actions , N_ ("get all values: key [value-regex]" ), ACTION_GET_ALL ),
@@ -218,7 +220,8 @@ static int get_value(const char *key_, const char *regex_)
218220 }
219221
220222 git_config_with_options (collect_config , & values ,
221- given_config_file , respect_includes );
223+ given_config_file , given_config_blob ,
224+ respect_includes );
222225
223226 ret = !values .nr ;
224227
@@ -302,7 +305,8 @@ static void get_color(const char *def_color)
302305 get_color_found = 0 ;
303306 parsed_color [0 ] = '\0' ;
304307 git_config_with_options (git_get_color_config , NULL ,
305- given_config_file , respect_includes );
308+ given_config_file , given_config_blob ,
309+ respect_includes );
306310
307311 if (!get_color_found && def_color )
308312 color_parse (def_color , "command line" , parsed_color );
@@ -330,7 +334,8 @@ static int get_colorbool(int print)
330334 get_colorbool_found = -1 ;
331335 get_diff_color_found = -1 ;
332336 git_config_with_options (git_get_colorbool_config , NULL ,
333- given_config_file , respect_includes );
337+ given_config_file , given_config_blob ,
338+ respect_includes );
334339
335340 if (get_colorbool_found < 0 ) {
336341 if (!strcmp (get_colorbool_slot , "color.diff" ))
@@ -348,6 +353,12 @@ static int get_colorbool(int print)
348353 return get_colorbool_found ? 0 : 1 ;
349354}
350355
356+ static void check_blob_write (void )
357+ {
358+ if (given_config_blob )
359+ die ("writing config blobs is not supported" );
360+ }
361+
351362int cmd_config (int argc , const char * * argv , const char * prefix )
352363{
353364 int nongit = !startup_info -> have_repository ;
@@ -359,7 +370,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
359370 builtin_config_usage ,
360371 PARSE_OPT_STOP_AT_NON_OPTION );
361372
362- if (use_global_config + use_system_config + use_local_config + !!given_config_file > 1 ) {
373+ if (use_global_config + use_system_config + use_local_config +
374+ !!given_config_file + !!given_config_blob > 1 ) {
363375 error ("only one config file at a time." );
364376 usage_with_options (builtin_config_usage , builtin_config_options );
365377 }
@@ -438,6 +450,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
438450 check_argc (argc , 0 , 0 );
439451 if (git_config_with_options (show_all_config , NULL ,
440452 given_config_file ,
453+ given_config_blob ,
441454 respect_includes ) < 0 ) {
442455 if (given_config_file )
443456 die_errno ("unable to read config file '%s'" ,
@@ -450,13 +463,16 @@ int cmd_config(int argc, const char **argv, const char *prefix)
450463 check_argc (argc , 0 , 0 );
451464 if (!given_config_file && nongit )
452465 die ("not in a git directory" );
466+ if (given_config_blob )
467+ die ("editing blobs is not supported" );
453468 git_config (git_default_config , NULL );
454469 launch_editor (given_config_file ?
455470 given_config_file : git_path ("config" ),
456471 NULL , NULL );
457472 }
458473 else if (actions == ACTION_SET ) {
459474 int ret ;
475+ check_blob_write ();
460476 check_argc (argc , 2 , 2 );
461477 value = normalize_value (argv [0 ], argv [1 ]);
462478 ret = git_config_set_in_file (given_config_file , argv [0 ], value );
@@ -466,18 +482,21 @@ int cmd_config(int argc, const char **argv, const char *prefix)
466482 return ret ;
467483 }
468484 else if (actions == ACTION_SET_ALL ) {
485+ check_blob_write ();
469486 check_argc (argc , 2 , 3 );
470487 value = normalize_value (argv [0 ], argv [1 ]);
471488 return git_config_set_multivar_in_file (given_config_file ,
472489 argv [0 ], value , argv [2 ], 0 );
473490 }
474491 else if (actions == ACTION_ADD ) {
492+ check_blob_write ();
475493 check_argc (argc , 2 , 2 );
476494 value = normalize_value (argv [0 ], argv [1 ]);
477495 return git_config_set_multivar_in_file (given_config_file ,
478496 argv [0 ], value , "^$" , 0 );
479497 }
480498 else if (actions == ACTION_REPLACE_ALL ) {
499+ check_blob_write ();
481500 check_argc (argc , 2 , 3 );
482501 value = normalize_value (argv [0 ], argv [1 ]);
483502 return git_config_set_multivar_in_file (given_config_file ,
@@ -500,6 +519,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
500519 return get_value (argv [0 ], argv [1 ]);
501520 }
502521 else if (actions == ACTION_UNSET ) {
522+ check_blob_write ();
503523 check_argc (argc , 1 , 2 );
504524 if (argc == 2 )
505525 return git_config_set_multivar_in_file (given_config_file ,
@@ -509,12 +529,14 @@ int cmd_config(int argc, const char **argv, const char *prefix)
509529 argv [0 ], NULL );
510530 }
511531 else if (actions == ACTION_UNSET_ALL ) {
532+ check_blob_write ();
512533 check_argc (argc , 1 , 2 );
513534 return git_config_set_multivar_in_file (given_config_file ,
514535 argv [0 ], NULL , argv [1 ], 1 );
515536 }
516537 else if (actions == ACTION_RENAME_SECTION ) {
517538 int ret ;
539+ check_blob_write ();
518540 check_argc (argc , 2 , 2 );
519541 ret = git_config_rename_section_in_file (given_config_file ,
520542 argv [0 ], argv [1 ]);
@@ -525,6 +547,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
525547 }
526548 else if (actions == ACTION_REMOVE_SECTION ) {
527549 int ret ;
550+ check_blob_write ();
528551 check_argc (argc , 1 , 1 );
529552 ret = git_config_rename_section_in_file (given_config_file ,
530553 argv [0 ], NULL );
0 commit comments