@@ -21,6 +21,7 @@ static char term = '\n';
21
21
22
22
static int use_global_config , use_system_config , use_local_config ;
23
23
static const char * given_config_file ;
24
+ static const char * given_config_blob ;
24
25
static int actions , types ;
25
26
static const char * get_color_slot , * get_colorbool_slot ;
26
27
static int end_null ;
@@ -53,6 +54,7 @@ static struct option builtin_config_options[] = {
53
54
OPT_BOOLEAN (0 , "system" , & use_system_config , N_ ("use system config file" )),
54
55
OPT_BOOLEAN (0 , "local" , & use_local_config , N_ ("use repository config file" )),
55
56
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" )),
56
58
OPT_GROUP (N_ ("Action" )),
57
59
OPT_BIT (0 , "get" , & actions , N_ ("get value: name [value-regex]" ), ACTION_GET ),
58
60
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_)
218
220
}
219
221
220
222
git_config_with_options (collect_config , & values ,
221
- given_config_file , respect_includes );
223
+ given_config_file , given_config_blob ,
224
+ respect_includes );
222
225
223
226
ret = !values .nr ;
224
227
@@ -302,7 +305,8 @@ static void get_color(const char *def_color)
302
305
get_color_found = 0 ;
303
306
parsed_color [0 ] = '\0' ;
304
307
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 );
306
310
307
311
if (!get_color_found && def_color )
308
312
color_parse (def_color , "command line" , parsed_color );
@@ -331,7 +335,8 @@ static int get_colorbool(int print)
331
335
get_diff_color_found = -1 ;
332
336
get_color_ui_found = -1 ;
333
337
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 );
335
340
336
341
if (get_colorbool_found < 0 ) {
337
342
if (!strcmp (get_colorbool_slot , "color.diff" ))
@@ -353,6 +358,12 @@ static int get_colorbool(int print)
353
358
return get_colorbool_found ? 0 : 1 ;
354
359
}
355
360
361
+ static void check_blob_write (void )
362
+ {
363
+ if (given_config_blob )
364
+ die ("writing config blobs is not supported" );
365
+ }
366
+
356
367
int cmd_config (int argc , const char * * argv , const char * prefix )
357
368
{
358
369
int nongit = !startup_info -> have_repository ;
@@ -364,7 +375,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
364
375
builtin_config_usage ,
365
376
PARSE_OPT_STOP_AT_NON_OPTION );
366
377
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 ) {
368
380
error ("only one config file at a time." );
369
381
usage_with_options (builtin_config_usage , builtin_config_options );
370
382
}
@@ -443,6 +455,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
443
455
check_argc (argc , 0 , 0 );
444
456
if (git_config_with_options (show_all_config , NULL ,
445
457
given_config_file ,
458
+ given_config_blob ,
446
459
respect_includes ) < 0 ) {
447
460
if (given_config_file )
448
461
die_errno ("unable to read config file '%s'" ,
@@ -455,13 +468,16 @@ int cmd_config(int argc, const char **argv, const char *prefix)
455
468
check_argc (argc , 0 , 0 );
456
469
if (!given_config_file && nongit )
457
470
die ("not in a git directory" );
471
+ if (given_config_blob )
472
+ die ("editing blobs is not supported" );
458
473
git_config (git_default_config , NULL );
459
474
launch_editor (given_config_file ?
460
475
given_config_file : git_path ("config" ),
461
476
NULL , NULL );
462
477
}
463
478
else if (actions == ACTION_SET ) {
464
479
int ret ;
480
+ check_blob_write ();
465
481
check_argc (argc , 2 , 2 );
466
482
value = normalize_value (argv [0 ], argv [1 ]);
467
483
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)
471
487
return ret ;
472
488
}
473
489
else if (actions == ACTION_SET_ALL ) {
490
+ check_blob_write ();
474
491
check_argc (argc , 2 , 3 );
475
492
value = normalize_value (argv [0 ], argv [1 ]);
476
493
return git_config_set_multivar_in_file (given_config_file ,
477
494
argv [0 ], value , argv [2 ], 0 );
478
495
}
479
496
else if (actions == ACTION_ADD ) {
497
+ check_blob_write ();
480
498
check_argc (argc , 2 , 2 );
481
499
value = normalize_value (argv [0 ], argv [1 ]);
482
500
return git_config_set_multivar_in_file (given_config_file ,
483
501
argv [0 ], value , "^$" , 0 );
484
502
}
485
503
else if (actions == ACTION_REPLACE_ALL ) {
504
+ check_blob_write ();
486
505
check_argc (argc , 2 , 3 );
487
506
value = normalize_value (argv [0 ], argv [1 ]);
488
507
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)
505
524
return get_value (argv [0 ], argv [1 ]);
506
525
}
507
526
else if (actions == ACTION_UNSET ) {
527
+ check_blob_write ();
508
528
check_argc (argc , 1 , 2 );
509
529
if (argc == 2 )
510
530
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)
514
534
argv [0 ], NULL );
515
535
}
516
536
else if (actions == ACTION_UNSET_ALL ) {
537
+ check_blob_write ();
517
538
check_argc (argc , 1 , 2 );
518
539
return git_config_set_multivar_in_file (given_config_file ,
519
540
argv [0 ], NULL , argv [1 ], 1 );
520
541
}
521
542
else if (actions == ACTION_RENAME_SECTION ) {
522
543
int ret ;
544
+ check_blob_write ();
523
545
check_argc (argc , 2 , 2 );
524
546
ret = git_config_rename_section_in_file (given_config_file ,
525
547
argv [0 ], argv [1 ]);
@@ -530,6 +552,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
530
552
}
531
553
else if (actions == ACTION_REMOVE_SECTION ) {
532
554
int ret ;
555
+ check_blob_write ();
533
556
check_argc (argc , 1 , 1 );
534
557
ret = git_config_rename_section_in_file (given_config_file ,
535
558
argv [0 ], NULL );
0 commit comments