Skip to content

Commit dbb9a81

Browse files
hvoigtgitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca4b5de commit dbb9a81

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

config.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,23 @@ int git_config_from_parameters(config_fn_t fn, void *data)
169169
static int get_next_char(void)
170170
{
171171
int c;
172-
FILE *f;
172+
FILE *f = cf->f;
173173

174-
c = '\n';
175-
if (cf && ((f = cf->f) != NULL)) {
174+
c = fgetc(f);
175+
if (c == '\r') {
176+
/* DOS like systems */
176177
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';
190181
}
191182
}
183+
if (c == '\n')
184+
cf->linenr++;
185+
if (c == EOF) {
186+
cf->eof = 1;
187+
c = '\n';
188+
}
192189
return c;
193190
}
194191

0 commit comments

Comments
 (0)