Add a function to release all packs

On Windows, files that are in use cannot be removed or renamed. That
means that we have to release pack files when we are about to, say,
repack them. Let's introduce a convenient function to close them
pack files.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2015-10-05 21:09:39 +02:00
parent f8a0a22fb5
commit 2136f53b9e
2 changed files with 17 additions and 0 deletions

View File

@@ -1275,6 +1275,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

@@ -798,6 +798,22 @@ static int close_pack_fd(struct packed_git *p)
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.