]> git.proxmox.com Git - libgit2.git/commitdiff
indexer: introduce `git_packfile_close`
authorEdward Thomson <ethomson@github.com>
Sat, 21 Jan 2017 19:51:31 +0000 (14:51 -0500)
committerEdward Thomson <ethomson@github.com>
Sat, 21 Jan 2017 20:21:29 +0000 (15:21 -0500)
Encapsulation!

src/indexer.c
src/pack.c
src/pack.h

index 05a02f6469dca9c274ce78b7b44e70bc6e607ea0..805c36ea4b38b8ece0b7d390d42ad6a91e8bf217 100644 (file)
@@ -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);
        }
index 345ff52591715ea4f36805c315cd57ac7637dacd..243719d9c91c31fa78466eb9bee07dc01144a3e4 100644 (file)
@@ -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);
 
index 5302db5b7c9a23e91d475902894b408a9d53c962..e2bf165f48f9c577382e033f1c5106112c012c33 100644 (file)
@@ -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);