From 3836d88ae575cf2321fb17296f748c0bb35ba268 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:21 -0700 Subject: pack: move pack-closing functions The function close_pack_fd() needs to be temporarily made global. Its scope will be restored to static in a subsequent commit. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- packfile.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 8daa74ad11..c8e2dbdeec 100644 --- a/packfile.c +++ b/packfile.c @@ -257,3 +257,57 @@ void release_pack_memory(size_t need) while (need >= (cur - pack_mapped) && unuse_one_window(NULL)) ; /* nothing */ } + +void close_pack_windows(struct packed_git *p) +{ + while (p->windows) { + struct pack_window *w = p->windows; + + if (w->inuse_cnt) + die("pack '%s' still has open windows to it", + p->pack_name); + munmap(w->base, w->len); + pack_mapped -= w->len; + pack_open_windows--; + p->windows = w->next; + free(w); + } +} + +int close_pack_fd(struct packed_git *p) +{ + if (p->pack_fd < 0) + return 0; + + close(p->pack_fd); + pack_open_fds--; + p->pack_fd = -1; + + return 1; +} + +void close_pack_index(struct packed_git *p) +{ + if (p->index_data) { + munmap((void *)p->index_data, p->index_size); + p->index_data = NULL; + } +} + +static void close_pack(struct packed_git *p) +{ + close_pack_windows(p); + close_pack_fd(p); + close_pack_index(p); +} + +void close_all_packs(void) +{ + struct packed_git *p; + + for (p = packed_git; p; p = p->next) + if (p->do_not_close) + die("BUG: want to close pack marked 'do-not-close'"); + else + close_pack(p); +} -- cgit v1.2.3