@matheusbsbs / matheus-bagliano / commits / b34c39cf31
Fork 0

read-tree: teach 1 and 2 way merges about cache-tree.

This teaches one-way and two-way "read-tree -m" (and its special form, "read-tree --reset" as well) not to discard cache-tree but invalidate only the changed parts of the tree. When switching between related branches, this helps the eventual commit (i.e. write-tree) by keeping cache-tree valid as much as possible. This does not prime cache-tree yet, but we ought to be able to do that for no-merge (i.e. reading from a tree object) case and, and also perhaps 1 way merge case. With this patch applied, switching between the tip of Linux 2.6 kernel tree and a branch that touches one path (fs/ext3/Makefile) from it invalidates only 3 paths out of 1201 cache-tree entries in the index, and subsequent write-tree takes about a half as much time as before. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 27, 2006 at 00:13 UTC b34c39cf31e370dad3bcfba29ee8cd023c40fd6b
1 file changed +13 -4
read-tree.c
+13 -4
@@ -422,6 +422,12 @@ static void verify_uptodate(struct cache_entry *ce)
422 die("Entry '%s' not uptodate. Cannot merge.", ce->name);
423 }
424
425 +static void invalidate_ce_path(struct cache_entry *ce)
426 +{
427 + if (ce)
428 + cache_tree_invalidate_path(active_cache_tree, ce->name);
429 +}
430 +
431 static int merged_entry(struct cache_entry *merge, struct cache_entry *old)
432 {
433 merge->ce_flags |= htons(CE_UPDATE);
@@ -437,6 +443,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old)
443 *merge = *old;
444 } else {
445 verify_uptodate(old);
446 + invalidate_ce_path(old);
447 }
448 }
449 merge->ce_flags &= ~htons(CE_STAGEMASK);
@@ -450,6 +457,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old)
457 verify_uptodate(old);
458 ce->ce_mode = 0;
459 add_cache_entry(ce, ADD_CACHE_OK_TO_ADD);
460 + invalidate_ce_path(ce);
461 return 1;
462 }
463
@@ -684,8 +692,10 @@ static int oneway_merge(struct cache_entry **src)
692 return error("Cannot do a oneway merge of %d trees",
693 merge_size);
694
687 - if (!a)
695 + if (!a) {
696 + invalidate_ce_path(old);
697 return 0;
698 + }
699 if (old && same(old, a)) {
700 return keep_entry(old);
701 }
@@ -704,6 +714,7 @@ static int read_cache_unmerged(void)
714 struct cache_entry *ce = active_cache[i];
715 if (ce_stage(ce)) {
716 deleted++;
717 + invalidate_ce_path(ce);
718 continue;
719 }
720 if (deleted)
@@ -815,10 +826,9 @@ int main(int argc, char **argv)
826 fn = twoway_merge;
827 break;
828 case 3:
818 - fn = threeway_merge;
819 - break;
829 default:
830 fn = threeway_merge;
831 + cache_tree_free(&active_cache_tree);
832 break;
833 }
834
@@ -829,7 +839,6 @@ int main(int argc, char **argv)
839 }
840
841 unpack_trees(fn);
832 - cache_tree_free(&active_cache_tree);
842 if (write_cache(newfd, active_cache, active_nr) ||
843 commit_index_file(&cache_file))
844 die("unable to write new index file");