Skip to content

Commit 843931b

Browse files
committed
pack-objects (mingw): initialize packing_data mutex in the correct spot
In 9ac3f0e (pack-objects: fix performance issues on packing large deltas, 2018-07-22), a mutex was introduced that is used to guard the call to set the delta size. This commit even added code to initialize it, but at an incorrect spot: in `init_threaded_search()`, while the call to `oe_set_delta_size()` (and hence to `packing_data_lock()`) can happen in the call chain `check_object()` <- `get_object_details()` <- `prepare_pack()` <- `cmd_pack_objects()`, which is long before the `prepare_pack()` function calls `ll_find_deltas()` (which initializes the threaded search). Another tell-tale that the mutex was initialized in an incorrect spot is that the function to initialize it lives in builtin/, while the code that uses the mutex is defined in a libgit.a header file. Let's use a more appropriate function: `prepare_packing_data()`, which not only lives in libgit.a, but *has* to be called before the `packing_data` struct is used that contains that mutex. This fixes #1839. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a20f413 commit 843931b

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

builtin/pack-objects.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,6 @@ static void init_threaded_search(void)
22992299
pthread_mutex_init(&cache_mutex, NULL);
23002300
pthread_mutex_init(&progress_mutex, NULL);
23012301
pthread_cond_init(&progress_cond, NULL);
2302-
pthread_mutex_init(&to_pack.lock, NULL);
23032302
old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
23042303
}
23052304

pack-objects.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ void prepare_packing_data(struct packing_data *pdata)
148148
1U << OE_SIZE_BITS);
149149
pdata->oe_delta_size_limit = git_env_ulong("GIT_TEST_OE_DELTA_SIZE",
150150
1UL << OE_DELTA_SIZE_BITS);
151+
#ifndef NO_PTHREADS
152+
pthread_mutex_init(&pdata->lock, NULL);
153+
#endif
151154
}
152155

153156
struct object_entry *packlist_alloc(struct packing_data *pdata,

t/t5319-pack-large-objects.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test_expect_success 'setup' '
2424
git index-pack --stdin <ab.pack
2525
'
2626

27-
test_expect_failure 'repack large deltas' '
27+
test_expect_success 'repack large deltas' '
2828
printf "%s\\n" $A $B |
2929
GIT_TEST_OE_DELTA_SIZE=2 git pack-objects tmp-pack
3030
'

0 commit comments

Comments
 (0)