commit: don't rewrite shared index unnecessarily
authorDavid Turner <dturner@twopensource.com>
Thu, 27 Aug 2015 17:07:54 +0000 (13:07 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 15:41:07 +0000 (08:41 -0700)
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>
builtin/commit.c
t/t0090-cache-tree.sh
test-dump-split-index.c

index 254477f..1692620 100644 (file)
@@ -404,10 +404,8 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
                hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
                if (active_cache_changed
-                   || !cache_tree_fully_valid(active_cache_tree)) {
+                   || !cache_tree_fully_valid(active_cache_tree))
                        update_main_cache_tree(WRITE_TREE_SILENT);
-                       active_cache_changed = 1;
-               }
                if (active_cache_changed) {
                        if (write_locked_index(&the_index, &index_lock,
                                               COMMIT_LOCK))
index 601d02d..f92dd1f 100755 (executable)
@@ -218,4 +218,14 @@ test_expect_success 'no phantom error when switching trees' '
        ! test -s errors
 '
 
+test_expect_success 'switching trees does not invalidate shared index' '
+       git update-index --split-index &&
+       >split &&
+       git add split &&
+       test-dump-split-index .git/index | grep -v ^own >before &&
+       git commit -m "as-is" &&
+       test-dump-split-index .git/index | grep -v ^own >after &&
+       test_cmp before after
+'
+
 test_done
index 9cf3112..861d28c 100644 (file)
@@ -26,9 +26,11 @@ int main(int ac, char **av)
                       sha1_to_hex(ce->sha1), ce_stage(ce), ce->name);
        }
        printf("replacements:");
-       ewah_each_bit(si->replace_bitmap, show_bit, NULL);
+       if (si->replace_bitmap)
+               ewah_each_bit(si->replace_bitmap, show_bit, NULL);
        printf("\ndeletions:");
-       ewah_each_bit(si->delete_bitmap, show_bit, NULL);
+       if (si->delete_bitmap)
+               ewah_each_bit(si->delete_bitmap, show_bit, NULL);
        printf("\n");
        return 0;
 }