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

[PATCH 12/24] untracked cache: invalidate at index addition or removal

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 20, 2015, 13:03 UTC
Message-ID
<1421759013-8494-13-git-send-email-pclouds@gmail.com>
In-Reply-To
<1421759013-8494-1-git-send-email-pclouds@gmail.com>

Ideally we should implement untracked_cache_remove_from_index() and untracked_cache_add_to_index() so that they update untracked cache right away instead of invalidating it and wait for read_directory() next time to deal with it. But that may need some more work in unpack-trees.c. So stay simple as the first step.

The new call in add_index_entry_with_check() may look strange because new calls usually stay close to cache_tree_invalidate_path(). We do it a bit later than c_t_i_p() in this function because if it's about replacing the entry with the same name, we don't care (but cache-tree does).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 dir.c          | 31 +++++++++++++++++++++++++++++++
 dir.h          |  4 ++++
 read-cache.c   |  4 ++++
 unpack-trees.c |  7 +++++--
 4 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/dir.c b/dir.c
index e7d7df3..30e23f8 100644
--- a/dir.c
+++ b/dir.c
@@ -2495,3 +2495,34 @@ done2:
 	}
 	return uc;
 }
+
+void untracked_cache_invalidate_path(struct index_state *istate,
+				     const char *path)
+{
+	const char *sep;
+	struct untracked_cache_dir *d;
+	if (!istate->untracked || !istate->untracked->root)
+		return;
+	sep = strrchr(path, '/');
+	if (sep)
+		d = lookup_untracked(istate->untracked,
+				     istate->untracked->root,
+				     path, sep - path);
+	else
+		d = istate->untracked->root;
+	istate->untracked->dir_invalidated++;
+	d->valid = 0;
+	d->untracked_nr = 0;
+}
+
+void untracked_cache_remove_from_index(struct index_state *istate,
+				       const char *path)
+{
+	untracked_cache_invalidate_path(istate, path);
+}
+
+void untracked_cache_add_to_index(struct index_state *istate,
+				  const char *path)
+{
+	untracked_cache_invalidate_path(istate, path);
+}
diff --git a/dir.h b/dir.h
index 40a679a..2ce7dd3 100644
--- a/dir.h
+++ b/dir.h
@@ -298,6 +298,10 @@ static inline int dir_path_match(const struct dir_entry *ent,
 			      has_trailing_dir);
 }
 
+void untracked_cache_invalidate_path(struct index_state *, const char *);
+void untracked_cache_remove_from_index(struct index_state *, const char *);
+void untracked_cache_add_to_index(struct index_state *, const char *);
+
 void free_untracked_cache(struct untracked_cache *);
 struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
 void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
diff --git a/read-cache.c b/read-cache.c
index 3736a56..d643a3f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -78,6 +78,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
 	memcpy(new->name, new_name, namelen + 1);
 
 	cache_tree_invalidate_path(istate, old->name);
+	untracked_cache_remove_from_index(istate, old->name);
 	remove_index_entry_at(istate, nr);
 	add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 }
@@ -537,6 +538,7 @@ int remove_file_from_index(struct index_state *istate, const char *path)
 	if (pos < 0)
 		pos = -pos-1;
 	cache_tree_invalidate_path(istate, path);
+	untracked_cache_remove_from_index(istate, path);
 	while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path))
 		remove_index_entry_at(istate, pos);
 	return 0;
@@ -968,6 +970,8 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
 	}
 	pos = -pos-1;
 
