Skip to content

Commit 0efa3d7

Browse files
committed
Merge branch 'nd/split-index-null-base-fix'
Split-index fix. * nd/split-index-null-base-fix: read-cache.c: fix writing "link" index ext with null base oid
2 parents ebf846c + 6e37c8e commit 0efa3d7

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

read-cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
29002900
return -1;
29012901
}
29022902

2903-
if (!strip_extensions && istate->split_index) {
2903+
if (!strip_extensions && istate->split_index &&
2904+
!is_null_oid(&istate->split_index->base_oid)) {
29042905
struct strbuf sb = STRBUF_INIT;
29052906

29062907
err = write_link_extension(&sb, istate) < 0 ||
@@ -3195,7 +3196,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
31953196
ret = write_split_index(istate, lock, flags);
31963197

31973198
/* Freshen the shared index only if the split-index was written */
3198-
if (!ret && !new_shared_index) {
3199+
if (!ret && !new_shared_index && !is_null_oid(&si->base_oid)) {
31993200
const char *shared_index = git_path("sharedindex.%s",
32003201
oid_to_hex(&si->base_oid));
32013202
freshen_shared_index(shared_index, 1);

split-index.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -440,24 +440,26 @@ void add_split_index(struct index_state *istate)
440440
void remove_split_index(struct index_state *istate)
441441
{
442442
if (istate->split_index) {
443-
/*
444-
* When removing the split index, we need to move
445-
* ownership of the mem_pool associated with the
446-
* base index to the main index. There may be cache entries
447-
* allocated from the base's memory pool that are shared with
448-
* the_index.cache[].
449-
*/
450-
mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
443+
if (istate->split_index->base) {
444+
/*
445+
* When removing the split index, we need to move
446+
* ownership of the mem_pool associated with the
447+
* base index to the main index. There may be cache entries
448+
* allocated from the base's memory pool that are shared with
449+
* the_index.cache[].
450+
*/
451+
mem_pool_combine(istate->ce_mem_pool,
452+
istate->split_index->base->ce_mem_pool);
451453

452-
/*
453-
* The split index no longer owns the mem_pool backing
454-
* its cache array. As we are discarding this index,
455-
* mark the index as having no cache entries, so it
456-
* will not attempt to clean up the cache entries or
457-
* validate them.
458-
*/
459-
if (istate->split_index->base)
454+
/*
455+
* The split index no longer owns the mem_pool backing
456+
* its cache array. As we are discarding this index,
457+
* mark the index as having no cache entries, so it
458+
* will not attempt to clean up the cache entries or
459+
* validate them.
460+
*/
460461
istate->split_index->base->cache_nr = 0;
462+
}
461463

462464
/*
463465
* We can discard the split index because its

t/t1700-split-index.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,22 @@ test_expect_success 'writing split index with null sha1 does not write cache tre
472472
test_line_count = 0 cache-tree.out
473473
'
474474

475+
test_expect_success 'do not refresh null base index' '
476+
test_create_repo merge &&
477+
(
478+
cd merge &&
479+
test_commit initial &&
480+
git checkout -b side-branch &&
481+
test_commit extra &&
482+
git checkout master &&
483+
git update-index --split-index &&
484+
test_commit more &&
485+
# must not write a new shareindex, or we wont catch the problem
486+
git -c splitIndex.maxPercentChange=100 merge --no-edit side-branch 2>err &&
487+
# i.e. do not expect warnings like
488+
# could not freshen shared index .../shareindex.00000...
489+
test_must_be_empty err
490+
)
491+
'
492+
475493
test_done

0 commit comments

Comments
 (0)