indexer: introduce `git_packfile_close` Encapsulation!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/src/indexer.c b/src/indexer.c
index 05a02f6..805c36e 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -1091,17 +1091,10 @@ void git_indexer_free(git_indexer *idx)
git_vector_free_deep(&idx->deltas);
- /* Try to delete the temporary file in case it was not committed. */
- git_mwindow_free_all(&idx->pack->mwf);
-
- /* We need to close the descriptor here so Windows doesn't choke on unlink */
- if (idx->pack->mwf.fd != -1)
- p_close(idx->pack->mwf.fd);
-
- if (!idx->pack_committed)
- p_unlink(idx->pack->pack_name);
-
if (!git_mutex_lock(&git__mwindow_mutex)) {
+ if (!idx->pack_committed)
+ git_packfile_close(idx->pack, true);
+
git_packfile_free(idx->pack);
git_mutex_unlock(&git__mwindow_mutex);
}
diff --git a/src/pack.c b/src/pack.c
index 345ff52..243719d 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -991,6 +991,18 @@ git_off_t get_delta_base(
*
***********************************************************/
+void git_packfile_close(struct git_pack_file *p, bool unlink_packfile)
+{
+ if (p->mwf.fd >= 0) {
+ git_mwindow_free_all_locked(&p->mwf);
+ p_close(p->mwf.fd);
+ p->mwf.fd = -1;
+ }
+
+ if (unlink_packfile)
+ p_unlink(p->pack_name);
+}
+
void git_packfile_free(struct git_pack_file *p)
{
if (!p)
@@ -998,10 +1010,7 @@ void git_packfile_free(struct git_pack_file *p)
cache_free(&p->bases);
- if (p->mwf.fd >= 0) {
- git_mwindow_free_all_locked(&p->mwf);
- p_close(p->mwf.fd);
- }
+ git_packfile_close(p, false);
pack_index_free(p);
diff --git a/src/pack.h b/src/pack.h
index 5302db5..e2bf165 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -149,6 +149,7 @@ git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
git_off_t *curpos, git_otype type,
git_off_t delta_obj_offset);
+void git_packfile_close(struct git_pack_file *p, bool unlink_packfile);
void git_packfile_free(struct git_pack_file *p);
int git_packfile_alloc(struct git_pack_file **pack_out, const char *path);