Skip to contentSkip to conversation

read_cache_from(): small simplification

PATCH In review Luiz Fernando N. Capitulino 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 3/5 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.

---
 read-cache.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
read-cache.c +8 -8
index d2f332a..24e5581 100644
@@ -856,15 +856,15 @@ int read_cache_from(const char *path)
 		die("index file open failed (%s)", strerror(errno));
 	}
 
-	if (!fstat(fd, &st)) {
-		cache_mmap_size = xsize_t(st.st_size);
-		errno = EINVAL;
-		if (cache_mmap_size >= sizeof(struct cache_header) + 20)
-			cache_mmap = xmmap(NULL, cache_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;
+	cache_mmap_size = xsize_t(st.st_size);
+	if (cache_mmap_size < sizeof(struct cache_header) + 20)
+		die("index file smaller than expected");
+
+	cache_mmap = xmmap(NULL, cache_mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
 	close(fd);
 
 	hdr = cache_mmap;
Signature · 1 line
1.5.1.1.320.g1cf2