@matheusbsbs / matheus-bagliano / commits / 3511a3774e
Fork 0

read_cache_from(): small simplification

This change 'opens' the code block which maps the index file into memory, making the code clearer and easier to read. Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> Signed-off-by: Junio C Hamano <junkio@cox.net>

Luiz Fernando N. Capitulino committed Apr 25, 2007 at 11:18 UTC 3511a3774e60783d979ebc2ef7b04371a23602bb
1 file changed +8 -9
read-cache.c
+8 -9
@@ -864,16 +864,15 @@ int read_index_from(struct index_state *istate, const char *path)
864 die("index file open failed (%s)", strerror(errno));
865 }
866
867 - if (!fstat(fd, &st)) {
868 - istate->mmap_size = xsize_t(st.st_size);
869 - errno = EINVAL;
870 - if (istate->mmap_size >= sizeof(struct cache_header) + 20)
871 - istate->mmap = xmmap(NULL, istate->mmap_size,
872 - PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
873 - else
874 - die("index file smaller than expected");
875 - } else
867 + if (fstat(fd, &st))
868 die("cannot stat the open index (%s)", strerror(errno));
869 +
870 + errno = EINVAL;
871 + istate->mmap_size = xsize_t(st.st_size);
872 + if (istate->mmap_size < sizeof(struct cache_header) + 20)
873 + die("index file smaller than expected");
874 +
875 + istate->mmap = xmmap(NULL, istate->mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
876 close(fd);
877
878 hdr = istate->mmap;