summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorDariusz Luksza2010-08-15 16:27:56 (EDT)
committer Dariusz Luksza2010-08-16 14:43:30 (EDT)
commit68d6e348c069d07d60a8ad44daf9aa6d93f55635 (patch)
tree77bf1100f9fa3023429dfe4c6fe00654a94c2adc
parentd97e8442fb3d5981d5f279e4a13af9a1fdcb5ae6 (diff)
downloadegit-68d6e348c069d07d60a8ad44daf9aa6d93f55635.zip
egit-68d6e348c069d07d60a8ad44daf9aa6d93f55635.tar.gz
egit-68d6e348c069d07d60a8ad44daf9aa6d93f55635.tar.bz2
Use getChildren() instead of TreeWalk in GitCommitMappingrefs/changes/12/1312/2
This is a small performance improvement in GitCommitMapping class. TreeWalk over repository were replaced by iteration over GitModelCommit children. Change-Id: I30187dc1bd43420d5087f62a4b7e994b8f313a96 Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitCommitMapping.java70
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java6
5 files changed, 49 insertions, 45 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitCommitMapping.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitCommitMapping.java
index 77fb2ef..fca369f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitCommitMapping.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitCommitMapping.java
@@ -8,7 +8,10 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.synchronize.mapping;
-import java.io.IOException;
+import static org.eclipse.core.resources.IResource.ALLOW_MISSING_LOCAL;
+import static org.eclipse.core.resources.IResource.DEPTH_INFINITE;
+import static org.eclipse.core.resources.IResource.DEPTH_ONE;
+
import java.util.ArrayList;
import java.util.List;
@@ -22,13 +25,8 @@ import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.egit.core.Activator;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.treewalk.TreeWalk;
-import org.eclipse.jgit.treewalk.filter.TreeFilter;
+import org.eclipse.egit.ui.internal.synchronize.model.GitModelObject;
class GitCommitMapping extends GitObjectMapping {
@@ -42,52 +40,34 @@ class GitCommitMapping extends GitObjectMapping {
@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context,
IProgressMonitor monitor) throws CoreException {
- Repository repo = gitCommit.getRepository();
- TreeWalk tw = new TreeWalk(repo);
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
List<ResourceTraversal> result = new ArrayList<ResourceTraversal>();
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
-
- tw.reset();
- tw.setRecursive(false);
- tw.setFilter(TreeFilter.ANY_DIFF);
- try {
- RevCommit commit = gitCommit.getRemoteCommit();
- tw.addTree(commit.getParent(0).getTree());
- int nth = tw.addTree(commit.getTree());
-
- while (tw.next()) {
- ResourceTraversal traversal = getTraversal(tw, workspaceRoot,
- nth);
- if (traversal != null)
- result.add(traversal);
- }
- } catch (IOException e) {
- Activator.logError(e.getMessage(), e);
- }
+ for (GitModelObject child : gitCommit.getChildren()) {
+ ResourceTraversal traversal;
+ IPath location = child.getLocation();
- return result.toArray(new ResourceTraversal[result.size()]);
- }
+ if (child.isContainer()) {
+ IContainer container = root.getContainerForLocation(location);
+ if (container == null)
+ continue;
- private ResourceTraversal getTraversal(TreeWalk tw,
- IWorkspaceRoot workspaceRoot, int nth) {
- IPath path = gitCommit.getLocation().append(tw.getPathString());
- int objectType = tw.getFileMode(nth).getObjectType();
+ traversal = new ResourceTraversal(
+ new IResource[] { container }, DEPTH_INFINITE,
+ ALLOW_MISSING_LOCAL);
+ } else {
+ IFile file = root.getFileForLocation(location);
+ if (file == null)
+ continue;
- ResourceTraversal traversal = null;
- if (objectType == Constants.OBJ_BLOB) {
- IFile file = workspaceRoot.getFileForLocation(path);
- if (file != null)
traversal = new ResourceTraversal(new IResource[] { file },
- IResource.DEPTH_ZERO, IResource.ALLOW_MISSING_LOCAL);
- } else if (objectType == Constants.OBJ_TREE) {
- IContainer folder = workspaceRoot.getContainerForLocation(path);
- if (folder != null)
- traversal = new ResourceTraversal(new IResource[] { folder },
- IResource.DEPTH_INFINITE, IResource.ALLOW_MISSING_LOCAL);
+ DEPTH_ONE, ALLOW_MISSING_LOCAL);
+ }
+
+ result.add(traversal);
}
- return traversal;
+ return result.toArray(new ResourceTraversal[result.size()]);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java
index ebc6248..1e0db4e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java
@@ -95,6 +95,11 @@ public class GitModelBlob extends GitModelCommit {
}
@Override
+ public boolean isContainer() {
+ return false;
+ }
+
+ @Override
public ITypedElement getAncestor() {
if (objectExist(getAncestorCommit(), ancestorId))
return CompareUtils.getFileRevisionTypedElement(gitPath,
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
index b885283..8382dc1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
@@ -210,6 +210,11 @@ public class GitModelCommit extends GitModelObject implements ISynchronizationCo
// do nothing, we should disallow coping content between commits
}
+ @Override
+ public boolean isContainer() {
+ return true;
+ }
+
/**
* @return SHA1 of ancestor object
*/
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java
index 21cdb18..27d3879 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java
@@ -76,6 +76,14 @@ public abstract class GitModelObject extends PlatformObject {
public abstract IPath getLocation();
/**
+ * Answers if model object may have children.
+ *
+ * @return <code>true</code> if the model object may have children and
+ * <code>false</code> otherwise.
+ */
+ public abstract boolean isContainer();
+
+ /**
*
* @param parent
* of particular model object
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java
index dfddbfd..0a8c291 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java
@@ -112,6 +112,12 @@ public class GitModelRepository extends GitModelObject {
return location;
}
+ @Override
+ public boolean isContainer() {
+ return true;
+ }
+
+
private void getChildrenImpl() {
List<GitModelCommit> result = new ArrayList<GitModelCommit>();