@@ -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 );
@@ -331,7 +335,8 @@ static int get_colorbool(int print)
331335 get_diff_color_found = -1 ;
332336 get_color_ui_found = -1 ;
333337 git_config_with_options (git_get_colorbool_config , NULL ,
334- given_config_file , respect_includes );
338+ given_config_file , given_config_blob ,
339+ respect_includes );
335340
336341 if (get_colorbool_found < 0 ) {
337342 if (!strcmp (get_colorbool_slot , "color.diff" ))
@@ -353,6 +358,12 @@ static int get_colorbool(int print)
353358 return get_colorbool_found ? 0 : 1 ;
354359}
355360
361+ static void check_blob_write (void )
362+ {
363+ if (given_config_blob )
364+ die ("writing config blobs is not supported" );
365+ }
366+
356367int cmd_config (int argc , const char * * argv , const char * prefix )
357368{
358369 int nongit = !startup_info -> have_repository ;
@@ -364,7 +375,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
364375 builtin_config_usage ,
365376 PARSE_OPT_STOP_AT_NON_OPTION );
366377
367- if (use_global_config + use_system_config + use_local_config + !!given_config_file > 1 ) {
378+ if (use_global_config + use_system_config + use_local_config +
379+ !!given_config_file + !!given_config_blob > 1 ) {
368380 error ("only one config file at a time." );
369381 usage_with_options (builtin_config_usage , builtin_config_options );
370382 }
@@ -443,6 +455,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
443455 check_argc (argc , 0 , 0 );
444456 if (git_config_with_options (show_all_config , NULL ,
445457 given_config_file ,
458+ given_config_blob ,
446459 respect_includes ) < 0 ) {
447460 if (given_config_file )
448461 die_errno ("unable to read config file '%s'" ,
@@ -455,13 +468,16 @@ int cmd_config(int argc, const char **argv, const char *prefix)
455468 check_argc (argc , 0 , 0 );
456469 if (!given_config_file && nongit )
457470 die ("not in a git directory" );
471+ if (given_config_blob )
472+ die ("editing blobs is not supported" );
458473 git_config (git_default_config , NULL );
459474 launch_editor (given_config_file ?
460475 given_config_file : git_path ("config" ),
461476 NULL , NULL );
462477 }
463478 else if (actions == ACTION_SET ) {
464479 int ret ;
480+ check_blob_write ();
465481 check_argc (argc , 2 , 2 );
466482 value = normalize_value (argv [0 ], argv [1 ]);
467483 ret = git_config_set_in_file (given_config_file , argv [0 ], value );
@@ -471,18 +487,21 @@ int cmd_config(int argc, const char **argv, const char *prefix)
471487 return ret ;
472488 }
473489 else if (actions == ACTION_SET_ALL ) {
490+ check_blob_write ();
474491 check_argc (argc , 2 , 3 );
475492 value = normalize_value (argv [0 ], argv [1 ]);
476493 return git_config_set_multivar_in_file (given_config_file ,
477494 argv [0 ], value , argv [2 ], 0 );
478495 }
479496 else if (actions == ACTION_ADD ) {
497+ check_blob_write ();
480498 check_argc (argc , 2 , 2 );
481499 value = normalize_value (argv [0 ], argv [1 ]);
482500 return git_config_set_multivar_in_file (given_config_file ,
483501 argv [0 ], value , "^$" , 0 );
484502 }
485503 else if (actions == ACTION_REPLACE_ALL ) {
504+ check_blob_write ();
486505 check_argc (argc , 2 , 3 );
487506 value = normalize_value (argv [0 ], argv [1 ]);
488507 return git_config_set_multivar_in_file (given_config_file ,
@@ -505,6 +524,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
505524 return get_value (argv [0 ], argv [1 ]);
506525 }
507526 else if (actions == ACTION_UNSET ) {
527+ check_blob_write ();
508528 check_argc (argc , 1 , 2 );
509529 if (argc == 2 )
510530 return git_config_set_multivar_in_file (given_config_file ,
@@ -514,12 +534,14 @@ int cmd_config(int argc, const char **argv, const char *prefix)
514534 argv [0 ], NULL );
515535 }
516536 else if (actions == ACTION_UNSET_ALL ) {
537+ check_blob_write ();
517538 check_argc (argc , 1 , 2 );
518539 return git_config_set_multivar_in_file (given_config_file ,
519540 argv [0 ], NULL , argv [1 ], 1 );
520541 }
521542 else if (actions == ACTION_RENAME_SECTION ) {
522543 int ret ;
544+ check_blob_write ();
523545 check_argc (argc , 2 , 2 );
524546 ret = git_config_rename_section_in_file (given_config_file ,
525547 argv [0 ], argv [1 ]);
@@ -530,6 +552,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
530552 }
531553 else if (actions == ACTION_REMOVE_SECTION ) {
532554 int ret ;
555+ check_blob_write ();
533556 check_argc (argc , 1 , 1 );
534557 ret = git_config_rename_section_in_file (given_config_file ,
535558 argv [0 ], NULL );
0 commit comments