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

[PATCH v2] Fix extraneous lstat's in 'git checkout -f'

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jul 14, 2009, 21:19 UTC
Message-ID
<alpine.LFD.2.01.0907141417160.13838@localhost.localdomain>
In-Reply-To
<alpine.LFD.2.01.0907140750290.13838@localhost.localdomain>

In our 'oneway_merge()' we always do an 'lstat()' to see if we might need to mark the entry for updating.

But we really shouldn't need to do that when the cache entry is already marked as being ce_uptodate(), and this makes us do unnecessary lstat() calls if we have index preloading enabled.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

As Junio noticed, I meant "ce_uptodate()", not "ce_valid()", but this is basically the simplified version that replaces the one that cared about CE_VALID.

On Tue, 14 Jul 2009, Linus Torvalds wrote:
Show 14 quoted lines
> 
> And in that case, I guess it's also fine. In fact, for that case CE_VALID 
> would tend to really mean "always assume CE_UPTODATE", so then the patch I 
> sent out doesn't really necessarily need the whole "known_uptodate()" 
> thing, and could just use
> 
> 	if (o->reset && !ce_valid(old)) {
> 
> instead.
> 
> Which also makes my other worries go away.
> 
> 			Linus
> 
 unpack-trees.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index f9d12aa..48d862d 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1004,7 +1004,7 @@ int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
 
 	if (old && same(old, a)) {
 		int update = 0;
-		if (o->reset) {
+		if (o->reset && !ce_uptodate(old)) {
 			struct stat st;
 			if (lstat(old->name, &st) ||
 			    ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID))
Previous: Linus Torvalds
Message 5 of 5 in “Fix extraneous lstat's in 'git checkout -f'”
  1. Linus TorvaldsJul 14, 2009
  2. Linus TorvaldsJul 14, 2009
  3. Junio C HamanoJul 14, 2009
  4. Linus TorvaldsJul 14, 2009
  5. Fix extraneous lstat's in 'git checkout -f'Linus Torvalds, Jul 14, 2009

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.