summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2015-10-06 13:18:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-10-07 17:47:10 (GMT)
commit38849a8116e690071c02eba0a8ef60a031a58080 (patch)
tree698f68b05e4eab803a511ddb47182c2a2d8361cd /sha1_file.c
parent71fe5d7fb03c0db6edcae39a0312bae2c014a818 (diff)
downloadgit-38849a8116e690071c02eba0a8ef60a031a58080.zip
git-38849a8116e690071c02eba0a8ef60a031a58080.tar.gz
git-38849a8116e690071c02eba0a8ef60a031a58080.tar.bz2
sha1_file.c: 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 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>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 18922b4..d215e0c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)