mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
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>
This commit is contained in:
parent
f0e17e86e1
commit
3836d88ae5
@ -31,6 +31,7 @@
|
||||
#include "mailinfo.h"
|
||||
#include "apply.h"
|
||||
#include "string-list.h"
|
||||
#include "packfile.h"
|
||||
|
||||
/**
|
||||
* Returns 1 if the file is empty or does not exist, 0 otherwise.
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "remote.h"
|
||||
#include "run-command.h"
|
||||
#include "connected.h"
|
||||
#include "packfile.h"
|
||||
|
||||
/*
|
||||
* Overall FIXMEs:
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "connected.h"
|
||||
#include "argv-array.h"
|
||||
#include "utf8.h"
|
||||
#include "packfile.h"
|
||||
|
||||
static const char * const builtin_fetch_usage[] = {
|
||||
N_("git fetch [<options>] [<repository> [<refspec>...]]"),
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "gpg-interface.h"
|
||||
#include "sequencer.h"
|
||||
#include "string-list.h"
|
||||
#include "packfile.h"
|
||||
|
||||
#define DEFAULT_TWOHEAD (1<<0)
|
||||
#define DEFAULT_OCTOPUS (1<<1)
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "fsck.h"
|
||||
#include "tmp-objdir.h"
|
||||
#include "oidset.h"
|
||||
#include "packfile.h"
|
||||
|
||||
static const char * const receive_pack_usage[] = {
|
||||
N_("git receive-pack <git-dir>"),
|
||||
|
8
cache.h
8
cache.h
@ -1639,15 +1639,7 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern);
|
||||
*/
|
||||
extern int odb_pack_keep(const char *name);
|
||||
|
||||
/*
|
||||
* munmap the index file for the specified packfile (if it is
|
||||
* currently mmapped).
|
||||
*/
|
||||
extern void close_pack_index(struct packed_git *);
|
||||
|
||||
extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
|
||||
extern void close_pack_windows(struct packed_git *);
|
||||
extern void close_all_packs(void);
|
||||
extern void unuse_pack(struct pack_window **);
|
||||
extern void clear_delta_base_cache(void);
|
||||
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
|
||||
|
54
packfile.c
54
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);
|
||||
}
|
||||
|
11
packfile.h
11
packfile.h
@ -43,6 +43,17 @@ extern void pack_report(void);
|
||||
*/
|
||||
extern int open_pack_index(struct packed_git *);
|
||||
|
||||
/*
|
||||
* munmap the index file for the specified packfile (if it is
|
||||
* currently mmapped).
|
||||
*/
|
||||
extern void close_pack_index(struct packed_git *);
|
||||
|
||||
extern void close_pack_windows(struct packed_git *);
|
||||
extern void close_all_packs(void);
|
||||
|
||||
extern int close_pack_fd(struct packed_git *);
|
||||
|
||||
extern int unuse_one_window(struct packed_git *current);
|
||||
|
||||
extern void release_pack_memory(size_t);
|
||||
|
55
sha1_file.c
55
sha1_file.c
@ -719,53 +719,6 @@ void *xmmap(void *start, size_t length,
|
||||
return ret;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The LRU pack is the one with the oldest MRU window, preferring packs
|
||||
* 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)
|
||||
}
|
||||
}
|
||||
|
||||
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 unsigned int get_max_fd_limit(void)
|
||||
{
|
||||
#ifdef RLIMIT_NOFILE
|
||||
|
Loading…
Reference in New Issue
Block a user