unpack-trees: preserve index extensions
authorDavid Turner <dturner@twopensource.com>
Mon, 8 May 2017 09:41:42 +0000 (11:41 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 May 2017 09:26:45 +0000 (18:26 +0900)
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>
cache.h
read-cache.c
t/t7063-status-untracked-cache.sh
unpack-trees.c
diff --git a/cache.h b/cache.h
index e1f0e182ad011d5a3b6912f48b597dcc6d1070b0..d41336dfd5de9f8fa1486e3d7e41fead87808d6f 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 0d0081a11b858227d3f55ebbc21f04bd49875f68..79827a4d71091cf6493a0ed4740cec94c4814b38 100644 (file)
@@ -2628,3 +2628,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 aa15111fefc8ca333edeeeb3ac77a8b946e4c6a5..17117bd0fda83fb2c5fc89082a1d5a72f1049fb8 100644 (file)
@@ -1391,6 +1391,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 {