Skip to content

Commit 38849a8

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71fe5d7 commit 38849a8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ extern void close_pack_index(struct packed_git *);
12311231

12321232
extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
12331233
extern void close_pack_windows(struct packed_git *);
1234+
extern void close_all_packs(void);
12341235
extern void unuse_pack(struct pack_window **);
12351236
extern void free_pack_by_name(const char *);
12361237
extern void clear_delta_base_cache(void);

sha1_file.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,25 @@ static int close_pack_fd(struct packed_git *p)
765765
return 1;
766766
}
767767

768+
static void close_pack(struct packed_git *p)
769+
{
770+
close_pack_windows(p);
771+
close_pack_fd(p);
772+
close_pack_index(p);
773+
}
774+
775+
void close_all_packs(void)
776+
{
777+
struct packed_git *p;
778+
779+
for (p = packed_git; p; p = p->next)
780+
if (p->do_not_close)
781+
die("BUG! Want to close pack marked 'do-not-close'");
782+
else
783+
close_pack(p);
784+
}
785+
786+
768787
/*
769788
* The LRU pack is the one with the oldest MRU window, preferring packs
770789
* 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)
873892
p = *pp;
874893
if (strcmp(pack_name, p->pack_name) == 0) {
875894
clear_delta_base_cache();
876-
close_pack_windows(p);
877-
close_pack_fd(p);
878-
close_pack_index(p);
895+
close_pack(p);
879896
free(p->bad_object_sha1);
880897
*pp = p->next;
881898
if (last_found_pack == p)

0 commit comments

Comments
 (0)