Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebc13b2

Browse files
committed
Clean up issues include.path issues found during code review.
* Error-handling is cleaned up to only let a file-not-found error through, not other sorts of errors. And when a file-not-found error happens, we clean up the error. * Test now checks that file-not-found introduces no error. And other minor cleanups.
1 parent 727ae38 commit ebc13b2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/config_file.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,11 +1280,18 @@ static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct r
12801280

12811281
r->file_path = git_buf_detach(&path);
12821282
git_buf_init(&r->buffer, 0);
1283-
if (git_futils_readbuffer_updated(&r->buffer, r->file_path, &r->file_mtime,
1284-
&r->file_size, NULL) == 0) {
1283+
result = git_futils_readbuffer_updated(&r->buffer, r->file_path, &r->file_mtime,
1284+
&r->file_size, NULL);
1285+
1286+
if (result == 0) {
12851287
result = config_parse(values, cfg_file, r, level, depth+1);
12861288
r = git_array_get(cfg_file->readers, index);
12871289
}
1290+
else if (result == GIT_ENOTFOUND) {
1291+
giterr_clear();
1292+
result = 0;
1293+
}
1294+
12881295
git_buf_free(&r->buffer);
12891296

12901297
if (result < 0)

tests/config/include.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ void test_config_include__missing(void)
9292
git_config *cfg;
9393
const char *str;
9494

95-
cl_git_mkfile("included", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
95+
cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
9696

97-
cl_git_pass(git_config_open_ondisk(&cfg, "included"));
97+
giterr_clear();
98+
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
99+
cl_assert(giterr_last() == NULL);
98100
cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
99101
cl_assert_equal_s(str, "baz");
100102

101103
git_config_free(cfg);
102-
unlink("included");
103104
}

0 commit comments

Comments
 (0)