Skip to content

Commit 4f9e6bd

Browse files
KarthikNayakgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9c5ce06 commit 4f9e6bd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packfile.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,13 @@ static void find_lru_pack(struct packed_git *p, struct packed_git **lru_p, struc
460460
*accept_windows_inuse = has_windows_inuse;
461461
}
462462

463-
static int close_one_pack(void)
463+
static int close_one_pack(struct repository *r)
464464
{
465465
struct packed_git *p, *lru_p = NULL;
466466
struct pack_window *mru_w = NULL;
467467
int accept_windows_inuse = 1;
468468

469-
for (p = the_repository->objects->packed_git; p; p = p->next) {
469+
for (p = r->objects->packed_git; p; p = p->next) {
470470
if (p->pack_fd == -1)
471471
continue;
472472
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)
555555
pack_max_fds = 1;
556556
}
557557

558-
while (pack_max_fds <= pack_open_fds && close_one_pack())
558+
while (pack_max_fds <= pack_open_fds && close_one_pack(p->repo))
559559
; /* nothing */
560560

561561
p->pack_fd = git_open(p->pack_name);
@@ -610,7 +610,8 @@ static int open_packed_git(struct packed_git *p)
610610
return -1;
611611
}
612612

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)
614615
{
615616
/* We must promise at least one full hash after the
616617
* offset is available from this window, otherwise the offset
@@ -620,7 +621,7 @@ static int in_window(struct pack_window *win, off_t offset)
620621
*/
621622
off_t win_off = win->offset;
622623
return win_off <= offset
623-
&& (offset + the_hash_algo->rawsz) <= (win_off + win->len);
624+
&& (offset + r->hash_algo->rawsz) <= (win_off + win->len);
624625
}
625626

626627
unsigned char *use_pack(struct packed_git *p,
@@ -642,11 +643,11 @@ unsigned char *use_pack(struct packed_git *p,
642643
if (offset < 0)
643644
die(_("offset before end of packfile (broken .idx?)"));
644645

645-
if (!win || !in_window(win, offset)) {
646+
if (!win || !in_window(p->repo, win, offset)) {
646647
if (win)
647648
win->inuse_cnt--;
648649
for (win = p->windows; win; win = win->next) {
649-
if (in_window(win, offset))
650+
if (in_window(p->repo, win, offset))
650651
break;
651652
}
652653
if (!win) {

0 commit comments

Comments
 (0)