Web lists-archives.com

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




From: Jeff King <peff@xxxxxxxx>

Signed-off-by: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
---

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@xxxxxxxxxxxxxxxxxxxxx/#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