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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Aug 18, 2017 at 15:20 UTC
3836d88ae575cf2321fb17296f748c0bb35ba268
9 files changed
+70
-63
builtin/am.c
+1
@@ -31,6 +31,7 @@
31
#include "mailinfo.h"
32
#include "apply.h"
33
#include "string-list.h"
34
+#include "packfile.h"
35
36
/**
37
* Returns 1 if the file is empty or does not exist, 0 otherwise.
builtin/clone.c
+1
@@ -25,6 +25,7 @@
25
#include "remote.h"
26
#include "run-command.h"
27
#include "connected.h"
28
+#include "packfile.h"
29
30
/*
31
* Overall FIXMEs:
builtin/fetch.c
+1
@@ -17,6 +17,7 @@
17
#include "connected.h"
18
#include "argv-array.h"
19
#include "utf8.h"
20
+#include "packfile.h"
21
22
static const char * const builtin_fetch_usage[] = {
23
N_("git fetch [<options>] [<repository> [<refspec>...]]"),
builtin/merge.c
+1
@@ -32,6 +32,7 @@
32
#include "gpg-interface.h"
33
#include "sequencer.h"
34
#include "string-list.h"
35
+#include "packfile.h"
36
37
#define DEFAULT_TWOHEAD (1<<0)
38
#define DEFAULT_OCTOPUS (1<<1)
builtin/receive-pack.c
+1
@@ -23,6 +23,7 @@
23
#include "fsck.h"
24
#include "tmp-objdir.h"
25
#include "oidset.h"
26
+#include "packfile.h"
27
28
static const char * const receive_pack_usage[] = {
29
N_("git receive-pack <git-dir>"),
cache.h
-8
@@ -1639,15 +1639,7 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern);
1639
*/
1640
extern int odb_pack_keep(const char *name);
1641
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
-
1642
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);
1643
extern void unuse_pack(struct pack_window **);
1644
extern void clear_delta_base_cache(void);
1645
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
packfile.c
+54
@@ -257,3 +257,57 @@ void release_pack_memory(size_t need)
257
while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
258
; /* nothing */
259
}
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
+11
@@ -43,6 +43,17 @@ extern void pack_report(void);
43
*/
44
extern int open_pack_index(struct packed_git *);
45
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
+
57
extern int unuse_one_window(struct packed_git *current);
58
59
extern void release_pack_memory(size_t);
sha1_file.c
-55
@@ -719,53 +719,6 @@ void *xmmap(void *start, size_t length,
719
return ret;
720
}
721
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
-
722
/*
723
* The LRU pack is the one with the oldest MRU window, preferring packs
724
* 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)
801
}
802
}
803
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
-
804
static unsigned int get_max_fd_limit(void)
805
{
806
#ifdef RLIMIT_NOFILE