Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java22
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java36
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/RevUtils.java4
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java2
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java23
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java20
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java10
7 files changed, 57 insertions, 60 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 904333aa0..80f0fd1f5 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
@@ -15,6 +15,7 @@ import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
+import static org.eclipse.jgit.lib.Constants.HEAD;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -33,6 +34,7 @@ import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
import org.eclipse.egit.core.test.GitTestCase;
import org.eclipse.egit.core.test.TestRepository;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -57,6 +59,10 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
testRepo = new TestRepository(gitDir);
testRepo.connect(iProject);
repo = RepositoryMapping.getMapping(iProject).getRepository();
+
+ // make initial commit
+ new Git(repo).commit().setAuthor("JUnit", "junit@jgit.org")
+ .setMessage("Initall commit").call();
}
@After
@@ -172,11 +178,11 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
+ "keep");
RevCommit commit = testRepo.addAndCommit(iProject, file,
"initial commit");
- String path = Repository.stripWorkDir(repo.getWorkTree(), file.getParentFile());
+ String path = Repository.stripWorkDir(repo.getWorkTree(), file);
IPath iPath = new Path(File.separator + path);
IContainer local = createMock(IContainer.class);
- expect(local.exists()).andReturn(true).anyTimes();
+ expect(local.exists()).andReturn(true);
expect(local.getFullPath()).andReturn(iPath).anyTimes();
replay(local);
@@ -201,7 +207,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
// when
byte[] shortContent = "short content".getBytes();
byte[] longContent = "very long long content".getBytes();
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
dataSet);
@@ -243,7 +249,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
byte[] localContent = "very long long content".getBytes();
// this typo should be here
byte[] remoteContent = "very long lonk content".getBytes();
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
dataSet);
@@ -287,7 +293,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
byte[] remoteContent = new byte[8192];
Arrays.fill(remoteContent, (byte) 'a');
remoteContent[8101] = 'b';
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
dataSet);
@@ -335,7 +341,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
Arrays.fill(localContent, (byte) 'a');
byte[] remoteContent = new byte[8200];
Arrays.fill(remoteContent, (byte) 'a');
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
dataSet);
@@ -376,7 +382,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
// when
byte[] localContent = "very long long content".getBytes();
byte[] remoteContent = "very long long content".getBytes();
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
dataSet);
@@ -420,7 +426,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
Arrays.fill(localContent, (byte) 'a');
byte[] remoteContent = new byte[8192];
Arrays.fill(remoteContent, (byte) 'a');
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
dataSet);
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
index 073117a80..3ca306c1b 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
@@ -8,6 +8,8 @@
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
+import static org.eclipse.jgit.lib.Constants.HEAD;
+import static org.eclipse.jgit.lib.Constants.MASTER;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -16,7 +18,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
@@ -33,6 +34,7 @@ import org.eclipse.egit.core.test.TestProject;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.team.core.variants.IResourceVariant;
@@ -72,12 +74,14 @@ public class GitResourceVariantTreeTest extends GitTestCase {
* given repository. In this case there is only one project associated with
* this repository therefore only one root should be returned.
*
- * @throws IOException
+ * @throws Exception
*/
@Test
- public void shouldReturnOneRoot() throws IOException {
+ public void shouldReturnOneRoot() throws Exception {
// when
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", false);
+ new Git(repo).commit().setAuthor("JUnit", "junit@egit.org")
+ .setMessage("Initial commit").call();
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
@@ -105,7 +109,9 @@ public class GitResourceVariantTreeTest extends GitTestCase {
IProject secondIProject = secondProject.project;
// add connect project with repository
new ConnectProviderOperation(secondIProject, gitDir).execute(null);
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", false);
+ new Git(repo).commit().setAuthor("JUnit", "junit@egit.org")
+ .setMessage("Initial commit").call();
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
@@ -130,8 +136,10 @@ public class GitResourceVariantTreeTest extends GitTestCase {
@Test
public void shouldReturnNullResourceVariant() throws Exception {
// when
- GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
- Constants.MASTER, false);
+ new Git(repo).commit().setAuthor("JUnit", "junit@egit.org")
+ .setMessage("Initial commit").call();
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER,
+ false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
@@ -153,8 +161,10 @@ public class GitResourceVariantTreeTest extends GitTestCase {
IPackageFragment iPackage = project.createPackage("org.egit.test");
IType mainJava = project.createType(iPackage, "Main.java",
"class Main {}");
- GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
- Constants.MASTER, false);
+ new Git(repo).commit().setAuthor("JUnit", "junit@egit.org")
+ .setMessage("Initial commit").call();
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER,
+ false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
@@ -179,8 +189,8 @@ public class GitResourceVariantTreeTest extends GitTestCase {
testRepo.appendContentAndCommit(iProject, file, "class Main {}",
"initial commit");
IFile mainJava = testRepo.getIFile(iProject, file);
- GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
- Constants.MASTER, false);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER,
+ false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
@@ -221,8 +231,8 @@ public class GitResourceVariantTreeTest extends GitTestCase {
Constants.R_HEADS + "test");
testRepo.appendContentAndCommit(iProject, file, "// test",
"first commit");
- GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
- Constants.MASTER, false);
+ GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER,
+ false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/RevUtils.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/RevUtils.java
index 1af91635a..12143595c 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/RevUtils.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/RevUtils.java
@@ -40,8 +40,8 @@ public class RevUtils {
RevWalk rw = new RevWalk(repo);
rw.setRevFilter(RevFilter.MERGE_BASE);
- RevCommit srcRev = rw.parseCommit(commit1);
- RevCommit dstRev = rw.parseCommit(commit2);
+ RevCommit srcRev = rw.lookupCommit(commit1);
+ RevCommit dstRev = rw.lookupCommit(commit2);
rw.markStart(dstRev);
rw.markStart(srcRev);
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java
index a2736d6dd..d226aa8aa 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java
@@ -31,7 +31,7 @@ class GitBaseResourceVariantTree extends GitResourceVariantTree {
throws TeamException {
try {
return RevUtils.getCommonAncestor(gsd.getRepository(), gsd
- .getSrcRev().getObjectId(), gsd.getDstRev().getObjectId());
+ .getSrcRevCommit(), gsd.getDstRevCommit());
} catch (IOException e) {
throw new TeamException(e.getMessage(), e);
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java
index abcfdb8f3..da1a320bf 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java
@@ -11,15 +11,9 @@
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
-import java.io.IOException;
-
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
-import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
-import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.variants.SessionResourceVariantByteStore;
@@ -31,22 +25,7 @@ class GitRemoteResourceVariantTree extends GitResourceVariantTree {
@Override
protected RevCommit getRevCommit(GitSynchronizeData gsd) throws TeamException {
- RevCommit result;
- Repository repo = gsd.getRepository();
- RevWalk rw = new RevWalk(repo);
- rw.setRevFilter(RevFilter.MERGE_BASE);
-
- try {
- Ref dstRef = gsd.getDstRev();
- if (dstRef == null)
- result = null;
- else
- result = rw.parseCommit(dstRef.getObjectId());
- } catch (IOException e) {
- throw new TeamException("", e); //$NON-NLS-1$
- }
-
- return result != null ? result : null;
+ return gsd.getDstRevCommit();
}
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java
index 10d1e06c2..6f0ce8017 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java
@@ -19,6 +19,8 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.ObjectWalk;
+import org.eclipse.jgit.revwalk.RevCommit;
/**
* Simple data transfer object containing all necessary information for
@@ -30,9 +32,9 @@ public class GitSynchronizeData {
private final Repository repo;
- private final Ref srcRev;
+ private final RevCommit srcRev;
- private final Ref dstRev;
+ private final RevCommit dstRev;
private final Set<IProject> projects;
@@ -52,8 +54,14 @@ public class GitSynchronizeData {
public GitSynchronizeData(Repository repository, String srcRev,
String dstRev, boolean includeLocal) throws IOException {
repo = repository;
- this.srcRev = repo.getRef(srcRev);
- this.dstRev = repo.getRef(dstRev);
+
+ Ref srcRef = repo.getRef(srcRev);
+ Ref dstRef = repo.getRef(dstRev);
+ ObjectWalk ow = new ObjectWalk(repo);
+
+ this.srcRev = ow.parseCommit(srcRef.getObjectId());
+ this.dstRev = ow.parseCommit(dstRef.getObjectId());
+
this.includeLocal = includeLocal;
repoParentPath = repo.getDirectory().getParentFile().getAbsolutePath();
@@ -78,14 +86,14 @@ public class GitSynchronizeData {
/**
* @return synchronize source rev name
*/
- public Ref getSrcRev() {
+ public RevCommit getSrcRevCommit() {
return srcRev;
}
/**
* @return synchronize destination rev name
*/
- public Ref getDstRev() {
+ public RevCommit getDstRevCommit() {
return dstRev;
}
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 7de351992..dfddbfdb9 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
@@ -27,7 +27,6 @@ import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevCommitList;
import org.eclipse.jgit.revwalk.RevObject;
@@ -62,13 +61,8 @@ public class GitModelRepository extends GitModelObject {
Set<IProject> projectSet = data.getProjects();
projects = projectSet.toArray(new IProject[projectSet.size()]);
- ObjectWalk ow = new ObjectWalk(repo);
- ow.markStart(ow.parseAny(data.getSrcRev().getObjectId()));
- srcRev = ow.next();
-
- ow.reset();
- ow.markStart(ow.parseAny(data.getDstRev().getObjectId()));
- dstRev = ow.next();
+ srcRev = data.getSrcRevCommit();
+ dstRev = data.getDstRevCommit();
}
@Override

Back to the top