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>
Karthik Nayak committed
Dec 3, 2024 at 15:43 UTC
4f9e6bd4923728053669c300d3ee8483d95f599b
1 file changed
+8
-7
packfile.c
+8
-7
@@ -460,13 +460,13 @@ static void find_lru_pack(struct packed_git *p, struct packed_git **lru_p, struc
460
*accept_windows_inuse = has_windows_inuse;
461
}
462
463
-static int close_one_pack(void)
463
+static int close_one_pack(struct repository *r)
464
{
465
struct packed_git *p, *lru_p = NULL;
466
struct pack_window *mru_w = NULL;
467
int accept_windows_inuse = 1;
468
469
- for (p = the_repository->objects->packed_git; p; p = p->next) {
469
+ for (p = r->objects->packed_git; p; p = p->next) {
470
if (p->pack_fd == -1)
471
continue;
472
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)
555
pack_max_fds = 1;
556
}
557
558
- while (pack_max_fds <= pack_open_fds && close_one_pack())
558
+ while (pack_max_fds <= pack_open_fds && close_one_pack(p->repo))
559
; /* nothing */
560
561
p->pack_fd = git_open(p->pack_name);
@@ -610,7 +610,8 @@ static int open_packed_git(struct packed_git *p)
610
return -1;
611
}
612
613
-static int in_window(struct pack_window *win, off_t offset)
613
+static int in_window(struct repository *r, struct pack_window *win,
614
+ off_t offset)
615
{
616
/* We must promise at least one full hash after the
617
* offset is available from this window, otherwise the offset
@@ -620,7 +621,7 @@ static int in_window(struct pack_window *win, off_t offset)
621
*/
622
off_t win_off = win->offset;
623
return win_off <= offset
623
- && (offset + the_hash_algo->rawsz) <= (win_off + win->len);
624
+ && (offset + r->hash_algo->rawsz) <= (win_off + win->len);
625
}
626
627
unsigned char *use_pack(struct packed_git *p,
@@ -642,11 +643,11 @@ unsigned char *use_pack(struct packed_git *p,
643
if (offset < 0)
644
die(_("offset before end of packfile (broken .idx?)"));
645
645
- if (!win || !in_window(win, offset)) {
646
+ if (!win || !in_window(p->repo, win, offset)) {
647
if (win)
648
win->inuse_cnt--;
649
for (win = p->windows; win; win = win->next) {
649
- if (in_window(win, offset))
650
+ if (in_window(p->repo, win, offset))
651
break;
652
}
653
if (!win) {