Skip to content

Commit 3836d88

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f0e17e8 commit 3836d88

File tree

9 files changed

+70
-63
lines changed

9 files changed

+70
-63
lines changed

builtin/am.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "mailinfo.h"
3232
#include "apply.h"
3333
#include "string-list.h"
34+
#include "packfile.h"
3435

3536
/**
3637
* Returns 1 if the file is empty or does not exist, 0 otherwise.

builtin/clone.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "remote.h"
2626
#include "run-command.h"
2727
#include "connected.h"
28+
#include "packfile.h"
2829

2930
/*
3031
* Overall FIXMEs:

builtin/fetch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "connected.h"
1818
#include "argv-array.h"
1919
#include "utf8.h"
20+
#include "packfile.h"
2021

2122
static const char * const builtin_fetch_usage[] = {
2223
N_("git fetch [<options>] [<repository> [<refspec>...]]"),

builtin/merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "gpg-interface.h"
3333
#include "sequencer.h"
3434
#include "string-list.h"
35+
#include "packfile.h"
3536

3637
#define DEFAULT_TWOHEAD (1<<0)
3738
#define DEFAULT_OCTOPUS (1<<1)

builtin/receive-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "fsck.h"
2424
#include "tmp-objdir.h"
2525
#include "oidset.h"
26+
#include "packfile.h"
2627

2728
static const char * const receive_pack_usage[] = {
2829
N_("git receive-pack <git-dir>"),

cache.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,15 +1639,7 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern);
16391639
*/
16401640
extern int odb_pack_keep(const char *name);
16411641

1642-
/*
1643-
* munmap the index file for the specified packfile (if it is
1644-
* currently mmapped).
1645-
*/
1646-
extern void close_pack_index(struct packed_git *);
1647-
16481642
extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
1649-
extern void close_pack_windows(struct packed_git *);
1650-
extern void close_all_packs(void);
16511643
extern void unuse_pack(struct pack_window **);
16521644
extern void clear_delta_base_cache(void);
16531645
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);

packfile.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,57 @@ void release_pack_memory(size_t need)
257257
while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
258258
; /* nothing */
259259
}
260+
261+
void close_pack_windows(struct packed_git *p)
262+
{
263+
while (p->windows) {
264+
struct pack_window *w = p->windows;
265+
266+
if (w->inuse_cnt)
267+
die("pack '%s' still has open windows to it",
268+
p->pack_name);
269+
munmap(w->base, w->len);
270+
pack_mapped -= w->len;
271+
pack_open_windows--;
272+
p->windows = w->next;
273+
free(w);
274+
}
275+
}
276+
277+
int close_pack_fd(struct packed_git *p)
278+
{
279+
if (p->pack_fd < 0)
280+
return 0;
281+
282+
close(p->pack_fd);
283+
pack_open_fds--;
284+
p->pack_fd = -1;
285+
286+
return 1;
287+
}
288+
289+
void close_pack_index(struct packed_git *p)
290+
{
291+
if (p->index_data) {
292+
munmap((void *)p->index_data, p->index_size);
293+
p->index_data = NULL;
294+
}
295+
}
296+
297+
static void close_pack(struct packed_git *p)
298+
{
299+
close_pack_windows(p);
300+
close_pack_fd(p);
301+
close_pack_index(p);
302+
}
303+
304+
void close_all_packs(void)
305+
{
306+
struct packed_git *p;
307+
308+
for (p = packed_git; p; p = p->next)
309+
if (p->do_not_close)
310+
die("BUG: want to close pack marked 'do-not-close'");
311+
else
312+
close_pack(p);
313+
}

packfile.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ extern void pack_report(void);
4343
*/
4444
extern int open_pack_index(struct packed_git *);
4545

46+
/*
47+
* munmap the index file for the specified packfile (if it is
48+
* currently mmapped).
49+
*/
50+
extern void close_pack_index(struct packed_git *);
51+
52+
extern void close_pack_windows(struct packed_git *);
53+
extern void close_all_packs(void);
54+
55+
extern int close_pack_fd(struct packed_git *);
56+
4657
extern int unuse_one_window(struct packed_git *current);
4758

4859
extern void release_pack_memory(size_t);

sha1_file.c

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -719,53 +719,6 @@ void *xmmap(void *start, size_t length,
719719
return ret;
720720
}
721721

722-
void close_pack_windows(struct packed_git *p)
723-
{
724-
while (p->windows) {
725-
struct pack_window *w = p->windows;
726-
727-
if (w->inuse_cnt)
728-
die("pack '%s' still has open windows to it",
729-
p->pack_name);
730-
munmap(w->base, w->len);
731-
pack_mapped -= w->len;
732-
pack_open_windows--;
733-
p->windows = w->next;
734-
free(w);
735-
}
736-
}
737-
738-
static int close_pack_fd(struct packed_git *p)
739-
{
740-
if (p->pack_fd < 0)
741-
return 0;
742-
743-
close(p->pack_fd);
744-
pack_open_fds--;
745-
p->pack_fd = -1;
746-
747-
return 1;
748-
}
749-
750-
static void close_pack(struct packed_git *p)
751-
{
752-
close_pack_windows(p);
753-
close_pack_fd(p);
754-
close_pack_index(p);
755-
}
756-
757-
void close_all_packs(void)
758-
{
759-
struct packed_git *p;
760-
761-
for (p = packed_git; p; p = p->next)
762-
if (p->do_not_close)
763-
die("BUG: want to close pack marked 'do-not-close'");
764-
else
765-
close_pack(p);
766-
}
767-
768-
769722
/*
770723
* The LRU pack is the one with the oldest MRU window, preferring packs
771724
* with no used windows, or the oldest mtime if it has no windows allocated.
@@ -848,14 +801,6 @@ void unuse_pack(struct pack_window **w_cursor)
848801
}
849802
}
850803

851-
void close_pack_index(struct packed_git *p)
852-
{
853-
if (p->index_data) {
854-
munmap((void *)p->index_data, p->index_size);
855-
p->index_data = NULL;
856-
}
857-
}
858-
859804
static unsigned int get_max_fd_limit(void)
860805
{
861806
#ifdef RLIMIT_NOFILE

0 commit comments

Comments
 (0)