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

[PATCH v3 3/9] packfile: pass `repository` to static function in the file

From
Karthik Nayak <karthik.188@gmail.com>
Date
Oct 30, 2024, 14:32 UTC
Message-ID
<5b975cb6d6ad760d70c9e9649c30978f2952bff9.1730297934.git.karthik.188@gmail.com>
In-Reply-To
<cover.1730297934.git.karthik.188@gmail.com>

Some of the static functions in the `packfile.c` access global variables, which can simply be avoiding by passing the `repository` struct down to them. Let's do that.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 packfile.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/packfile.c b/packfile.c
index ecb284fd98..a391474031 100644
--- a/packfile.c
+++ b/packfile.c
@@ -460,13 +460,13 @@ static void find_lru_pack(struct packed_git *p, struct packed_git **lru_p, struc
 	*accept_windows_inuse = has_windows_inuse;
 }
 
-static int close_one_pack(void)
+static int close_one_pack(struct repository *r)
 {
 	struct packed_git *p, *lru_p = NULL;
 	struct pack_window *mru_w = NULL;
 	int accept_windows_inuse = 1;
 
-	for (p = the_repository->objects->packed_git; p; p = p->next) {
+	for (p = r->objects->packed_git; p; p = p->next) {
 		if (p->pack_fd == -1)
 			continue;
 		find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);
@@ -555,7 +555,7 @@ static int open_packed_git_1(struct packed_git *p)
 			pack_max_fds = 1;
 	}
 
-	while (pack_max_fds <= pack_open_fds && close_one_pack())
+	while (pack_max_fds <= pack_open_fds && close_one_pack(p->r))
 		; /* nothing */
 
 	p->pack_fd = git_open(p->pack_name);
@@ -610,7 +610,8 @@ static int open_packed_git(struct packed_git *p)
 	return -1;
 }
 
-static int in_window(struct pack_window *win, off_t offset)
+static int in_window(struct repository *r, struct pack_window *win,
+		     off_t offset)
 {
 	/* We must promise at least one full hash after the
 	 * offset is available from this window, otherwise the offset
@@ -620,7 +621,7 @@ static int in_window(struct pack_window *win, off_t offset)
 	 */
 	off_t win_off = win->offset;
 	return win_off <= offset
-		&& (offset + the_hash_algo->rawsz) <= (win_off + win->len);
+		&& (offset + r->hash_algo->rawsz) <= (win_off + win->len);
 }
 
 unsigned char *use_pack(struct packed_git *p,
@@ -642,11 +643,11 @@ unsigned char *use_pack(struct packed_git *p,
 	if (offset < 0)
 		die(_("offset before end of packfile (broken .idx?)"));
 
-	if (!win || !in_window(win, offset)) {
+	if (!win || !in_window(p->r, win, offset)) {
 		if (win)
 			win->inuse_cnt--;
 		for (win = p->windows; win; win = win->next) {
-			if (in_window(win, offset))
+			if (in_window(p->r, win, offset))
 				break;
 		}
 		if (!win) {
-- 
2.47.0
Previous: Taylor BlauNext: Karthik Nayak
Message 4 of 13 in “packfile: avoid using the 'the_repository' global variable”
  1. 0/9 packfile: avoid using the 'the_repository' global variableKarthik Nayak, Oct 30, 2024
  2. 1/9 packfile: add repository to struct `packed_git`Karthik Nayak, Oct 30, 2024
  3. Taylor BlauOct 30, 2024
  4. 3/9 packfile: pass `repository` to static function in the fileKarthik Nayak, Oct 30, 2024
  5. 2/9 packfile: use `repository` from `packed_git` directlyKarthik Nayak, Oct 30, 2024
  6. 4/9 packfile: pass down repository to `odb_pack_name`Karthik Nayak, Oct 30, 2024
  7. 5/9 packfile: pass down repository to `has_object[_kept]_pack`Karthik Nayak, Oct 30, 2024
  8. 7/9 config: make `delta_base_cache_limit` a non-global variableKarthik Nayak, Oct 30, 2024
  9. 8/9 config: make `packed_git_(limit|window_size)` non-global variablesKarthik Nayak, Oct 30, 2024
  10. 6/9 packfile: pass down repository to `for_each_packed_object`Karthik Nayak, Oct 30, 2024
  11. 9/9 midx: add repository to `multi_pack_index` structKarthik Nayak, Oct 30, 2024
  12. Taylor BlauOct 30, 2024
  13. karthik nayakOct 31, 2024

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.