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

[PATCH 1/2] Use git_open_noatime when accessing pack data

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 1, 2010, 22:54 UTC
Message-ID
<1288652061-19614-2-git-send-email-spearce@spearce.org>
In-Reply-To
<1288652061-19614-1-git-send-email-spearce@spearce.org>

This utility function avoids an unnecessary update of the access time for a loose object file. Just as the atime isn't useful on a loose object, its not useful on the pack or the corresonding idx file.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 sha1_file.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index f709ed6..a6c1934 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -35,6 +35,8 @@ static size_t sz_fmt(size_t s) { return s; }
 
 const unsigned char null_sha1[20];
 
+static int git_open_noatime(const char *name);
+
 int safe_create_leading_directories(char *path)
 {
 	char *pos = path + offset_1st_component(path);
@@ -298,7 +300,7 @@ static void read_info_alternates(const char * relative_base, int depth)
 	int fd;
 
 	sprintf(path, "%s/%s", relative_base, alt_file_name);
-	fd = open(path, O_RDONLY);
+	fd = git_open_noatime(path);
 	if (fd < 0)
 		return;
 	if (fstat(fd, &st) || (st.st_size == 0)) {
@@ -411,7 +413,7 @@ static int check_packed_git_idx(const char *path,  struct packed_git *p)
 	struct pack_idx_header *hdr;
 	size_t idx_size;
 	uint32_t version, nr, i, *index;
-	int fd = open(path, O_RDONLY);
+	int fd = git_open_noatime(path);
 	struct stat st;
 
 	if (fd < 0)
@@ -655,9 +657,9 @@ static int open_packed_git_1(struct packed_git *p)
 	if (!p->index_data && open_pack_index(p))
 		return error("packfile %s index unavailable", p->pack_name);
 
-	p->pack_fd = open(p->pack_name, O_RDONLY);
+	p->pack_fd = git_open_noatime(p->pack_name);
 	while (p->pack_fd < 0 && errno == EMFILE && unuse_one_window(p, -1))
-		p->pack_fd = open(p->pack_name, O_RDONLY);
+		p->pack_fd = git_open_noatime(p->pack_name);
 	if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
 		return -1;
 
-- 
1.7.3.2.191.g2d0e5
Previous: Shawn O. PearceNext: Junio C Hamano
Message 2 of 11 in “Work around too many file descriptors”
  1. 0/2 Work around too many file descriptorsShawn O. Pearce, Nov 1, 2010
  2. 1/2 Use git_open_noatime when accessing pack dataShawn O. Pearce, Nov 1, 2010
  3. Junio C HamanoNov 3, 2010
  4. Jonathan NiederNov 3, 2010
  5. Junio C HamanoNov 3, 2010
  6. Jonathan NiederNov 4, 2010
  7. Kevin BallardNov 4, 2010
  8. Junio C HamanoNov 5, 2010
  9. 2/2 Work around EMFILE when there are too many pack filesShawn O. Pearce, Nov 1, 2010
  10. Johannes SixtNov 2, 2010
  11. Junio C HamanoNov 3, 2010

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.