aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2010-08-09 16:39:42 (EDT)
committerChris Aniszczyk2010-08-11 20:45:12 (EDT)
commita15eaffd115ba8de82c44ffca066375fa149209a (patch)
treea6ab12096d4c0cdcde592e8edf0f9d45815bdfd1
parentb0620c8d074ac5c676172bf2b4de7beeb77bff73 (diff)
downloadegit-a15eaffd115ba8de82c44ffca066375fa149209a.zip
egit-a15eaffd115ba8de82c44ffca066375fa149209a.tar.gz
egit-a15eaffd115ba8de82c44ffca066375fa149209a.tar.bz2
Improve GitResourceVariant performancerefs/changes/69/1269/6
Recursive TreeWalk's for obtaining objectId were replaced by additional onstructor parameter, this change should improve performance of synchronize action. Change-Id: I6c221ee7a1f754262d008bffe5103d37082773dc Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java52
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java21
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java34
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java56
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java6
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java18
6 files changed, 69 insertions, 118 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java
index 80f0fd1..31b6b4a 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java
@@ -38,6 +38,7 @@ import org.eclipse.jgit.api.Git;
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.team.core.variants.IResourceVariant;
import org.junit.After;
import org.junit.Before;
@@ -152,7 +153,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
String path = Repository.stripWorkDir(repo.getWorkTree(), file);
GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
- commit, path);
+ commit.getTree(), path);
// then
assertFalse(grvc.compare(local, remote));
@@ -186,8 +187,8 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
expect(local.getFullPath()).andReturn(iPath).anyTimes();
replay(local);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
- commit, path);
+ GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
+ commit.getTree(), path);
// then
assertTrue(grvc.compare(local, remote));
@@ -482,9 +483,9 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
String path = Repository.stripWorkDir(repo.getWorkTree(), file);
GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
- baseCommit, path);
+ baseCommit.getTree(), path);
GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
- remoteCommit, path);
+ remoteCommit.getTree(), path);
// then
assertFalse(grvc.compare(base, remote));
@@ -514,9 +515,9 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
String path = Repository.stripWorkDir(repo.getWorkTree(), file);
GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
- baseCommit, path);
+ baseCommit.getTree(), path);
GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
- remoteCommit, path);
+ remoteCommit.getTree(), path);
// then
assertFalse(grvc.compare(base, remote));
@@ -545,9 +546,9 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
String folderPath = Repository.stripWorkDir(repo.getWorkTree(),
new File(file.getParent()));
GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
- commit, filePath);
+ commit.getTree(), filePath);
GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
- commit, folderPath);
+ commit.getTree(), folderPath);
// then
assertFalse(grvc.compare(base, remote));
@@ -577,9 +578,9 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
new File(file.getParent()));
GitFolderResourceVariant base = new GitFolderResourceVariant(repo,
- commit, folderPath);
+ commit.getTree(), folderPath);
GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
- commit, filePath);
+ commit.getTree(), filePath);
// then
assertFalse(grvc.compare(base, remote));
@@ -610,15 +611,18 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
testRepo.addToIndex(testRepo.getIFile(iProject, file2));
RevCommit commit = testRepo.commit("initial commit");
- String path1 = Repository.stripWorkDir(repo.getWorkTree(), new File(
- file1.getParent()));
- String path2 = Repository.stripWorkDir(repo.getWorkTree(), new File(
- file2.getParent()));
+ TreeWalk tw = new TreeWalk(repo);
+ int nth = tw.addTree(commit.getTree());
+ tw.next();
+ tw.enterSubtree(); // enter project node
+ tw.next();
GitFolderResourceVariant base = new GitFolderResourceVariant(repo,
- commit, path1);
+ tw.getObjectId(nth), tw.getNameString());
+
+ tw.next();
GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
- commit, path2);
+ tw.getObjectId(nth), tw.getNameString());
// then
assertFalse(grvc.compare(base, remote));
@@ -648,9 +652,9 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
file1.getParent()));
GitFolderResourceVariant base = new GitFolderResourceVariant(repo,
- commit, path1);
+ commit.getTree(), path1);
GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
- commit, path1);
+ commit.getTree(), path1);
// then
assertTrue(grvc.compare(base, remote));
@@ -678,10 +682,10 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
String path = Repository.stripWorkDir(repo.getWorkTree(), file);
GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
- baseCommit, path);
+ baseCommit.getTree(), path);
GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
- remoteCommit, path);
+ remoteCommit.getTree(), path);
// then
assertFalse(grvc.compare(base, remote));
@@ -705,9 +709,11 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
"a", "initial commit");
String path = Repository.stripWorkDir(repo.getWorkTree(), file);
- GitBlobResourceVariant base = new GitBlobResourceVariant(repo, commit, path);
+ GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
+ commit.getTree(), path);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(repo, commit, path);
+ GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
+ commit.getTree(), path);
// then
assertTrue(grvc.compare(base, remote));
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java
index e8fe895..45f1fff 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java
@@ -26,12 +26,9 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.egit.core.Activator;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevTree;
-import org.eclipse.jgit.treewalk.TreeWalk;
-import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.team.core.TeamException;
/**
@@ -43,9 +40,9 @@ public class GitBlobResourceVariant extends GitResourceVariant {
private byte[] bytes;
- GitBlobResourceVariant(Repository repo, RevCommit revCommit, String path)
+ GitBlobResourceVariant(Repository repo, ObjectId objectId, String path)
throws IOException {
- super(repo, revCommit, path);
+ super(repo, objectId, path);
if (getObjectId() != null) {
ObjectLoader blob = repo.open(getObjectId());
@@ -104,16 +101,4 @@ public class GitBlobResourceVariant extends GitResourceVariant {
return bytes;
}
- @Override
- protected TreeWalk getTreeWalk(Repository repo, RevTree revTree,
- String path) throws IOException {
- TreeWalk tw = new TreeWalk(repo);
- tw.reset();
- tw.addTree(revTree);
- tw.setRecursive(true);
- tw.setFilter(PathFilter.create(path));
-
- return tw.next() ? tw : null;
- }
-
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java
index f1b406f..f3ee793 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java
@@ -19,11 +19,9 @@ import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.egit.core.CoreText;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.treewalk.TreeWalk;
-import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.variants.IResourceVariant;
@@ -33,13 +31,11 @@ import org.eclipse.team.core.variants.IResourceVariant;
*/
public class GitFolderResourceVariant extends GitResourceVariant {
- private TreeWalk tw;
-
private IResourceVariant members[];
- GitFolderResourceVariant(Repository repo, RevCommit revCommit, String path)
+ GitFolderResourceVariant(Repository repo, ObjectId objectId, String path)
throws IOException {
- super(repo, revCommit, path);
+ super(repo, objectId, path);
}
public boolean isContainer() {
@@ -68,6 +64,10 @@ public class GitFolderResourceVariant extends GitResourceVariant {
progress.done();
}
+ TreeWalk tw = new TreeWalk(getRepository());
+ tw.reset();
+ int nth = tw.addTree(getObjectId());
+
IProgressMonitor monitor = SubMonitor.convert(progress);
monitor.beginTask(
NLS.bind(CoreText.GitFolderResourceVariant_fetchingMembers, this),
@@ -78,12 +78,13 @@ public class GitFolderResourceVariant extends GitResourceVariant {
try {
while (tw.next()) {
+ ObjectId newObjectId = tw.getObjectId(nth);
String path = getPath() + "/" + new String(tw.getRawPath()); //$NON-NLS-1$
if (tw.isSubtree())
- result.add(new GitFolderResourceVariant(repo, getRevCommit(),
+ result.add(new GitFolderResourceVariant(repo, newObjectId,
path));
else
- result.add(new GitBlobResourceVariant(repo, getRevCommit(),
+ result.add(new GitBlobResourceVariant(repo, newObjectId,
path));
monitor.worked(1);
}
@@ -95,19 +96,4 @@ public class GitFolderResourceVariant extends GitResourceVariant {
}
}
- @Override
- protected TreeWalk getTreeWalk(Repository repo, RevTree revTree, String path)
- throws IOException {
- tw = new TreeWalk(repo);
- tw.reset();
- tw.addTree(revTree);
- tw.setFilter(PathFilter.create(path));
-
- while (tw.next() && !path.equals(tw.getPathString()))
- if (tw.isSubtree())
- tw.enterSubtree();
-
- return tw;
- }
-
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java
index 8ddfc96..136de20 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java
@@ -21,23 +21,16 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevTree;
-import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.team.core.variants.IResourceVariant;
abstract class GitResourceVariant implements IResourceVariant {
- private final String variantPath;
+ private final String path;
private final Repository repo;
private final ObjectId objectId;
- private final RevCommit revCommit;
-
- private final String path;
-
private String name;
private IPath fullPath;
@@ -49,24 +42,16 @@ abstract class GitResourceVariant implements IResourceVariant {
* Construct Git representation of {@link IResourceVariant}.
*
* @param repo
- * @param revCommit
+ * @param objectId
* @param path
* should be repository relative
* @throws IOException
*/
- GitResourceVariant(Repository repo, RevCommit revCommit, String path)
+ GitResourceVariant(Repository repo, ObjectId objectId, String path)
throws IOException {
- this.repo = repo;
- this.revCommit = revCommit;
this.path = path;
- TreeWalk tw = getTreeWalk(repo, revCommit.getTree(), path);
- if (tw == null) {
- objectId = null;
- this.variantPath = null;
- } else {
- objectId = tw.getObjectId(0);
- this.variantPath = new String(tw.getRawPath());
- }
+ this.repo = repo;
+ this.objectId = objectId;
}
public String getContentIdentifier() {
@@ -74,12 +59,12 @@ abstract class GitResourceVariant implements IResourceVariant {
}
public String getName() {
- if (name == null && variantPath != null) {
- int lastSeparator = variantPath.lastIndexOf('/');
+ if (name == null && path != null) {
+ int lastSeparator = path.lastIndexOf('/');
if (lastSeparator > -1)
- name = variantPath.substring(lastSeparator + 1);
+ name = path.substring(lastSeparator + 1);
else
- name = variantPath;
+ name = path;
}
return name;
@@ -100,24 +85,9 @@ abstract class GitResourceVariant implements IResourceVariant {
@Override
public String toString() {
- return variantPath + "(" + objectId.getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ return path + "(" + objectId.getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
- /**
- *
- * @param repository
- * @param revTree
- * base commit
- * @param path
- * to resource variant
- * @return new tree walk positioned on given object or <code>null</code>
- * when given path was not found in repository
- * @throws IOException
- * when something goes wrong during tree walk initialization
- */
- protected abstract TreeWalk getTreeWalk(Repository repository, RevTree revTree,
- String path) throws IOException;
-
protected ObjectId getObjectId() {
return objectId;
}
@@ -126,12 +96,8 @@ abstract class GitResourceVariant implements IResourceVariant {
return repo;
}
- protected RevCommit getRevCommit() {
- return revCommit;
- }
-
protected String getPath() {
- return variantPath;
+ return path;
}
protected IPath getFullPath() {
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java
index 9270382..e648a9f 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java
@@ -100,8 +100,10 @@ class GitResourceVariantComparator implements IResourceVariantComparator {
boolean exists = gitBase.exists() && gitRemote.exists();
boolean equalType = !(gitBase.isContainer() ^ gitRemote.isContainer());
- return equalType && exists
- && gitBase.getObjectId().equals(gitRemote.getObjectId());
+ boolean equalSha1 = gitBase.getObjectId().getName()
+ .equals(gitRemote.getObjectId().getName());
+
+ return equalType && exists && equalSha1;
}
public boolean isThreeWay() {
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java
index b20f247..1bd320d 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java
@@ -71,13 +71,19 @@ abstract class GitResourceVariantTree extends ResourceVariantTree {
TreeWalk tw = initializeTreeWalk(repo, path);
try {
- tw.addTree(revCommit.getTree());
+ int nth = tw.addTree(revCommit.getTree());
if (resource.getType() == IResource.FILE) {
tw.setRecursive(true);
if (tw.next())
- return new GitBlobResourceVariant(repo, revCommit, path);
- } else
- return new GitFolderResourceVariant(repo, revCommit, path);
+ return new GitBlobResourceVariant(repo,
+ tw.getObjectId(nth), path);
+ } else {
+ while (tw.next() && !path.equals(tw.getPathString()))
+ if (tw.isSubtree())
+ tw.enterSubtree();
+ return new GitFolderResourceVariant(repo, tw.getObjectId(nth),
+ path);
+ }
} catch (IOException e) {
throw new TeamException(
NLS.bind(
@@ -133,8 +139,8 @@ abstract class GitResourceVariantTree extends ResourceVariantTree {
private IResourceVariant handleRepositoryRoot(final IResource resource,
Repository repo, RevCommit revCommit) throws TeamException {
try {
- return new GitFolderResourceVariant(repo, revCommit, resource
- .getLocation().toString());
+ return new GitFolderResourceVariant(repo, revCommit.getTree(),
+ resource.getLocation().toString());
} catch (IOException e) {
throw new TeamException(
NLS.bind(