Merge branch 'racy-dissociate'

This topic branch replaces the previous patch and will be submitted to
the Git mailing list soon, as reply to:

	http://thread.gmane.org/gmane.comp.version-control.git/278746

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2015-10-18 13:51:33 +02:00
3 changed files with 36 additions and 28 deletions

View File

@@ -1067,12 +1067,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
transport_disconnect(transport);
if (option_dissociate) {
struct packed_git *p;
for (p = packed_git; p; p = p->next) {
close_pack_windows(p);
close_pack_index(p);
}
close_all_packs();
dissociate_from_references();
}

View File

@@ -1286,6 +1286,7 @@ 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 free_pack_by_name(const char *);
extern void clear_delta_base_cache(void);

View File

@@ -786,6 +786,34 @@ 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;
}
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)
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.
@@ -853,12 +881,8 @@ static int close_one_pack(void)
find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);
}
if (lru_p) {
close(lru_p->pack_fd);
pack_open_fds--;
lru_p->pack_fd = -1;
return 1;
}
if (lru_p)
return close_pack_fd(lru_p);
return 0;
}
@@ -898,12 +922,7 @@ void free_pack_by_name(const char *pack_name)
p = *pp;
if (strcmp(pack_name, p->pack_name) == 0) {
clear_delta_base_cache();
close_pack_windows(p);
if (p->pack_fd != -1) {
close(p->pack_fd);
pack_open_fds--;
}
close_pack_index(p);
close_pack(p);
free(p->bad_object_sha1);
*pp = p->next;
if (last_found_pack == p)
@@ -1037,11 +1056,7 @@ static int open_packed_git(struct packed_git *p)
{
if (!open_packed_git_1(p))
return 0;
if (p->pack_fd != -1) {
close(p->pack_fd);
pack_open_fds--;
p->pack_fd = -1;
}
close_pack_fd(p);
return -1;
}
@@ -1107,11 +1122,8 @@ unsigned char *use_pack(struct packed_git *p,
p->pack_name,
strerror(errno));
if (!win->offset && win->len == p->pack_size
&& !p->do_not_close) {
close(p->pack_fd);
pack_open_fds--;
p->pack_fd = -1;
}
&& !p->do_not_close)
close_pack_fd(p);
pack_mmap_calls++;
pack_open_windows++;
if (pack_mapped > peak_pack_mapped)