sha1_file.c: add a function to release all packs
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Tue, 6 Oct 2015 13:18:34 +0000 (15:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Oct 2015 17:47:10 +0000 (10:47 -0700)
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 all the
pack files and their idx files.

While at it, we consolidate the close windows/close fd/close index
stanza in `free_pack_by_name()` into the `close_pack()` function that
is used by the new `close_all_packs()` function to avoid repeated code.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
sha1_file.c
diff --git a/cache.h b/cache.h
index 4427945bc08be2d182b123ce5f684d23304582d9..c3a2bb8afff32b029d429b052b1c901dc4776811 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1231,6 +1231,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);
index 18922b435ebd82f95b495a40b76c4ceb15416dc0..d215e0c9bf0fdf0a7a28233ddccd87ba0c51fd68 100644 (file)
@@ -765,6 +765,25 @@ 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)
+               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.
@@ -873,9 +892,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);
-                       close_pack_fd(p);
-                       close_pack_index(p);
+                       close_pack(p);
                        free(p->bad_object_sha1);
                        *pp = p->next;
                        if (last_found_pack == p)