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

Re: Efficient way to import snapshots?

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 30, 2007, 21:55 UTC
Message-ID
<7vy7gximkc.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<alpine.LFD.0.999.0707301240330.4161@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
> Junio? I _thought_ we already took the index into account with "git add", 
> but we obviously don't. 

I think 366bfcb6 "broke" it by moving read_cache() call down, because it wanted the directory walking code to grab paths that are already in the index. The change serves its purpose, but introduces this regression now the responsibility of avoiding unnecessary reindexing by matching the cached stat is shifted nowhere.

We would need to do something like this patch, perhaps? This function has three callers, two in builtin-add and another in builtin-mv.

---
 read-cache.c  |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index a363f31..c346d88 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -380,7 +380,7 @@ static int index_name_pos_also_unmerged(struct index_state *istate,
 
 int add_file_to_index(struct index_state *istate, const char *path, int verbose)
 {
-	int size, namelen;
+	int size, namelen, pos;
 	struct stat st;
 	struct cache_entry *ce;
 
@@ -414,6 +414,13 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
 		ce->ce_mode = ce_mode_from_stat(ent, st.st_mode);
 	}
 
+	pos = index_name_pos(istate, ce->name, namelen);
+	if (0 <= pos && !ie_modified(istate, istate->cache[pos], &st, 1)) {
+		/* Nothing changed, really */
+		free(ce);
+		return 0;
+	}
+
 	if (index_path(ce->sha1, path, &st, 1))
 		die("unable to index file %s", path);
 	if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE))
Previous: Linus TorvaldsNext: Linus Torvalds
Message 10 of 27 in “Efficient way to import snapshots?”
  1. Craig BostonJul 30, 2007
  2. Linus TorvaldsJul 30, 2007
  3. Craig BostonJul 30, 2007
  4. Linus TorvaldsJul 30, 2007
  5. Craig BostonJul 30, 2007
  6. Junio C HamanoJul 30, 2007
  7. Craig BostonJul 30, 2007
  8. Junio C HamanoJul 30, 2007
  9. Linus TorvaldsJul 30, 2007
  10. Junio C HamanoJul 30, 2007
  11. Linus TorvaldsJul 30, 2007
  12. Junio C HamanoJul 30, 2007
  13. Linus TorvaldsJul 31, 2007
  14. Junio C HamanoJul 31, 2007
  15. Craig BostonJul 30, 2007
  16. Linus TorvaldsJul 30, 2007
  17. Craig BostonJul 31, 2007
  18. Linus TorvaldsJul 31, 2007
  19. Theodore TsoJul 31, 2007
  20. Craig BostonJul 31, 2007
  21. Linus TorvaldsJul 31, 2007
  22. Theodore TsoJul 31, 2007
  23. David KastrupJul 31, 2007
  24. Florian WeimerJul 31, 2007
  25. David KastrupJul 31, 2007
  26. Jakub NarebskiJul 30, 2007
  27. David KastrupJul 30, 2007

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.