add_file_to_index: skip rehashing if the cached stat already matches
An earlier commit 366bfcb6 broke git-add 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 a regression because the responsibility of avoiding unnecessary reindexing by matching the cached stat is shifted nowhere. This makes it the job of add_file_to_index() function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 30, 2007 at 17:12 UTC
0781b8a9b2fe760fc4ed519a3a26e4b9bd6ccffe
1 file changed
+10
-1
read-cache.c
+10
-1
@@ -380,7 +380,7 @@ static int index_name_pos_also_unmerged(struct index_state *istate,
380
381
int add_file_to_index(struct index_state *istate, const char *path, int verbose)
382
{
383
- int size, namelen;
383
+ int size, namelen, pos;
384
struct stat st;
385
struct cache_entry *ce;
386
@@ -414,6 +414,15 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
414
ce->ce_mode = ce_mode_from_stat(ent, st.st_mode);
415
}
416
417
+ pos = index_name_pos(istate, ce->name, namelen);
418
+ if (0 <= pos &&
419
+ !ce_stage(istate->cache[pos]) &&
420
+ !ie_modified(istate, istate->cache[pos], &st, 1)) {
421
+ /* Nothing changed, really */
422
+ free(ce);
423
+ return 0;
424
+ }
425
+
426
if (index_path(ce->sha1, path, &st, 1))
427
die("unable to index file %s", path);
428
if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE))