@@ -485,6 +485,19 @@ static char *packed_set_peeling_mode(
485485 return data ;
486486}
487487
488+ static void packed_map_free (refdb_fs_backend * backend )
489+ {
490+ if (backend -> packed_refs_map .data ) {
491+ #ifdef GIT_WIN32
492+ git__free (backend -> packed_refs_map .data );
493+ #else
494+ git_futils_mmap_free (& backend -> packed_refs_map );
495+ #endif
496+ backend -> packed_refs_map .data = NULL ;
497+ backend -> packed_refs_map .len = 0 ;
498+ }
499+ }
500+
488501static int packed_map_check (refdb_fs_backend * backend )
489502{
490503 int error = 0 ;
@@ -522,7 +535,23 @@ static int packed_map_check(refdb_fs_backend *backend)
522535 return 0 ;
523536 }
524537
538+ #ifdef GIT_WIN32
539+ /* on windows, we copy the entire file into memory rather than using
540+ * mmap() because using mmap() on windows also locks the file and this
541+ * map is long-lived. */
542+ backend -> packed_refs_map .len = (size_t )st .st_size ;
543+ backend -> packed_refs_map .data =
544+ git__malloc (backend -> packed_refs_map .len );
545+ GIT_ERROR_CHECK_ALLOC (backend -> packed_refs_map .data );
546+ {
547+ ssize_t bytesread =
548+ p_read (fd , backend -> packed_refs_map .data ,
549+ backend -> packed_refs_map .len );
550+ error = (bytesread == (ssize_t )backend -> packed_refs_map .len ) ? 0 : -1 ;
551+ }
552+ #else
525553 error = git_futils_mmap_ro (& backend -> packed_refs_map , fd , 0 , (size_t )st .st_size );
554+ #endif
526555 p_close (fd );
527556 if (error < 0 ) {
528557 git_mutex_unlock (& backend -> prlock );
@@ -1302,10 +1331,7 @@ static int packed_write(refdb_fs_backend *backend)
13021331 return error ;
13031332 }
13041333
1305- if (backend -> packed_refs_map .data ) {
1306- git_futils_mmap_free (& backend -> packed_refs_map );
1307- backend -> packed_refs_map .data = NULL ;
1308- }
1334+ packed_map_free (backend );
13091335
13101336 git_mutex_unlock (& backend -> prlock );
13111337
@@ -1798,10 +1824,7 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
17981824 git_sortedcache_free (backend -> refcache );
17991825
18001826 git_mutex_lock (& backend -> prlock );
1801- if (backend -> packed_refs_map .data ) {
1802- git_futils_mmap_free (& backend -> packed_refs_map );
1803- backend -> packed_refs_map .data = NULL ;
1804- }
1827+ packed_map_free (backend );
18051828 git_mutex_unlock (& backend -> prlock );
18061829 git_mutex_free (& backend -> prlock );
18071830
0 commit comments