6 static FILE *config_file
;
7 static int config_linenr
;
8 static int get_next_char(void)
14 if ((f
= config_file
) != NULL
) {
17 /* DOS like systems */
34 static char *parse_value(void)
36 static char value
[1024];
37 int quote
= 0, comment
= 0, len
= 0, space
= 0;
40 int c
= get_next_char();
41 if (len
>= sizeof(value
))
51 if (isspace(c
) && !quote
) {
74 /* Some characters escape as themselves */
77 /* Reject unknown escape sequences */
89 if (c
== ';' || c
== '#') {
98 static int get_value(config_fn_t fn
, char *name
, unsigned int len
)
103 /* Get the full name */
110 name
[len
++] = tolower(c
);
115 while (c
== ' ' || c
== '\t')
122 value
= parse_value();
126 return fn(name
, value
);
129 static int get_base_var(char *name
)
134 int c
= get_next_char();
141 if (baselen
> MAXNAME
/ 2)
143 name
[baselen
++] = tolower(c
);
147 static int git_parse_file(config_fn_t fn
)
151 static char var
[MAXNAME
];
154 int c
= get_next_char();
162 if (comment
|| isspace(c
))
164 if (c
== '#' || c
== ';') {
169 baselen
= get_base_var(var
);
172 var
[baselen
++] = '.';
178 var
[baselen
] = tolower(c
);
179 if (get_value(fn
, var
, baselen
+1) < 0)
182 die("bad config file line %d", config_linenr
);
185 int git_config_int(const char *name
, const char *value
)
187 if (value
&& *value
) {
189 int val
= strtol(value
, &end
, 0);
193 die("bad config value for '%s'", name
);
196 int git_config_bool(const char *name
, const char *value
)
202 if (!strcasecmp(value
, "true"))
204 if (!strcasecmp(value
, "false"))
206 return git_config_int(name
, value
) != 0;
209 int git_default_config(const char *var
, const char *value
)
211 /* This needs a better name */
212 if (!strcmp(var
, "core.filemode")) {
213 trust_executable_bit
= git_config_bool(var
, value
);
217 if (!strcmp(var
, "core.symrefsonly")) {
218 only_use_symrefs
= git_config_bool(var
, value
);
222 if (!strcmp(var
, "user.name")) {
223 strncpy(git_default_name
, value
, sizeof(git_default_name
));
227 if (!strcmp(var
, "user.email")) {
228 strncpy(git_default_email
, value
, sizeof(git_default_email
));
232 if (!strcmp(var
, "diff.renamelimit")) {
233 diff_rename_limit_default
= git_config_int(var
, value
);
237 /* Add other config variables here.. */
241 int git_config(config_fn_t fn
)
244 FILE *f
= fopen(git_path("config"), "r");
250 ret
= git_parse_file(fn
);