Skip to content

Commit 57d84f8

Browse files
pcloudsgitster
authored andcommitted
read_index_from: remove bogus errno assignments
These assignments comes from the very first commit e83c516 (Initial revision of "git", the information manager from hell - 2005-04-07). Back then we did not die() when errors happened so correct errno was required. Since 5d1a5c0 ([PATCH] Better error reporting for "git status" - 2005-10-01), read_index_from() learned to die rather than just return -1 and these assignments became irrelevant. Remove them. While at it, move die_errno() next to xmmap() call because it's the mmap's error code that we care about. Otherwise if close(fd); fails, it could overwrite mmap's errno. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f174a25 commit 57d84f8

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

read-cache.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,11 +1274,9 @@ int read_index_from(struct index_state *istate, const char *path)
12741274
void *mmap;
12751275
size_t mmap_size;
12761276

1277-
errno = EBUSY;
12781277
if (istate->initialized)
12791278
return istate->cache_nr;
12801279

1281-
errno = ENOENT;
12821280
istate->timestamp.sec = 0;
12831281
istate->timestamp.nsec = 0;
12841282
fd = open(path, O_RDONLY);
@@ -1291,15 +1289,14 @@ int read_index_from(struct index_state *istate, const char *path)
12911289
if (fstat(fd, &st))
12921290
die_errno("cannot stat the open index");
12931291

1294-
errno = EINVAL;
12951292
mmap_size = xsize_t(st.st_size);
12961293
if (mmap_size < sizeof(struct cache_header) + 20)
12971294
die("index file smaller than expected");
12981295

12991296
mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
1300-
close(fd);
13011297
if (mmap == MAP_FAILED)
13021298
die_errno("unable to map index file");
1299+
close(fd);
13031300

13041301
hdr = mmap;
13051302
if (verify_hdr(hdr, mmap_size) < 0)
@@ -1358,7 +1355,6 @@ int read_index_from(struct index_state *istate, const char *path)
13581355

13591356
unmap:
13601357
munmap(mmap, mmap_size);
1361-
errno = EINVAL;
13621358
die("index file corrupt");
13631359
}
13641360

0 commit comments

Comments
 (0)