@@ -51,6 +51,16 @@ struct config_source {
51
51
};
52
52
#define CONFIG_SOURCE_INIT { 0 }
53
53
54
+ struct config_reader {
55
+ struct config_source * source ;
56
+ };
57
+ /*
58
+ * Where possible, prefer to accept "struct config_reader" as an arg than to use
59
+ * "the_reader". "the_reader" should only be used if that is infeasible, e.g. in
60
+ * a public function.
61
+ */
62
+ static struct config_reader the_reader ;
63
+
54
64
/*
55
65
* These variables record the "current" config source, which
56
66
* can be accessed by parsing callbacks.
@@ -66,6 +76,9 @@ struct config_source {
66
76
* at the variables, it's either a bug for it to be called in the first place,
67
77
* or it's a function which can be reused for non-config purposes, and should
68
78
* fall back to some sane behavior).
79
+ *
80
+ * FIXME "cf_global" has been replaced by "the_reader.source", remove
81
+ * "cf_global" once we plumb "the_reader" through all of the callback functions.
69
82
*/
70
83
static struct config_source * cf_global ;
71
84
static struct key_value_info * current_config_kvi ;
@@ -80,19 +93,24 @@ static struct key_value_info *current_config_kvi;
80
93
*/
81
94
static enum config_scope current_parsing_scope ;
82
95
83
- static inline void config_reader_push_source (struct config_source * top )
96
+ static inline void config_reader_push_source (struct config_reader * reader ,
97
+ struct config_source * top )
84
98
{
85
- top -> prev = cf_global ;
86
- cf_global = top ;
99
+ top -> prev = reader -> source ;
100
+ reader -> source = top ;
101
+ /* FIXME remove this when cf_global is removed. */
102
+ cf_global = reader -> source ;
87
103
}
88
104
89
- static inline struct config_source * config_reader_pop_source ()
105
+ static inline struct config_source * config_reader_pop_source (struct config_reader * reader )
90
106
{
91
107
struct config_source * ret ;
92
- if (!cf_global )
108
+ if (!reader -> source )
93
109
BUG ("tried to pop config source, but we weren't reading config" );
94
- ret = cf_global ;
95
- cf_global = cf_global -> prev ;
110
+ ret = reader -> source ;
111
+ reader -> source = reader -> source -> prev ;
112
+ /* FIXME remove this when cf_global is removed. */
113
+ cf_global = reader -> source ;
96
114
return ret ;
97
115
}
98
116
@@ -732,7 +750,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
732
750
struct config_source source = CONFIG_SOURCE_INIT ;
733
751
734
752
source .origin_type = CONFIG_ORIGIN_CMDLINE ;
735
- config_reader_push_source (& source );
753
+ config_reader_push_source (& the_reader , & source );
736
754
737
755
env = getenv (CONFIG_COUNT_ENVIRONMENT );
738
756
if (env ) {
@@ -790,7 +808,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
790
808
strbuf_release (& envvar );
791
809
strvec_clear (& to_free );
792
810
free (envw );
793
- config_reader_pop_source ();
811
+ config_reader_pop_source (& the_reader );
794
812
return ret ;
795
813
}
796
814
@@ -1325,31 +1343,31 @@ int git_config_int(const char *name, const char *value)
1325
1343
{
1326
1344
int ret ;
1327
1345
if (!git_parse_int (value , & ret ))
1328
- die_bad_number (cf_global , name , value );
1346
+ die_bad_number (the_reader . source , name , value );
1329
1347
return ret ;
1330
1348
}
1331
1349
1332
1350
int64_t git_config_int64 (const char * name , const char * value )
1333
1351
{
1334
1352
int64_t ret ;
1335
1353
if (!git_parse_int64 (value , & ret ))
1336
- die_bad_number (cf_global , name , value );
1354
+ die_bad_number (the_reader . source , name , value );
1337
1355
return ret ;
1338
1356
}
1339
1357
1340
1358
unsigned long git_config_ulong (const char * name , const char * value )
1341
1359
{
1342
1360
unsigned long ret ;
1343
1361
if (!git_parse_ulong (value , & ret ))
1344
- die_bad_number (cf_global , name , value );
1362
+ die_bad_number (the_reader . source , name , value );
1345
1363
return ret ;
1346
1364
}
1347
1365
1348
1366
ssize_t git_config_ssize_t (const char * name , const char * value )
1349
1367
{
1350
1368
ssize_t ret ;
1351
1369
if (!git_parse_ssize_t (value , & ret ))
1352
- die_bad_number (cf_global , name , value );
1370
+ die_bad_number (the_reader . source , name , value );
1353
1371
return ret ;
1354
1372
}
1355
1373
@@ -1955,7 +1973,8 @@ int git_default_config(const char *var, const char *value, void *cb)
1955
1973
* fgetc, ungetc, ftell of top need to be initialized before calling
1956
1974
* this function.
1957
1975
*/
1958
- static int do_config_from (struct config_source * top , config_fn_t fn , void * data ,
1976
+ static int do_config_from (struct config_reader * reader ,
1977
+ struct config_source * top , config_fn_t fn , void * data ,
1959
1978
const struct config_options * opts )
1960
1979
{
1961
1980
int ret ;
@@ -1966,22 +1985,23 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data,
1966
1985
top -> total_len = 0 ;
1967
1986
strbuf_init (& top -> value , 1024 );
1968
1987
strbuf_init (& top -> var , 1024 );
1969
- config_reader_push_source (top );
1988
+ config_reader_push_source (reader , top );
1970
1989
1971
1990
ret = git_parse_source (top , fn , data , opts );
1972
1991
1973
1992
/* pop config-file parsing state stack */
1974
1993
strbuf_release (& top -> value );
1975
1994
strbuf_release (& top -> var );
1976
- config_reader_pop_source ();
1995
+ config_reader_pop_source (reader );
1977
1996
1978
1997
return ret ;
1979
1998
}
1980
1999
1981
- static int do_config_from_file (config_fn_t fn ,
1982
- const enum config_origin_type origin_type ,
1983
- const char * name , const char * path , FILE * f ,
1984
- void * data , const struct config_options * opts )
2000
+ static int do_config_from_file (struct config_reader * reader ,
2001
+ config_fn_t fn ,
2002
+ const enum config_origin_type origin_type ,
2003
+ const char * name , const char * path , FILE * f ,
2004
+ void * data , const struct config_options * opts )
1985
2005
{
1986
2006
struct config_source top = CONFIG_SOURCE_INIT ;
1987
2007
int ret ;
@@ -1996,15 +2016,15 @@ static int do_config_from_file(config_fn_t fn,
1996
2016
top .do_ftell = config_file_ftell ;
1997
2017
1998
2018
flockfile (f );
1999
- ret = do_config_from (& top , fn , data , opts );
2019
+ ret = do_config_from (reader , & top , fn , data , opts );
2000
2020
funlockfile (f );
2001
2021
return ret ;
2002
2022
}
2003
2023
2004
2024
static int git_config_from_stdin (config_fn_t fn , void * data )
2005
2025
{
2006
- return do_config_from_file (fn , CONFIG_ORIGIN_STDIN , "" , NULL , stdin ,
2007
- data , NULL );
2026
+ return do_config_from_file (& the_reader , fn , CONFIG_ORIGIN_STDIN , "" ,
2027
+ NULL , stdin , data , NULL );
2008
2028
}
2009
2029
2010
2030
int git_config_from_file_with_options (config_fn_t fn , const char * filename ,
@@ -2018,8 +2038,8 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
2018
2038
BUG ("filename cannot be NULL" );
2019
2039
f = fopen_or_warn (filename , "r" );
2020
2040
if (f ) {
2021
- ret = do_config_from_file (fn , CONFIG_ORIGIN_FILE , filename ,
2022
- filename , f , data , opts );
2041
+ ret = do_config_from_file (& the_reader , fn , CONFIG_ORIGIN_FILE ,
2042
+ filename , filename , f , data , opts );
2023
2043
fclose (f );
2024
2044
}
2025
2045
return ret ;
@@ -2048,7 +2068,7 @@ int git_config_from_mem(config_fn_t fn,
2048
2068
top .do_ungetc = config_buf_ungetc ;
2049
2069
top .do_ftell = config_buf_ftell ;
2050
2070
2051
- return do_config_from (& top , fn , data , opts );
2071
+ return do_config_from (& the_reader , & top , fn , data , opts );
2052
2072
}
2053
2073
2054
2074
int git_config_from_blob_oid (config_fn_t fn ,
@@ -3797,8 +3817,8 @@ const char *current_config_origin_type(void)
3797
3817
int type ;
3798
3818
if (current_config_kvi )
3799
3819
type = current_config_kvi -> origin_type ;
3800
- else if (cf_global )
3801
- type = cf_global -> origin_type ;
3820
+ else if (the_reader . source )
3821
+ type = the_reader . source -> origin_type ;
3802
3822
else
3803
3823
BUG ("current_config_origin_type called outside config callback" );
3804
3824
@@ -3843,8 +3863,8 @@ const char *current_config_name(void)
3843
3863
const char * name ;
3844
3864
if (current_config_kvi )
3845
3865
name = current_config_kvi -> filename ;
3846
- else if (cf_global )
3847
- name = cf_global -> name ;
3866
+ else if (the_reader . source )
3867
+ name = the_reader . source -> name ;
3848
3868
else
3849
3869
BUG ("current_config_name called outside config callback" );
3850
3870
return name ? name : "" ;
@@ -3863,7 +3883,7 @@ int current_config_line(void)
3863
3883
if (current_config_kvi )
3864
3884
return current_config_kvi -> linenr ;
3865
3885
else
3866
- return cf_global -> linenr ;
3886
+ return the_reader . source -> linenr ;
3867
3887
}
3868
3888
3869
3889
int lookup_config (const char * * mapping , int nr_mapping , const char * var )
0 commit comments