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

[RFC/PATCH] packfile: use extra variable to clarify code in use_pack()

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
Mar 12, 2019, 16:55 UTC
Message-ID
<e561b83f-cf1c-eef8-7651-8519ce105491@ramsayjones.plus.com>
From: Jeff King <peff@peff.net>
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
Hi Jeff,

I recently tried (yet again) to tidy up some old branches. When I get around to doing a 'git gc; git fsck' I always take a quick look at the 'dangling' commits, just before a 'git gc --prune=now'.

I had no recollection of this commit, from last October, but a quick look at the ML archive found this [1] discussion. I obviously thought it was worth saving this thought of yours. ;-) So, having deleted this already, I did a quick 'format-patch' to see if anyone thinks it is worth applying.

[1] https://public-inbox.org/git/20181013024624.GB15595@sigill.intra.peff.net/#t
Thanks!

ATB, Ramsay Jones

 packfile.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/packfile.c b/packfile.c
index 013294aec7..2f81ec9345 100644
--- a/packfile.c
+++ b/packfile.c
@@ -588,6 +588,7 @@ unsigned char *use_pack(struct packed_git *p,
 		size_t *left)
 {
 	struct pack_window *win = *w_cursor;
+	size_t offset_in_window;
 
 	/* Since packfiles end in a hash of their content and it's
 	 * pointless to ask for an offset into the middle of that
@@ -649,10 +650,14 @@ unsigned char *use_pack(struct packed_git *p,
 		win->inuse_cnt++;
 		*w_cursor = win;
 	}
-	offset -= win->offset;
+	/*
+	 * We know this difference will fit in a size_t, because our mmap
+	 * window by definition can be no larger than a size_t.
+	 */
+	offset_in_window = xsize_t(offset - win->offset);
 	if (left)
-		*left = win->len - xsize_t(offset);
-	return win->base + offset;
+		*left = win->len - offset_in_window;
+	return win->base + offset_in_window;
 }
 
 void unuse_pack(struct pack_window **w_cursor)
-- 
2.21.0
Next: Ramsay Jones
Message 1 of 4 in “packfile: use extra variable to clarify code in use_pack()”
  1. packfile: use extra variable to clarify code in use_pack()Ramsay Jones, Mar 12, 2019
  2. Ramsay JonesMar 12, 2019
  3. Jeff KingMar 12, 2019
  4. Ramsay JonesMar 12, 2019

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.