Skip to content

Commit 475a344

Browse files
dturner-twgitster
authored andcommitted
commit: don't rewrite shared index unnecessarily
Remove a cache invalidation which would cause the shared index to be rewritten on as-is commits. When the cache-tree has changed, we need to update it. But we don't necessarily need to update the shared index. So setting active_cache_changed to SOMETHING_CHANGED is unnecessary. Instead, we let update_main_cache_tree just update the CACHE_TREE_CHANGED bit. In order to test this, make test-dump-split-index not segfault on missing replace_bitmap/delete_bitmap. This new codepath is not called now that the test passes, but is necessary to avoid a segfault when the new test is run with the old builtin/commit.c code. Signed-off-by: David Turner <[email protected]> Acked-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 52f6893 commit 475a344

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

builtin/commit.c

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

t/t0090-cache-tree.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,14 @@ test_expect_success 'no phantom error when switching trees' '
218218
! test -s errors
219219
'
220220

221+
test_expect_success 'switching trees does not invalidate shared index' '
222+
git update-index --split-index &&
223+
>split &&
224+
git add split &&
225+
test-dump-split-index .git/index | grep -v ^own >before &&
226+
git commit -m "as-is" &&
227+
test-dump-split-index .git/index | grep -v ^own >after &&
228+
test_cmp before after
229+
'
230+
221231
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)