unpack-trees: preserve index extensions

Make git checkout (and other unpack_tree operations) preserve the untracked cache. This is valuable for two reasons: 1. Often, an unpack_tree operation will not touch large parts of the working tree, and thus most of the untracked cache will continue to be valid. 2. Even if the untracked cache were entirely invalidated by such an operation, the user has signaled their intention to have such a cache, and we don't want to throw it away. [jes: backed out the watchman-specific parts] Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed May 8, 2017 at 11:41 UTC edf3b90553f5c667cd8cb99aa809305470ba3bd7
4 files changed +30
cache.h
+1
@@ -597,6 +597,7 @@ extern int read_index_unmerged(struct index_state *);
597 #define CLOSE_LOCK (1 << 1)
598 extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
599 extern int discard_index(struct index_state *);
600 +extern void move_index_extensions(struct index_state *dst, struct index_state *src);
601 extern int unmerged_index(const struct index_state *);
602 extern int verify_path(const char *path);
603 extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
read-cache.c
+6
@@ -2628,3 +2628,9 @@ void stat_validity_update(struct stat_validity *sv, int fd)
2628 fill_stat_data(sv->sd, &st);
2629 }
2630 }
2631 +
2632 +void move_index_extensions(struct index_state *dst, struct index_state *src)
2633 +{
2634 + dst->untracked = src->untracked;
2635 + src->untracked = NULL;
2636 +}
t/t7063-status-untracked-cache.sh
+22
@@ -661,4 +661,26 @@ test_expect_success 'test ident field is working' '
661 test_i18ncmp ../expect ../err
662 '
663
664 +test_expect_success 'untracked cache survives a checkout' '
665 + git commit --allow-empty -m empty &&
666 + test-dump-untracked-cache >../before &&
667 + test_when_finished "git checkout master" &&
668 + git checkout -b other_branch &&
669 + test-dump-untracked-cache >../after &&
670 + test_cmp ../before ../after &&
671 + test_commit test &&
672 + test-dump-untracked-cache >../before &&
673 + git checkout master &&
674 + test-dump-untracked-cache >../after &&
675 + test_cmp ../before ../after
676 +'
677 +
678 +test_expect_success 'untracked cache survives a commit' '
679 + test-dump-untracked-cache >../before &&
680 + git add done/two &&
681 + git commit -m commit &&
682 + test-dump-untracked-cache >../after &&
683 + test_cmp ../before ../after
684 +'
685 +
686 test_done
unpack-trees.c
+1
@@ -1391,6 +1391,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1391 WRITE_TREE_SILENT |
1392 WRITE_TREE_REPAIR);
1393 }
1394 + move_index_extensions(&o->result, o->dst_index);
1395 discard_index(o->dst_index);
1396 *o->dst_index = o->result;
1397 } else {