+	untracked_cache_add_to_index(istate, ce->name);
+
 	/*
 	 * Inserting a merged entry ("stage 0") into the index
 	 * will always replace all non-merged entries..
diff --git a/unpack-trees.c b/unpack-trees.c
index 629c658..e5ddb0c 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -9,6 +9,7 @@
 #include "refs.h"
 #include "attr.h"
 #include "split-index.h"
+#include "dir.h"
 
 /*
  * Error messages expected by scripts out of plumbing commands such as
@@ -1255,8 +1256,10 @@ static int verify_uptodate_sparse(const struct cache_entry *ce,
 static void invalidate_ce_path(const struct cache_entry *ce,
 			       struct unpack_trees_options *o)
 {
-	if (ce)
-		cache_tree_invalidate_path(o->src_index, ce->name);
+	if (!ce)
+		return;
+	cache_tree_invalidate_path(o->src_index, ce->name);
+	untracked_cache_invalidate_path(o->src_index, ce->name);
 }
 
 /*
-- 
2.2.0.84.ge9c7a8a
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 13 of 34 in “nd/untracked-cache update”
  1. 00/24 nd/untracked-cache updateNguyễn Thái Ngọc Duy, Jan 20, 2015
  2. 01/24 dir.c: optionally compute sha-1 of a .gitignore fileNguyễn Thái Ngọc Duy, Jan 20, 2015
  3. 02/24 untracked cache: record .gitignore information and dir hierarchyNguyễn Thái Ngọc Duy, Jan 20, 2015
  4. 03/24 untracked cache: initial untracked cache validationNguyễn Thái Ngọc Duy, Jan 20, 2015
  5. 04/24 untracked cache: invalidate dirs recursively if .gitignore changesNguyễn Thái Ngọc Duy, Jan 20, 2015
  6. 05/24 untracked cache: make a wrapper around {open,read,close}dir()Nguyễn Thái Ngọc Duy, Jan 20, 2015
  7. 06/24 untracked cache: record/validate dir mtime and reuse cached outputNguyễn Thái Ngọc Duy, Jan 20, 2015
  8. 07/24 untracked cache: mark what dirs should be recursed/savedNguyễn Thái Ngọc Duy, Jan 20, 2015
  9. 08/24 untracked cache: don't open non-existent .gitignoreNguyễn Thái Ngọc Duy, Jan 20, 2015
  10. 09/24 ewah: add convenient wrapper ewah_serialize_strbuf()Nguyễn Thái Ngọc Duy, Jan 20, 2015
  11. 10/24 untracked cache: save to an index extensionNguyễn Thái Ngọc Duy, Jan 20, 2015
  12. 11/24 untracked cache: load from UNTR index extensionNguyễn Thái Ngọc Duy, Jan 20, 2015
  13. 12/24 untracked cache: invalidate at index addition or removalNguyễn Thái Ngọc Duy, Jan 20, 2015
  14. 13/24 read-cache.c: split racy stat test to a separate functionNguyễn Thái Ngọc Duy, Jan 20, 2015
  15. 14/24 untracked cache: avoid racy timestampsNguyễn Thái Ngọc Duy, Jan 20, 2015
  16. 15/24 untracked cache: print stats with $GIT_TRACE_UNTRACKED_STATSNguyễn Thái Ngọc Duy, Jan 20, 2015
  17. 16/24 untracked cache: mark index dirty if untracked cache is updatedNguyễn Thái Ngọc Duy, Jan 20, 2015
  18. 17/24 untracked-cache: temporarily disable with $GIT_DISABLE_UNTRACKED_CACHENguyễn Thái Ngọc Duy, Jan 20, 2015
  19. 18/24 status: enable untracked cacheNguyễn Thái Ngọc Duy, Jan 20, 2015
  20. 19/24 update-index: manually enable or disable untracked cacheNguyễn Thái Ngọc Duy, Jan 20, 2015
  21. 20/24 update-index: test the system before enabling untracked cacheNguyễn Thái Ngọc Duy, Jan 20, 2015
  22. Junio C HamanoJan 21, 2015
  23. Duy NguyenJan 21, 2015
  24. Junio C HamanoJan 21, 2015
  25. Duy NguyenJan 22, 2015
  26. Junio C HamanoJan 22, 2015
  27. Duy NguyenJan 24, 2015
  28. 21/24 t7063: tests for untracked cacheNguyễn Thái Ngọc Duy, Jan 20, 2015
  29. 22/24 mingw32: add uname()Nguyễn Thái Ngọc Duy, Jan 20, 2015
  30. 23/24 untracked cache: guard and disable on system changesNguyễn Thái Ngọc Duy, Jan 20, 2015
  31. 24/24 git-status.txt: advertisement for untracked cacheNguyễn Thái Ngọc Duy, Jan 20, 2015
  32. brian m. carlsonJan 22, 2015
  33. Torsten BögershausenJan 20, 2015
  34. Duy NguyenJan 21, 2015

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.