зеркало из https://github.com/microsoft/git.git
sha1_file: consolidate code to close a pack's file descriptor
There was a lot of repeated code to close the file descriptor of a given pack. Let's just refactor this code into a single function. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
11911bf7c4
Коммит
71fe5d7fb0
38
sha1_file.c
38
sha1_file.c
|
@ -753,6 +753,18 @@ void close_pack_windows(struct packed_git *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The LRU pack is the one with the oldest MRU window, preferring packs
|
* 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.
|
* with no used windows, or the oldest mtime if it has no windows allocated.
|
||||||
|
@ -820,12 +832,8 @@ static int close_one_pack(void)
|
||||||
find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);
|
find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lru_p) {
|
if (lru_p)
|
||||||
close(lru_p->pack_fd);
|
return close_pack_fd(lru_p);
|
||||||
pack_open_fds--;
|
|
||||||
lru_p->pack_fd = -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -866,10 +874,7 @@ void free_pack_by_name(const char *pack_name)
|
||||||
if (strcmp(pack_name, p->pack_name) == 0) {
|
if (strcmp(pack_name, p->pack_name) == 0) {
|
||||||
clear_delta_base_cache();
|
clear_delta_base_cache();
|
||||||
close_pack_windows(p);
|
close_pack_windows(p);
|
||||||
if (p->pack_fd != -1) {
|
close_pack_fd(p);
|
||||||
close(p->pack_fd);
|
|
||||||
pack_open_fds--;
|
|
||||||
}
|
|
||||||
close_pack_index(p);
|
close_pack_index(p);
|
||||||
free(p->bad_object_sha1);
|
free(p->bad_object_sha1);
|
||||||
*pp = p->next;
|
*pp = p->next;
|
||||||
|
@ -1004,11 +1009,7 @@ static int open_packed_git(struct packed_git *p)
|
||||||
{
|
{
|
||||||
if (!open_packed_git_1(p))
|
if (!open_packed_git_1(p))
|
||||||
return 0;
|
return 0;
|
||||||
if (p->pack_fd != -1) {
|
close_pack_fd(p);
|
||||||
close(p->pack_fd);
|
|
||||||
pack_open_fds--;
|
|
||||||
p->pack_fd = -1;
|
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,11 +1075,8 @@ unsigned char *use_pack(struct packed_git *p,
|
||||||
p->pack_name,
|
p->pack_name,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
if (!win->offset && win->len == p->pack_size
|
if (!win->offset && win->len == p->pack_size
|
||||||
&& !p->do_not_close) {
|
&& !p->do_not_close)
|
||||||
close(p->pack_fd);
|
close_pack_fd(p);
|
||||||
pack_open_fds--;
|
|
||||||
p->pack_fd = -1;
|
|
||||||
}
|
|
||||||
pack_mmap_calls++;
|
pack_mmap_calls++;
|
||||||
pack_open_windows++;
|
pack_open_windows++;
|
||||||
if (pack_mapped > peak_pack_mapped)
|
if (pack_mapped > peak_pack_mapped)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче