git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] unpack-trees: preserve index extensions

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 8, 2017, 09:41 UTC
Message-ID
<52008ec9f5b6c459f596052836cd88addb7167db.1494236457.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1494236457.git.johannes.schindelin@gmx.de>
From: David Turner <dturner@twosigma.com>

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@twosigma.com>
Signed-off-by: Ben Peart <benpeart@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 cache.h                           |  1 +
 read-cache.c                      |  6 ++++++
 t/t7063-status-untracked-cache.sh | 22 ++++++++++++++++++++++
 unpack-trees.c                    |  1 +
 4 files changed, 30 insertions(+)
diff --git a/cache.h b/cache.h
index e1f0e182ad0..d41336dfd5d 100644
--- 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);
diff --git a/read-cache.c b/read-cache.c
index 0d0081a11b8..79827a4d710 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -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;
+}
diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
index 0667bd9dd3e..e5fb892f957 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -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
diff --git a/unpack-trees.c b/unpack-trees.c
index aa15111fefc..17117bd0fda 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -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 {
-- 
2.12.2.windows.2.800.gede8f145e06
Previous: Johannes SchindelinNext: Christian Couder
Message 2 of 8 in “Preserve the untracked cache across checkout, reset --hard, etc”
  1. 0/1 Preserve the untracked cache across checkout, reset --hard, etcJohannes Schindelin, May 8, 2017
  2. 1/1 unpack-trees: preserve index extensionsJohannes Schindelin, May 8, 2017
  3. Christian CouderMay 8, 2017
  4. David TurnerMay 8, 2017
  5. Junio C HamanoMay 9, 2017
  6. Ben PeartMay 9, 2017
  7. Ben PeartMay 18, 2017
  8. David TurnerMay 18, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.