Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2013-02-01 13:26:58 +0000
committerRobin Stocker2013-02-01 13:41:06 +0000
commit6c5a0d986b7bc84df969baea3d646e18a877b5e0 (patch)
tree2bf967d6959476295badd2e5f36678f0c79609d7 /org.eclipse.egit.ui.test/src
parent10cdd651b8acef99b4a89a2fc5732d1043d47b5b (diff)
downloadegit-6c5a0d986b7bc84df969baea3d646e18a877b5e0.tar.gz
egit-6c5a0d986b7bc84df969baea3d646e18a877b5e0.tar.xz
egit-6c5a0d986b7bc84df969baea3d646e18a877b5e0.zip
[sync] Fix performance problem with GitModelCache#getChildren
The problem was that it returned a child for each changed file, instead of only the direct children. So e.g. with changes in "dir/a", "dir/b" and "dir/c", it returned a node for "dir" three times. When the number of changes is significant, this resulted in many children returned, each of which also has children which will be processed by the calling code. The code in GitModelCommit for tree construction did it right. To fix this, this change consolidates the two tree construction implementations into one which should be correct. It also takes care that the final tree nodes use as little memory as possible by using arrays. Bug: 396209 Change-Id: I0f139cf7747affb06b32cee584355cf60b46fb76
Diffstat (limited to 'org.eclipse.egit.ui.test/src')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java33
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTreeTest.java2
2 files changed, 33 insertions, 2 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java
index 66bb5c7fbd..4668849c08 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2011, Dariusz Luksza <dariusz@luksza.org>
+ * Copyright (C) 2011, 2013 Dariusz Luksza <dariusz@luksza.org> and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,13 +8,20 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.synchronize.model;
+import static org.eclipse.jgit.junit.JGitTestUtil.writeTrashFile;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.io.File;
+import java.util.Map;
+import org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change;
+import org.eclipse.egit.core.synchronize.StagedChangeCache;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.storage.file.FileRepository;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -93,6 +100,30 @@ public class GitModelCacheTest extends GitModelTestCase {
assertFalse(actual);
}
+ @Test
+ public void shouldReturnChildren() throws Exception {
+ FileRepository repo = lookupRepository(leftRepoFile);
+ writeTrashFile(repo, "dir/a.txt", "trash");
+ writeTrashFile(repo, "dir/b.txt", "trash");
+ writeTrashFile(repo, "dir/c.txt", "trash");
+ writeTrashFile(repo, "dir/d.txt", "trash");
+ new Git(repo).add().addFilepattern("dir").call();
+
+ Map<String, Change> changes = StagedChangeCache.build(repo);
+ assertEquals(4, changes.size());
+
+ GitModelCache cache = new GitModelCache(createModelRepository(), repo,
+ changes);
+
+ GitModelObject[] cacheChildren = cache.getChildren();
+ assertEquals(1, cacheChildren.length);
+ GitModelObject dir = cacheChildren[0];
+ assertEquals("dir", dir.getName());
+
+ GitModelObject[] dirChildren = dir.getChildren();
+ assertEquals(4, dirChildren.length);
+ }
+
@BeforeClass public static void setupEnvironment() throws Exception {
leftRepoFile = createProjectAndCommitToRepository();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTreeTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTreeTest.java
index 25aa328033..20f2198e47 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTreeTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTreeTest.java
@@ -15,7 +15,7 @@ import static org.mockito.Mockito.mock;
import org.eclipse.core.runtime.IPath;
import org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change;
import org.eclipse.egit.ui.Activator;
-import org.eclipse.egit.ui.internal.synchronize.model.GitModelCache.FileModelFactory;
+import org.eclipse.egit.ui.internal.synchronize.model.TreeBuilder.FileModelFactory;
import org.eclipse.jgit.lib.Repository;
import org.junit.BeforeClass;
import org.junit.Test;

Back to the top