]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Optimize the two-way merge of git-read-tree too
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 10 Aug 2007 19:31:20 +0000 (12:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Aug 2007 21:00:25 +0000 (14:00 -0700)
This trivially optimizes the two-way merge case of git-read-tree too,
which affects switching branches.

When you have tons and tons of files in your repository, but there are
only small differences in the branches (maybe just a couple of files
changed), the biggest cost of the branch switching was actually just the
index calculations.

This fixes it (timings for switching between the "testing" and "master"
branches in the 100,000 file testing-repo-from-hell, where the branches
only differ in one small file).

Before:
[torvalds@woody bummer]$ time git checkout master
real    0m9.919s
user    0m8.461s
sys     0m0.264s

After:
[torvalds@woody bummer]$ time git checkout testing
real    0m0.576s
user    0m0.348s
sys     0m0.228s

so it's easily an order of magnitude different.

This concludes the series. I think we could/should do the three-way merge
too (to speed up merges), but I'm lazy. Somebody else can do it.

The rule is very simple: you need to remove the old entry if:
 - you want to remove the file entirely
 - you replace it with a "merge conflict" entry (ie a non-stage-0 entry)

and you can avoid removing it if you either

 - keep the old one
 - or resolve it to a new one.

and these rules should all be valid for the three-way case too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
unpack-trees.c

index d57b91c1b2738f205d7997cc67f25f594ff3e5ed..fda7729f1d0e7eb85f449e41800a74278bc48254 100644 (file)
@@ -827,7 +827,6 @@ int twoway_merge(struct cache_entry **src,
        struct cache_entry *oldtree = src[1];
        struct cache_entry *newtree = src[2];
 
-       remove_entry(remove);
        if (o->merge_size != 2)
                return error("Cannot do a twoway merge of %d trees",
                             o->merge_size);
@@ -850,6 +849,7 @@ int twoway_merge(struct cache_entry **src,
                }
                else if (oldtree && !newtree && same(current, oldtree)) {
                        /* 10 or 11 */
+                       remove_entry(remove);
                        return deleted_entry(oldtree, current, o);
                }
                else if (oldtree && newtree &&
@@ -859,6 +859,7 @@ int twoway_merge(struct cache_entry **src,
                }
                else {
                        /* all other failures */
+                       remove_entry(remove);
                        if (oldtree)
                                reject_merge(oldtree);
                        if (current)
@@ -870,8 +871,8 @@ int twoway_merge(struct cache_entry **src,
        }
        else if (newtree)
                return merged_entry(newtree, current, o);
-       else
-               return deleted_entry(oldtree, current, o);
+       remove_entry(remove);
+       return deleted_entry(oldtree, current, o);
 }
 
 /*