Skip to content

Commit d6c8a05

Browse files
peffgitster
authored andcommitted
open_sha1_file: report "most interesting" errno
When we try to open a loose object file, we first attempt to open in the local object database, and then try any alternates. This means that the errno value when we return will be from the last place we looked (and due to the way the code is structured, simply ENOENT if we do not have have any alternates). This can cause confusing error messages, as read_sha1_file checks for ENOENT when reporting a missing object. If errno is something else, we report that. If it is ENOENT, but has_loose_object reports that we have it, then we claim the object is corrupted. For example: $ chmod 0 .git/objects/??/* $ git rev-list --all fatal: loose object b2d6fab18b92d49eac46dc3c5a0bcafabda20131 (stored in .git/objects/b2/d6fab18b92d49eac46dc3c5a0bcafabda20131) is corrupt This patch instead keeps track of the "most interesting" errno we receive during our search. We consider ENOENT to be the least interesting of all, and otherwise report the first error found (so problems in the object database take precedence over ones in alternates). Here it is with this patch: $ git rev-list --all fatal: failed to read object b2d6fab18b92d49eac46dc3c5a0bcafabda20131: Permission denied Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bbc4e8 commit d6c8a05

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sha1_file.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,20 +1424,24 @@ static int open_sha1_file(const unsigned char *sha1)
14241424
int fd;
14251425
char *name = sha1_file_name(sha1);
14261426
struct alternate_object_database *alt;
1427+
int most_interesting_errno;
14271428

14281429
fd = git_open_noatime(name);
14291430
if (fd >= 0)
14301431
return fd;
1432+
most_interesting_errno = errno;
14311433

14321434
prepare_alt_odb();
1433-
errno = ENOENT;
14341435
for (alt = alt_odb_list; alt; alt = alt->next) {
14351436
name = alt->name;
14361437
fill_sha1_path(name, sha1);
14371438
fd = git_open_noatime(alt->base);
14381439
if (fd >= 0)
14391440
return fd;
1441+
if (most_interesting_errno == ENOENT)
1442+
most_interesting_errno = errno;
14401443
}
1444+
errno = most_interesting_errno;
14411445
return -1;
14421446
}
14431447

0 commit comments

Comments
 (0)