git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] read_cache_from(): small simplification

From
LCLuiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
Date
Apr 25, 2007, 14:18 UTC
Message-ID
<20070425111817.4d4e4af5@localhost>

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>
---
 read-cache.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index d2f332a..24e5581 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -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;
-- 
1.5.1.1.320.g1cf2
Message 1 of 1 in “read_cache_from(): small simplification”
  1. 3/5 read_cache_from(): small simplificationLuiz Fernando N. Capitulino, Apr 25, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.