7 static FILE *config_file
;
8 static int config_linenr
;
9 static int get_next_char(void)
15 if ((f
= config_file
) != NULL
) {
27 static char *parse_value(void)
29 static char value
[1024];
30 int quote
= 0, comment
= 0, len
= 0, space
= 0;
33 int c
= get_next_char();
34 if (len
>= sizeof(value
))
44 if (isspace(c
) && !quote
) {
77 if (c
== ';' || c
== '#') {
86 static int get_value(config_fn_t fn
, char *name
, unsigned int len
)
91 /* Get the full name */
98 name
[len
++] = tolower(c
);
103 while (c
== ' ' || c
== '\t')
110 value
= parse_value();
114 return fn(name
, value
);
117 static int get_base_var(char *name
)
122 int c
= get_next_char();
129 if (baselen
> MAXNAME
/ 2)
131 name
[baselen
++] = tolower(c
);
135 static int git_parse_file(config_fn_t fn
)
139 static char var
[MAXNAME
];
142 int c
= get_next_char();
150 if (comment
|| isspace(c
))
152 if (c
== '#' || c
== ';') {
157 baselen
= get_base_var(var
);
160 var
[baselen
++] = '.';
167 if (get_value(fn
, var
, baselen
+1) < 0)
170 die("bad config file line %d", config_linenr
);
173 int git_config_int(const char *name
, const char *value
)
175 if (value
&& *value
) {
177 int val
= strtol(value
, &end
, 0);
181 die("bad config value for '%s'", name
);
184 int git_config_bool(const char *name
, const char *value
)
190 if (!strcasecmp(value
, "true"))
192 if (!strcasecmp(value
, "false"))
194 return git_config_int(name
, value
) != 0;
197 int git_default_config(const char *var
, const char *value
)
199 /* This needs a better name */
200 if (!strcmp(var
, "core.filemode")) {
201 trust_executable_bit
= git_config_bool(var
, value
);
205 /* Add other config variables here.. */
209 int git_config(config_fn_t fn
)
212 FILE *f
= fopen(git_path("config"), "r");
218 ret
= git_parse_file(fn
);