@@ -2292,23 +2292,29 @@ void read_very_early_config(config_fn_t cb, void *data)
2292
2292
config_with_options (cb , data , NULL , & opts );
2293
2293
}
2294
2294
2295
- static struct config_set_element * configset_find_element (struct config_set * cs , const char * key )
2295
+ RESULT_MUST_BE_USED
2296
+ static int configset_find_element (struct config_set * cs , const char * key ,
2297
+ struct config_set_element * * dest )
2296
2298
{
2297
2299
struct config_set_element k ;
2298
2300
struct config_set_element * found_entry ;
2299
2301
char * normalized_key ;
2302
+ int ret ;
2303
+
2300
2304
/*
2301
2305
* `key` may come from the user, so normalize it before using it
2302
2306
* for querying entries from the hashmap.
2303
2307
*/
2304
- if (git_config_parse_key (key , & normalized_key , NULL ))
2305
- return NULL ;
2308
+ ret = git_config_parse_key (key , & normalized_key , NULL );
2309
+ if (ret )
2310
+ return ret ;
2306
2311
2307
2312
hashmap_entry_init (& k .ent , strhash (normalized_key ));
2308
2313
k .key = normalized_key ;
2309
2314
found_entry = hashmap_get_entry (& cs -> config_hash , & k , ent , NULL );
2310
2315
free (normalized_key );
2311
- return found_entry ;
2316
+ * dest = found_entry ;
2317
+ return 0 ;
2312
2318
}
2313
2319
2314
2320
static int configset_add_value (struct config_set * cs , const char * key , const char * value )
@@ -2317,8 +2323,11 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
2317
2323
struct string_list_item * si ;
2318
2324
struct configset_list_item * l_item ;
2319
2325
struct key_value_info * kv_info = xmalloc (sizeof (* kv_info ));
2326
+ int ret ;
2320
2327
2321
- e = configset_find_element (cs , key );
2328
+ ret = configset_find_element (cs , key , & e );
2329
+ if (ret )
2330
+ return ret ;
2322
2331
/*
2323
2332
* Since the keys are being fed by git_config*() callback mechanism, they
2324
2333
* are already normalized. So simply add them without any further munging.
@@ -2412,24 +2421,65 @@ int git_configset_add_file(struct config_set *cs, const char *filename)
2412
2421
int git_configset_get_value (struct config_set * cs , const char * key , const char * * value )
2413
2422
{
2414
2423
const struct string_list * values = NULL ;
2424
+ int ret ;
2425
+
2415
2426
/*
2416
2427
* Follows "last one wins" semantic, i.e., if there are multiple matches for the
2417
2428
* queried key in the files of the configset, the value returned will be the last
2418
2429
* value in the value list for that key.
2419
2430
*/
2420
- values = git_configset_get_value_multi (cs , key );
2431
+ if ((ret = git_configset_get_value_multi (cs , key , & values )))
2432
+ return ret ;
2421
2433
2422
- if (!values )
2423
- return 1 ;
2424
2434
assert (values -> nr > 0 );
2425
2435
* value = values -> items [values -> nr - 1 ].string ;
2426
2436
return 0 ;
2427
2437
}
2428
2438
2429
- const struct string_list * git_configset_get_value_multi (struct config_set * cs , const char * key )
2439
+ int git_configset_get_value_multi (struct config_set * cs , const char * key ,
2440
+ const struct string_list * * dest )
2441
+ {
2442
+ struct config_set_element * e ;
2443
+ int ret ;
2444
+
2445
+ if ((ret = configset_find_element (cs , key , & e )))
2446
+ return ret ;
2447
+ else if (!e )
2448
+ return 1 ;
2449
+ * dest = & e -> value_list ;
2450
+
2451
+ return 0 ;
2452
+ }
2453
+
2454
+ static int check_multi_string (struct string_list_item * item , void * util )
2455
+ {
2456
+ return item -> string ? 0 : config_error_nonbool (util );
2457
+ }
2458
+
2459
+ int git_configset_get_string_multi (struct config_set * cs , const char * key ,
2460
+ const struct string_list * * dest )
2461
+ {
2462
+ int ret ;
2463
+
2464
+ if ((ret = git_configset_get_value_multi (cs , key , dest )))
2465
+ return ret ;
2466
+ if ((ret = for_each_string_list ((struct string_list * )* dest ,
2467
+ check_multi_string , (void * )key )))
2468
+ return ret ;
2469
+
2470
+ return 0 ;
2471
+ }
2472
+
2473
+ int git_configset_get (struct config_set * cs , const char * key )
2430
2474
{
2431
- struct config_set_element * e = configset_find_element (cs , key );
2432
- return e ? & e -> value_list : NULL ;
2475
+ struct config_set_element * e ;
2476
+ int ret ;
2477
+
2478
+ if ((ret = configset_find_element (cs , key , & e )))
2479
+ return ret ;
2480
+ else if (!e )
2481
+ return 1 ;
2482
+ return 0 ;
2433
2483
}
2434
2484
2435
2485
int git_configset_get_string (struct config_set * cs , const char * key , char * * dest )
@@ -2568,18 +2618,31 @@ void repo_config(struct repository *repo, config_fn_t fn, void *data)
2568
2618
configset_iter (repo -> config , fn , data );
2569
2619
}
2570
2620
2621
+ int repo_config_get (struct repository * repo , const char * key )
2622
+ {
2623
+ git_config_check_init (repo );
2624
+ return git_configset_get (repo -> config , key );
2625
+ }
2626
+
2571
2627
int repo_config_get_value (struct repository * repo ,
2572
2628
const char * key , const char * * value )
2573
2629
{
2574
2630
git_config_check_init (repo );
2575
2631
return git_configset_get_value (repo -> config , key , value );
2576
2632
}
2577
2633
2578
- const struct string_list * repo_config_get_value_multi (struct repository * repo ,
2579
- const char * key )
2634
+ int repo_config_get_value_multi (struct repository * repo , const char * key ,
2635
+ const struct string_list * * dest )
2636
+ {
2637
+ git_config_check_init (repo );
2638
+ return git_configset_get_value_multi (repo -> config , key , dest );
2639
+ }
2640
+
2641
+ int repo_config_get_string_multi (struct repository * repo , const char * key ,
2642
+ const struct string_list * * dest )
2580
2643
{
2581
2644
git_config_check_init (repo );
2582
- return git_configset_get_value_multi (repo -> config , key );
2645
+ return git_configset_get_string_multi (repo -> config , key , dest );
2583
2646
}
2584
2647
2585
2648
int repo_config_get_string (struct repository * repo ,
@@ -2682,14 +2745,25 @@ void git_config_clear(void)
2682
2745
repo_config_clear (the_repository );
2683
2746
}
2684
2747
2748
+ int git_config_get (const char * key )
2749
+ {
2750
+ return repo_config_get (the_repository , key );
2751
+ }
2752
+
2685
2753
int git_config_get_value (const char * key , const char * * value )
2686
2754
{
2687
2755
return repo_config_get_value (the_repository , key , value );
2688
2756
}
2689
2757
2690
- const struct string_list * git_config_get_value_multi (const char * key )
2758
+ int git_config_get_value_multi (const char * key , const struct string_list * * dest )
2759
+ {
2760
+ return repo_config_get_value_multi (the_repository , key , dest );
2761
+ }
2762
+
2763
+ int git_config_get_string_multi (const char * key ,
2764
+ const struct string_list * * dest )
2691
2765
{
2692
- return repo_config_get_value_multi (the_repository , key );
2766
+ return repo_config_get_string_multi (the_repository , key , dest );
2693
2767
}
2694
2768
2695
2769
int git_config_get_string (const char * key , char * * dest )
@@ -2836,7 +2910,8 @@ void git_die_config(const char *key, const char *err, ...)
2836
2910
error_fn (err , params );
2837
2911
va_end (params );
2838
2912
}
2839
- values = git_config_get_value_multi (key );
2913
+ if (git_config_get_value_multi (key , & values ))
2914
+ BUG ("for key '%s' we must have a value to report on" , key );
2840
2915
kv_info = values -> items [values -> nr - 1 ].util ;
2841
2916
git_die_config_linenr (key , kv_info -> filename , kv_info -> linenr );
2842
2917
}
0 commit comments