Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2015-12-16 15:47:38 +0000
committerMatthias Sohn2015-12-23 14:52:52 +0000
commit983c74084e5c5fd832f5ee0e2ebac464f850a8bd (patch)
tree8124879057e0df676efaaee4117d801d2535ec84 /org.eclipse.egit.core.test
parent045f15fa4c0045b8f14dfb991b985af8d089f96a (diff)
downloadegit-983c74084e5c5fd832f5ee0e2ebac464f850a8bd.tar.gz
egit-983c74084e5c5fd832f5ee0e2ebac464f850a8bd.tar.xz
egit-983c74084e5c5fd832f5ee0e2ebac464f850a8bd.zip
[performance] Remove ContainerTreeIterator and AdaptableFileTreeIterator
Don't hook any extra Eclipse based iterators to jgit tree traversal: 1) Eclipse IResource API can't handle "unusual" links (unresolved or recursive), see bug 290318. This is a major functional deficiency for repositories which make use of links. 2) The assumption that Eclipse IResource API traverses the file system faster as java.io does not hold on Windows/Linux/Mac/NFS with modern (7+) Java, see bug 484498 comments 10 and 14,15,17. The opposite is true: especially on Linux the java.io access is considerably faster as IResource API or what the ContainerTreeIterator makes of it. AdaptableFileTreeIterator/ContainerTreeIterator use is replaced with default FileTreeIterator, tests adopted or removed. Bug: 484498 Change-Id: I026abee1706e6fbcd470cc7262b9fc1e59a7fe8b Signed-off-by: Andrey Loskutov <loskutov@gmx.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/AdaptableFileTreeIteratorTest.java88
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/ContainerTreeIteratorResourceFilterTest.java250
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java4
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/SubmoduleAndContainerTreeIteratorTest.java8
4 files changed, 5 insertions, 345 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/AdaptableFileTreeIteratorTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/AdaptableFileTreeIteratorTest.java
deleted file mode 100644
index 3740339e9d..0000000000
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/AdaptableFileTreeIteratorTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2009, Tor Arne Vestbø <torarnv@gmail.com>
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-package org.eclipse.egit.core.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.Collections;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.egit.core.AdaptableFileTreeIterator;
-import org.eclipse.egit.core.ContainerTreeIterator;
-import org.eclipse.egit.core.op.ConnectProviderOperation;
-import org.eclipse.egit.core.project.RepositoryMapping;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.eclipse.jgit.treewalk.TreeWalk;
-import org.eclipse.jgit.treewalk.WorkingTreeIterator;
-import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
-import org.junit.Before;
-import org.junit.Test;
-
-public class AdaptableFileTreeIteratorTest extends GitTestCase {
-
- private Repository repository;
-
- private File file;
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
-
- repository = FileRepositoryBuilder.create(gitDir);
- repository.create();
-
- file = new File(project.getProject().getLocation().toFile(), "a.txt");
- final Writer fileWriter = new OutputStreamWriter(new FileOutputStream(
- file), "UTF-8");
- fileWriter.write("aaaaaaaaaaa");
- fileWriter.close();
-
- final ConnectProviderOperation operation = new ConnectProviderOperation(
- project.getProject(), gitDir);
- operation.execute(null);
- }
-
- @Test
- public void testFileTreeToContainerAdaptation() throws IOException {
- final IWorkspaceRoot root = project.getProject().getWorkspace()
- .getRoot();
-
- try (final TreeWalk treeWalk = new TreeWalk(repository)) {
- treeWalk.addTree(new AdaptableFileTreeIterator(repository, root));
- treeWalk.setRecursive(true);
-
- final IFile eclipseFile = project.getProject()
- .getFile(file.getName());
- final RepositoryMapping mapping = RepositoryMapping
- .getMapping(eclipseFile);
- final Set<String> repositoryPaths = Collections
- .singleton(mapping.getRepoRelativePath(eclipseFile));
-
- assertEquals(1, repositoryPaths.size());
- treeWalk.setFilter(
- PathFilterGroup.createFromStrings(repositoryPaths));
-
- assertTrue(treeWalk.next());
-
- final WorkingTreeIterator iterator = treeWalk.getTree(0,
- WorkingTreeIterator.class);
- assertTrue(iterator instanceof ContainerTreeIterator);
- }
- }
-}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/ContainerTreeIteratorResourceFilterTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/ContainerTreeIteratorResourceFilterTest.java
deleted file mode 100644
index 0389a70c64..0000000000
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/ContainerTreeIteratorResourceFilterTest.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2012, Robin Stocker <robin@nibor.org>
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-package org.eclipse.egit.core.test;
-
-import static org.eclipse.core.resources.IResourceFilterDescription.EXCLUDE_ALL;
-import static org.eclipse.core.resources.IResourceFilterDescription.FILES;
-import static org.eclipse.core.resources.IResourceFilterDescription.FOLDERS;
-import static org.eclipse.core.resources.IResourceFilterDescription.INHERITABLE;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.FileInfoMatcherDescription;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.egit.core.AdaptableFileTreeIterator;
-import org.eclipse.egit.core.ContainerTreeIterator;
-import org.eclipse.egit.core.op.ConnectProviderOperation;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.eclipse.jgit.treewalk.AbstractTreeIterator;
-import org.eclipse.jgit.treewalk.TreeWalk;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test for how {@link ContainerTreeIterator} handles filtered resources.
- * <p>
- * The tricky thing is that they are not returned from API like
- * {@link IContainer#members()}. So we have to fall back to using an
- * {@link AdaptableFileTreeIterator} if there may be resource filters active.
- * <p>
- * In case of nested projects where the subproject is filtered in the parent
- * project with resource filters, we want the nested project to be walked with
- * {@link ContainerTreeIterator} again. That is, it should "recover" from
- * falling back to {@link AdaptableFileTreeIterator}.
- */
-public class ContainerTreeIteratorResourceFilterTest extends GitTestCase {
-
- private Repository repository;
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
-
- repository = FileRepositoryBuilder.create(gitDir);
- repository.create();
-
- connectProject(project.getProject());
- }
-
- @Test
- public void simpleNonInheritableFilter() throws Exception {
- IProject p = project.getProject();
- IFile filtered = testUtils.addFileToProject(p, "filtered.txt", "");
- IFile unfiltered = testUtils.addFileToProject(p, "unfiltered.txt", "");
- assertTrue("IFile should exist before filtering.", filtered.exists());
- assertTrue("IFile should exist before filtering.", unfiltered.exists());
-
- createFilter(p, EXCLUDE_ALL | FILES, "filtered.txt");
- assertFalse("IFile should no longer exist after filtering.", filtered.exists());
- assertTrue("IFile should exist after filtering.", unfiltered.exists());
-
- List<Entry> entries = walkTree();
-
- assertThat(entries, hasItem(containerTreeEntry("Project-1/filtered.txt")));
- assertThat(entries, hasItem(containerTreeEntry("Project-1/unfiltered.txt")));
- }
-
- @Test
- public void simpleNonInheritableFolderFilter() throws Exception {
- IProject p = project.getProject();
- IFile filtered = testUtils.addFileToProject(p, "folder/filtered.txt", "");
- IFile unfiltered = testUtils.addFileToProject(p, "folder2/unfiltered.txt", "");
-
- createFilter(p, EXCLUDE_ALL | FOLDERS, "folder");
- assertFalse("IFile should no longer exist after filtering.", filtered.exists());
- assertTrue("IFile should exist after filtering.", unfiltered.exists());
-
- List<Entry> entries = walkTree();
-
- assertThat(entries, hasItem(adaptableFileTreeEntry("Project-1/folder/filtered.txt")));
- assertThat(entries, hasItem(containerTreeEntry("Project-1/folder2/unfiltered.txt")));
- }
-
- @Test
- public void inheritableFilter() throws Exception {
- IProject p = project.getProject();
- IFile filtered1 = testUtils.addFileToProject(p, "folder1/filtered.txt", "");
- IFile filtered2 = testUtils.addFileToProject(p, "folder1/folder2/filtered.txt", "");
- IFile unfiltered = testUtils.addFileToProject(p, "folder1/folder2/unfiltered.txt", "");
-
- createFilter(p, EXCLUDE_ALL | FILES | INHERITABLE, "filtered.txt");
- assertFalse("IFile should no longer exist after filtering.", filtered1.exists());
- assertFalse("IFile should no longer exist after filtering.", filtered2.exists());
- assertTrue("IFile should exist after filtering.", unfiltered.exists());
-
- List<Entry> entries = walkTree();
-
- assertThat(entries, hasItem(containerTreeEntry("Project-1/folder1/filtered.txt")));
- assertThat(entries, hasItem(containerTreeEntry("Project-1/folder1/folder2/filtered.txt")));
- assertThat(entries, hasItem(containerTreeEntry("Project-1/folder1/folder2/unfiltered.txt")));
- }
-
- @Test
- public void directlyNestedProject() throws Exception {
- IProject p = project.getProject();
- testUtils.addFileToProject(p, "file.txt", "");
-
- TestProject testProject2 = new TestProject(true, "Project-1/Project-2");
- testUtils.addFileToProject(testProject2.getProject(), "project2.txt", "");
-
- createFilter(p, EXCLUDE_ALL | FOLDERS, "Project-2");
-
- List<Entry> entries = walkTree();
-
- assertThat(entries, hasItem(containerTreeEntry("Project-1/file.txt")));
- // Should be handled by container tree iterator because it exists, even
- // when it's not returned by members() of Project-1.
- assertThat(entries, hasItem(containerTreeEntry("Project-1/Project-2/project2.txt")));
- }
-
- @Test
- public void nestedProject() throws Exception {
- IProject p = project.getProject();
- testUtils.addFileToProject(p, "folder1/file.txt", "");
- testUtils.addFileToProject(p, "folder1/subfolder/filtered.txt", "");
-
- TestProject testProject2 = new TestProject(true, "Project-1/folder1/subfolder/Project-2");
- connectProject(testProject2.getProject());
- IFile project2File = testUtils.addFileToProject(testProject2.getProject(), "project2.txt", "");
- assertThat(project2File.getProject(), is(testProject2.getProject()));
-
- createFilter(p.getFolder("folder1"), EXCLUDE_ALL | FOLDERS, "subfolder");
- assertFalse("IFolder should be filtered",
- p.getFolder(new Path("folder1/subfolder")).exists());
-
- List<Entry> entries = walkTree();
-
- assertThat(entries, hasItem(containerTreeEntry("Project-1/folder1/file.txt")));
- assertThat(entries, hasItem(adaptableFileTreeEntry("Project-1/folder1/subfolder/filtered.txt")));
- // Should be handled by container tree iterator again, because the project exists.
- assertThat(entries, hasItem(containerTreeEntry("Project-1/folder1/subfolder/Project-2/project2.txt")));
-
- testProject2.dispose();
- }
-
- private static void createFilter(IContainer container, int type, String regexFilterArguments) throws CoreException {
- FileInfoMatcherDescription matcherDescription = new FileInfoMatcherDescription(
- "org.eclipse.core.resources.regexFilterMatcher",
- regexFilterArguments);
- container.createFilter(type, matcherDescription, 0, null);
- }
-
- private void connectProject(IProject p) throws CoreException {
- final ConnectProviderOperation operation = new ConnectProviderOperation(
- p, gitDir);
- operation.execute(null);
- }
-
- private List<Entry> walkTree() throws IOException {
- try (TreeWalk treeWalk = new TreeWalk(repository)) {
- ContainerTreeIterator tree = new ContainerTreeIterator(repository,
- project.getProject());
- int treeIndex = treeWalk.addTree(tree);
- treeWalk.setRecursive(true);
- List<Entry> entries = new ArrayList<Entry>();
- while (treeWalk.next()) {
- AbstractTreeIterator it = treeWalk.getTree(treeIndex,
- AbstractTreeIterator.class);
- Entry entry = new Entry(treeWalk.getPathString(),
- it.getClass());
- entries.add(entry);
- }
- return entries;
- }
- }
-
- private static Entry containerTreeEntry(String path) {
- return new Entry(path, ContainerTreeIterator.class);
- }
-
- private static Entry adaptableFileTreeEntry(String path) {
- return new Entry(path, AdaptableFileTreeIterator.class);
- }
-
- // Value object (case class).
- private static class Entry {
- private final String path;
- private Class<? extends AbstractTreeIterator> iteratorClass;
-
- public Entry(String path, Class<? extends AbstractTreeIterator> iteratorClass) {
- this.path = path;
- this.iteratorClass = iteratorClass;
- }
-
- @Override
- public String toString() {
- return path + " (" + iteratorClass.getSimpleName() + ")";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result
- + ((iteratorClass == null) ? 0 : iteratorClass.hashCode());
- result = prime * result + ((path == null) ? 0 : path.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Entry other = (Entry) obj;
- if (iteratorClass == null) {
- if (other.iteratorClass != null)
- return false;
- } else if (!iteratorClass.equals(other.iteratorClass))
- return false;
- if (path == null) {
- if (other.path != null)
- return false;
- } else if (!path.equals(other.path))
- return false;
- return true;
- }
- }
-}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java
index aa713e2131..670057ed8a 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java
@@ -25,10 +25,10 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.Activator;
-import org.eclipse.egit.core.ContainerTreeIterator;
import org.eclipse.egit.core.GitProvider;
import org.eclipse.egit.core.IteratorService;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.team.core.RepositoryProvider;
import org.junit.After;
@@ -176,7 +176,7 @@ public class LinkedResourcesTest {
// Test iterator
WorkingTreeIterator iterator = IteratorService
.createInitialIterator(repository1.repository);
- assertTrue(iterator instanceof ContainerTreeIterator);
+ assertTrue(iterator instanceof FileTreeIterator);
while (!iterator.eof()) {
assertFalse(iterator.getEntryPathString().startsWith("link2"));
iterator.next(1);
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/SubmoduleAndContainerTreeIteratorTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/SubmoduleAndContainerTreeIteratorTest.java
index fc49bb5e6b..a3b4bdb6f3 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/SubmoduleAndContainerTreeIteratorTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/SubmoduleAndContainerTreeIteratorTest.java
@@ -17,13 +17,13 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.Activator;
-import org.eclipse.egit.core.AdaptableFileTreeIterator;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -45,7 +45,7 @@ public class SubmoduleAndContainerTreeIteratorTest {
private IFile parentFile;
- private AdaptableFileTreeIterator treeIt;
+ private FileTreeIterator treeIt;
@Before
public void setUp() throws Exception {
@@ -78,9 +78,7 @@ public class SubmoduleAndContainerTreeIteratorTest {
parentRepository.trackAllFiles(parentProject);
parentRepository.commit("Initial commit");
- treeIt = new AdaptableFileTreeIterator(
- parentRepository.getRepository(), parentFile.getWorkspace()
- .getRoot());
+ treeIt = new FileTreeIterator(parentRepository.getRepository());
}
@After

Back to the top