Skip to content

Commit 81d0e33

Browse files
committed
Merge branch 'dt/commit-preserve-base-index-upon-opportunistic-cache-tree-update'
When re-priming the cache-tree opportunistically while committing the in-core index as-is, we mistakenly invalidated the in-core index too aggressively, causing the experimental split-index code to unnecessarily rewrite the on-disk index file(s). * dt/commit-preserve-base-index-upon-opportunistic-cache-tree-update: commit: don't rewrite shared index unnecessarily
2 parents 0fb8e24 + 475a344 commit 81d0e33

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

builtin/commit.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,8 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
405405
hold_locked_index(&index_lock, 1);
406406
refresh_cache_or_die(refresh_flags);
407407
if (active_cache_changed
408-
|| !cache_tree_fully_valid(active_cache_tree)) {
408+
|| !cache_tree_fully_valid(active_cache_tree))
409409
update_main_cache_tree(WRITE_TREE_SILENT);
410-
active_cache_changed = 1;
411-
}
412410
if (active_cache_changed) {
413411
if (write_locked_index(&the_index, &index_lock,
414412
COMMIT_LOCK))

t/t0090-cache-tree.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,14 @@ test_expect_success 'no phantom error when switching trees' '
242242
! test -s errors
243243
'
244244

245+
test_expect_success 'switching trees does not invalidate shared index' '
246+
git update-index --split-index &&
247+
>split &&
248+
git add split &&
249+
test-dump-split-index .git/index | grep -v ^own >before &&
250+
git commit -m "as-is" &&
251+
test-dump-split-index .git/index | grep -v ^own >after &&
252+
test_cmp before after
253+
'
254+
245255
test_done

test-dump-split-index.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ int main(int ac, char **av)
2626
sha1_to_hex(ce->sha1), ce_stage(ce), ce->name);
2727
}
2828
printf("replacements:");
29-
ewah_each_bit(si->replace_bitmap, show_bit, NULL);
29+
if (si->replace_bitmap)
30+
ewah_each_bit(si->replace_bitmap, show_bit, NULL);
3031
printf("\ndeletions:");
31-
ewah_each_bit(si->delete_bitmap, show_bit, NULL);
32+
if (si->delete_bitmap)
33+
ewah_each_bit(si->delete_bitmap, show_bit, NULL);
3234
printf("\n");
3335
return 0;
3436
}

0 commit comments

Comments
 (0)