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 <dturner@twopensource.com> Acked-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed Aug 27, 2015 at 13:07 UTC 475a34451f86d1b954c5da37f04ed044544cf6e4
3 files changed +15 -5
builtin/commit.c
+1 -3
@@ -404,10 +404,8 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
404 hold_locked_index(&index_lock, 1);
405 refresh_cache_or_die(refresh_flags);
406 if (active_cache_changed
407 - || !cache_tree_fully_valid(active_cache_tree)) {
407 + || !cache_tree_fully_valid(active_cache_tree))
408 update_main_cache_tree(WRITE_TREE_SILENT);
409 - active_cache_changed = 1;
410 - }
409 if (active_cache_changed) {
410 if (write_locked_index(&the_index, &index_lock,
411 COMMIT_LOCK))
t/t0090-cache-tree.sh
+10
@@ -218,4 +218,14 @@ test_expect_success 'no phantom error when switching trees' '
218 ! test -s errors
219 '
220
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 +
231 test_done
test-dump-split-index.c
+4 -2
@@ -26,9 +26,11 @@ int main(int ac, char **av)
26 sha1_to_hex(ce->sha1), ce_stage(ce), ce->name);
27 }
28 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);
31 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);
34 printf("\n");
35 return 0;
36 }