packfile: pass `repository` to static function in the file

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

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Karthik Nayak 2024-12-03 15:43:57 +01:00 committed by Junio C Hamano
parent 9c5ce06d74
commit 4f9e6bd492
1 changed files with 8 additions and 7 deletions

View File

@ -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; *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 packed_git *p, *lru_p = NULL;
struct pack_window *mru_w = NULL; struct pack_window *mru_w = NULL;
int accept_windows_inuse = 1; 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) if (p->pack_fd == -1)
continue; continue;
find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse); 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; 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->repo))
; /* nothing */ ; /* nothing */


p->pack_fd = git_open(p->pack_name); p->pack_fd = git_open(p->pack_name);
@ -610,7 +610,8 @@ static int open_packed_git(struct packed_git *p)
return -1; 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 /* We must promise at least one full hash after the
* offset is available from this window, otherwise the offset * 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; off_t win_off = win->offset;
return win_off <= 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, unsigned char *use_pack(struct packed_git *p,
@ -642,11 +643,11 @@ unsigned char *use_pack(struct packed_git *p,
if (offset < 0) if (offset < 0)
die(_("offset before end of packfile (broken .idx?)")); die(_("offset before end of packfile (broken .idx?)"));


if (!win || !in_window(win, offset)) { if (!win || !in_window(p->repo, win, offset)) {
if (win) if (win)
win->inuse_cnt--; win->inuse_cnt--;
for (win = p->windows; win; win = win->next) { for (win = p->windows; win; win = win->next) {
if (in_window(win, offset)) if (in_window(p->repo, win, offset))
break; break;
} }
if (!win) { if (!win) {