Skip to content

Commit f0f7beb

Browse files
peffgitster
authored andcommitted
read_info_alternates: warn on non-trivial errors
When we fail to open $GIT_DIR/info/alternates, we silently assume there are no alternates. This is the right thing to do for ENOENT, but not for other errors. A hard error is probably overkill here. If we fail to read an alternates file then either we'll complete our operation anyway, or we'll fail to find some needed object. Either way, a warning is good idea. And we already have a helper function to handle this pattern; let's just call warn_on_fopen_error(). Note that technically the errno from strbuf_read_file() might be from a read() error, not open(). But since read() would never return ENOENT or ENOTDIR, and since it produces a generic "unable to access" error, it's suitable for handling errors from either. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0db625f commit f0f7beb

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

sha1_file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ static void read_info_alternates(const char * relative_base, int depth)
456456

457457
path = xstrfmt("%s/info/alternates", relative_base);
458458
if (strbuf_read_file(&buf, path, 1024) < 0) {
459+
warn_on_fopen_errors(path);
459460
free(path);
460461
return;
461462
}

0 commit comments

Comments
 (0)