Skip to content

Commit da7f9fe

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#3879 from libgit2/ethomson/mwindow_init
mwindow: init mwindow files in git_libgit2_init
2 parents baa87df + 2381d9e commit da7f9fe

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

src/global.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ static int init_common(void)
6161
(ret = git_sysdir_global_init()) == 0 &&
6262
(ret = git_filter_global_init()) == 0 &&
6363
(ret = git_merge_driver_global_init()) == 0 &&
64-
(ret = git_transport_ssh_global_init()) == 0)
65-
ret = git_openssl_stream_global_init();
64+
(ret = git_transport_ssh_global_init()) == 0 &&
65+
(ret = git_openssl_stream_global_init()) == 0)
66+
ret = git_mwindow_global_init();
6667

6768
GIT_MEMORY_BARRIER;
6869

src/mwindow.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,20 @@ static git_mwindow_ctl mem_ctl;
3333
/* Global list of mwindow files, to open packs once across repos */
3434
git_strmap *git__pack_cache = NULL;
3535

36-
/**
37-
* Run under mwindow lock
38-
*/
39-
int git_mwindow_files_init(void)
36+
static void git_mwindow_files_free(void)
4037
{
41-
if (git__pack_cache)
42-
return 0;
43-
44-
git__on_shutdown(git_mwindow_files_free);
38+
git_strmap *tmp = git__pack_cache;
4539

46-
return git_strmap_alloc(&git__pack_cache);
40+
git__pack_cache = NULL;
41+
git_strmap_free(tmp);
4742
}
4843

49-
void git_mwindow_files_free(void)
44+
int git_mwindow_global_init(void)
5045
{
51-
git_strmap *tmp = git__pack_cache;
46+
assert(!git__pack_cache);
5247

53-
git__pack_cache = NULL;
54-
git_strmap_free(tmp);
48+
git__on_shutdown(git_mwindow_files_free);
49+
return git_strmap_alloc(&git__pack_cache);
5550
}
5651

5752
int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
@@ -69,12 +64,6 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
6964
return -1;
7065
}
7166

72-
if (git_mwindow_files_init() < 0) {
73-
git_mutex_unlock(&git__mwindow_mutex);
74-
git__free(packname);
75-
return -1;
76-
}
77-
7867
pos = git_strmap_lookup_index(git__pack_cache, packname);
7968
git__free(packname);
8069

src/mwindow.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf);
4343
void git_mwindow_file_deregister(git_mwindow_file *mwf);
4444
void git_mwindow_close(git_mwindow **w_cursor);
4545

46-
int git_mwindow_files_init(void);
47-
void git_mwindow_files_free(void);
46+
extern int git_mwindow_global_init(void);
4847

4948
struct git_pack_file; /* just declaration to avoid cyclical includes */
5049
int git_mwindow_get_pack(struct git_pack_file **out, const char *path);

src/odb_pack.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,6 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
591591
struct pack_backend *backend = NULL;
592592
git_buf path = GIT_BUF_INIT;
593593

594-
if (git_mwindow_files_init() < 0)
595-
return -1;
596-
597594
if (pack_backend__alloc(&backend, 8) < 0)
598595
return -1;
599596

0 commit comments

Comments
 (0)