Skip to content

Commit

Permalink
pack-objects (mingw): initialize packing_data mutex in the correct …
Browse files Browse the repository at this point in the history
…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 git-for-windows#1839.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and jamill committed Oct 15, 2018
1 parent eb6d101 commit 8979693
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,6 @@ static void init_threaded_search(void)
pthread_mutex_init(&cache_mutex, NULL);
pthread_mutex_init(&progress_mutex, NULL);
pthread_cond_init(&progress_cond, NULL);
pthread_mutex_init(&to_pack.lock, NULL);
old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
}

Expand Down
3 changes: 3 additions & 0 deletions pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ void prepare_packing_data(struct packing_data *pdata)
1U << OE_SIZE_BITS);
pdata->oe_delta_size_limit = git_env_ulong("GIT_TEST_OE_DELTA_SIZE",
1UL << OE_DELTA_SIZE_BITS);
#ifndef NO_PTHREADS
pthread_mutex_init(&pdata->lock, NULL);
#endif
}

struct object_entry *packlist_alloc(struct packing_data *pdata,
Expand Down
2 changes: 1 addition & 1 deletion t/t5321-pack-large-objects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test_expect_success 'setup' '
git index-pack --stdin <ab.pack
'

test_expect_failure 'repack large deltas' '
test_expect_success 'repack large deltas' '
printf "%s\\n" $A $B |
GIT_TEST_OE_DELTA_SIZE=2 git pack-objects tmp-pack
'
Expand Down

0 comments on commit 8979693

Please sign in to comment.