]> asedeno.scripts.mit.edu Git - git.git/blobdiff - read-cache.c
read_cache_from(): small simplification
[git.git] / read-cache.c
index e04e99112d4c4b19dc1b6e1dcab89600bb30b57a..d9f46da5cc547d8cfaa34c901be50a13995b120e 100644 (file)
@@ -864,16 +864,15 @@ int read_index_from(struct index_state *istate, const char *path)
                die("index file open failed (%s)", strerror(errno));
        }
 
-       if (!fstat(fd, &st)) {
-               istate->mmap_size = xsize_t(st.st_size);
-               errno = EINVAL;
-               if (istate->mmap_size >= sizeof(struct cache_header) + 20)
-                       istate->mmap = xmmap(NULL, istate->mmap_size,
-                                           PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
-               else
-                       die("index file smaller than expected");
-       } else
+       if (fstat(fd, &st))
                die("cannot stat the open index (%s)", strerror(errno));
+
+       errno = EINVAL;
+       istate->mmap_size = xsize_t(st.st_size);
+       if (istate->mmap_size < sizeof(struct cache_header) + 20)
+               die("index file smaller than expected");
+
+       istate->mmap = xmmap(NULL, istate->mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
        close(fd);
 
        hdr = istate->mmap;