Merge branch 'dt/unpack-save-untracked-cache-extension'
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 May 2017 02:16:45 +0000 (11:16 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 May 2017 02:16:45 +0000 (11:16 +0900)
When "git checkout", "git merge", etc. manipulates the in-core
index, various pieces of information in the index extensions are
discarded from the original state, as it is usually not the case
that they are kept up-to-date and in-sync with the operation on the
main index. The untracked cache extension is copied across these
operations now, which would speed up "git status" (as long as the
cache is properly invalidated).

* dt/unpack-save-untracked-cache-extension:
unpack-trees: preserve index extensions

cache.h
read-cache.c
t/t7063-status-untracked-cache.sh
unpack-trees.c
diff --git a/cache.h b/cache.h
index d1f2c5c08886643f0231945ca27f4d79026a3491..ae4c45d379d5b91941616c967a619ae643fe6921 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -597,6 +597,7 @@ extern int read_index_unmerged(struct index_state *);
 #define CLOSE_LOCK             (1 << 1)
 extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
 extern int discard_index(struct index_state *);
+extern void move_index_extensions(struct index_state *dst, struct index_state *src);
 extern int unmerged_index(const struct index_state *);
 extern int verify_path(const char *path);
 extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
index 22ab8b5b61636cbc3bf8bcaf5a2ef964bf69c4c3..92eb15c0004d2a286281fdfb2a489aa45f446288 100644 (file)
@@ -2625,3 +2625,9 @@ void stat_validity_update(struct stat_validity *sv, int fd)
                fill_stat_data(sv->sd, &st);
        }
 }
+
+void move_index_extensions(struct index_state *dst, struct index_state *src)
+{
+       dst->untracked = src->untracked;
+       src->untracked = NULL;
+}
index 0667bd9dd3e8bc650bc4e47ac9fcde5d63ef0d11..e5fb892f9575fda4baf0b2a0e6b31cf13a0d6c0b 100755 (executable)
@@ -661,4 +661,26 @@ test_expect_success 'test ident field is working' '
        test_i18ncmp ../expect ../err
 '
 
+test_expect_success 'untracked cache survives a checkout' '
+       git commit --allow-empty -m empty &&
+       test-dump-untracked-cache >../before &&
+       test_when_finished  "git checkout master" &&
+       git checkout -b other_branch &&
+       test-dump-untracked-cache >../after &&
+       test_cmp ../before ../after &&
+       test_commit test &&
+       test-dump-untracked-cache >../before &&
+       git checkout master &&
+       test-dump-untracked-cache >../after &&
+       test_cmp ../before ../after
+'
+
+test_expect_success 'untracked cache survives a commit' '
+       test-dump-untracked-cache >../before &&
+       git add done/two &&
+       git commit -m commit &&
+       test-dump-untracked-cache >../after &&
+       test_cmp ../before ../after
+'
+
 test_done
index c312c2cd3affa49b17fad336dce6be89fcc954ba..d38c37e38cf183cf878a9f35b19544d1da0bc438 100644 (file)
@@ -1396,6 +1396,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                                                  WRITE_TREE_SILENT |
                                                  WRITE_TREE_REPAIR);
                }
+               move_index_extensions(&o->result, o->dst_index);
                discard_index(o->dst_index);
                *o->dst_index = o->result;
        } else {