From 2136f53b9ea2e37069d3ca1104f34f53dd824b41 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 5 Oct 2015 21:09:39 +0200 Subject: [PATCH] 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 --- cache.h | 1 + sha1_file.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cache.h b/cache.h index 79066e57dc..5a9813b771 100644 --- a/cache.h +++ b/cache.h @@ -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); diff --git a/sha1_file.c b/sha1_file.c index 5d75a327bd..fe823fec3f 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -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.