config: drop cf validity check in get_next_char()
The global variable cf is set with an initialized value in all codepaths before calling this function. The complete call graph looks like this: git_config_from_file -> do_config_from -> git_parse_file -> get_next_char -> get_value -> get_next_char -> parse_value -> get_next_char -> get_base_var -> get_next_char -> get_extended_base_var -> get_next_char The variable is initialized in do_config_from. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Heiko Voigt committed
May 11, 2013 at 15:19 UTC
dbb9a8125542be4d57bc71b6d5baf81c7409a68b
1 file changed
+13
-16
config.c
+13
-16
@@ -169,26 +169,23 @@ int git_config_from_parameters(config_fn_t fn, void *data)
169
static int get_next_char(void)
170
{
171
int c;
172
- FILE *f;
172
+ FILE *f = cf->f;
173
174
- c = '\n';
175
- if (cf && ((f = cf->f) != NULL)) {
174
+ c = fgetc(f);
175
+ if (c == '\r') {
176
+ /* DOS like systems */
177
c = fgetc(f);
177
- if (c == '\r') {
178
- /* DOS like systems */
179
- c = fgetc(f);
180
- if (c != '\n') {
181
- ungetc(c, f);
182
- c = '\r';
183
- }
184
- }
185
- if (c == '\n')
186
- cf->linenr++;
187
- if (c == EOF) {
188
- cf->eof = 1;
189
- c = '\n';
178
+ if (c != '\n') {
179
+ ungetc(c, f);
180
+ c = '\r';
181
}
182
}
183
+ if (c == '\n')
184
+ cf->linenr++;
185
+ if (c == EOF) {
186
+ cf->eof = 1;
187
+ c = '\n';
188
+ }
189
return c;
190
}
191