Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Hohenegger2015-05-16 08:26:58 -0400
committerMax Hohenegger2015-05-18 08:00:34 -0400
commit4558da7a8d900efe2e2c434ef4dac1685d12eca0 (patch)
tree9ce3d2342fa446f29889f8e1bb9f34713236703c
parentd9e1cd1f26f7a636c700b18ca9a94f6b9b101d13 (diff)
downloadegit-4558da7a8d900efe2e2c434ef4dac1685d12eca0.tar.gz
egit-4558da7a8d900efe2e2c434ef4dac1685d12eca0.tar.xz
egit-4558da7a8d900efe2e2c434ef4dac1685d12eca0.zip
[gitflow] fixed unnecessary locking of resources
Bug: 348610 Change-Id: I370109d91e55719a3850cab4a7bb054fcfaa82a9 Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu>
-rw-r--r--org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/GitFlowRepositoryTest.java15
-rw-r--r--org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationTest.java6
-rw-r--r--org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/HotfixStartOperationTest.java5
-rw-r--r--org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/ReleaseStartOperationTest.java53
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java4
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/FeatureStartOperation.java6
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/HotfixStartOperation.java6
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/ReleaseStartOperation.java43
8 files changed, 125 insertions, 13 deletions
diff --git a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/GitFlowRepositoryTest.java b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/GitFlowRepositoryTest.java
index 62a8fab98..5380c936b 100644
--- a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/GitFlowRepositoryTest.java
+++ b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/GitFlowRepositoryTest.java
@@ -14,10 +14,14 @@ import static org.eclipse.egit.gitflow.GitFlowDefaults.HOTFIX_PREFIX;
import static org.eclipse.egit.gitflow.GitFlowDefaults.RELEASE_PREFIX;
import static org.eclipse.egit.gitflow.GitFlowDefaults.VERSION_TAG;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
+import static org.eclipse.jgit.lib.Constants.DOT_GIT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
+import java.io.File;
+
+import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.gitflow.op.AbstractDualRepositoryTestCase;
import org.eclipse.egit.gitflow.op.FeatureStartOperation;
import org.eclipse.egit.gitflow.op.HotfixStartOperation;
@@ -29,6 +33,15 @@ import org.eclipse.jgit.lib.Repository;
import org.junit.Test;
public class GitFlowRepositoryTest extends AbstractDualRepositoryTestCase {
+ @Test(expected = WrongGitFlowStateException.class)
+ public void testFindHeadFailOnEmptyRepository() throws Exception {
+ File workdir3 = testUtils.createTempDir("Repository3");
+ TestRepository repository3 = new TestRepository(new File(workdir3, DOT_GIT));
+ GitFlowRepository gfRepo = new GitFlowRepository(repository3.getRepository());
+
+ gfRepo.findHead();
+ }
+
@Test
public void testIsMaster() throws Exception {
repository1.createInitialCommit("testIsMaster\n\nfirst commit\n");
diff --git a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationTest.java b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationTest.java
index 55771a711..1fd6aa03f 100644
--- a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationTest.java
+++ b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationTest.java
@@ -8,7 +8,7 @@
*******************************************************************************/
package org.eclipse.egit.gitflow.op;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.op.BranchOperation;
@@ -22,7 +22,9 @@ public class FeatureStartOperationTest extends AbstractFeatureOperationTest {
Repository repository = testRepository.getRepository();
GitFlowRepository gfRepo = init("testFeatureStart\n\nfirst commit\n");
- new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);
+ FeatureStartOperation featureStartOperation = new FeatureStartOperation(gfRepo, MY_FEATURE);
+ assertNull(featureStartOperation.getSchedulingRule());
+ featureStartOperation.execute(null);
assertEquals(gfRepo.getConfig().getFullFeatureBranchName(MY_FEATURE),
repository.getFullBranch());
diff --git a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/HotfixStartOperationTest.java b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/HotfixStartOperationTest.java
index 77ea7da9e..a46799b3a 100644
--- a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/HotfixStartOperationTest.java
+++ b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/HotfixStartOperationTest.java
@@ -9,6 +9,7 @@
package org.eclipse.egit.gitflow.op;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.jgit.lib.Repository;
@@ -23,7 +24,9 @@ public class HotfixStartOperationTest extends AbstractGitFlowOperationTest {
new InitOperation(repository).execute(null);
GitFlowRepository gfRepo = new GitFlowRepository(repository);
- new HotfixStartOperation(gfRepo, MY_HOTFIX).execute(null);
+ HotfixStartOperation hotfixStartOperation = new HotfixStartOperation(gfRepo, MY_HOTFIX);
+ assertNull(hotfixStartOperation.getSchedulingRule());
+ hotfixStartOperation.execute(null);
assertEquals(gfRepo.getConfig().getFullHotfixBranchName(MY_HOTFIX),
repository.getFullBranch());
diff --git a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/ReleaseStartOperationTest.java b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/ReleaseStartOperationTest.java
index 53f9a0f2e..2fc372462 100644
--- a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/ReleaseStartOperationTest.java
+++ b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/ReleaseStartOperationTest.java
@@ -8,8 +8,7 @@
*******************************************************************************/
package org.eclipse.egit.gitflow.op;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.op.TagOperation;
@@ -23,19 +22,65 @@ public class ReleaseStartOperationTest extends AbstractGitFlowOperationTest {
@Test
public void testReleaseBranchCreated() throws Exception {
testRepository
- .createInitialCommit("testReleaseStart\n\nfirst commit\n");
+ .createInitialCommit("testReleaseBranchCreated\n\nfirst commit\n");
Repository repository = testRepository.getRepository();
new InitOperation(repository).execute(null);
GitFlowRepository gfRepo = new GitFlowRepository(repository);
- new ReleaseStartOperation(gfRepo, MY_RELEASE).execute(null);
+ ReleaseStartOperation releaseStartOperation = new ReleaseStartOperation(
+ gfRepo, MY_RELEASE);
+ releaseStartOperation.execute(null);
+
+ assertNull(releaseStartOperation.getSchedulingRule());
+
+ assertEquals(gfRepo.getConfig().getFullReleaseBranchName(MY_RELEASE),
+ repository.getFullBranch());
+ }
+
+ @Test
+ public void testReleaseBranchCreatedFromHeadCommit() throws Exception {
+ RevCommit initialCommit = testRepository
+ .createInitialCommit("testReleaseBranchCreatedFromHeadCommit\n\nfirst commit\n");
+
+ Repository repository = testRepository.getRepository();
+ new InitOperation(repository).execute(null);
+ GitFlowRepository gfRepo = new GitFlowRepository(repository);
+
+ ReleaseStartOperation releaseStartOperation = new ReleaseStartOperation(
+ gfRepo, initialCommit.getName(), MY_RELEASE);
+ releaseStartOperation.execute(null);
+
+ assertNull(releaseStartOperation.getSchedulingRule());
assertEquals(gfRepo.getConfig().getFullReleaseBranchName(MY_RELEASE),
repository.getFullBranch());
}
@Test
+ public void testReleaseBranchCreatedFromCommit() throws Exception {
+ RevCommit initialCommit = testRepository
+ .createInitialCommit("testReleaseBranchCreatedFromCommit\n\nfirst commit\n");
+ testRepository
+ .createInitialCommit("testReleaseBranchCreatedFromCommit\n\nsecond commit\n");
+
+ Repository repository = testRepository.getRepository();
+ new InitOperation(repository).execute(null);
+ GitFlowRepository gfRepo = new GitFlowRepository(repository);
+
+ ReleaseStartOperation releaseStartOperation = new ReleaseStartOperation(
+ gfRepo, initialCommit.getName(), MY_RELEASE);
+ releaseStartOperation.execute(null);
+
+ assertNotNull(releaseStartOperation.getSchedulingRule());
+
+ assertEquals(gfRepo.getConfig().getFullReleaseBranchName(MY_RELEASE),
+ repository.getFullBranch());
+
+ assertEquals(initialCommit, gfRepo.findHead());
+ }
+
+ @Test
public void testReleaseStartWithContent() throws Exception {
testRepository
.createInitialCommit("testReleaseStartWithContent\n\nfirst commit\n");
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java
index 753988232..a41893a4c 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java
@@ -137,6 +137,10 @@ public class GitFlowRepository {
try (RevWalk walk = new RevWalk(repository)) {
try {
ObjectId head = repository.resolve(HEAD);
+ if (head == null) {
+ throw new WrongGitFlowStateException(
+ CoreText.GitFlowRepository_gitFlowRepositoryMayNotBeEmpty);
+ }
return walk.parseCommit(head);
} catch (MissingObjectException e) {
throw new WrongGitFlowStateException(CoreText.GitFlowRepository_gitFlowRepositoryMayNotBeEmpty);
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/FeatureStartOperation.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/FeatureStartOperation.java
index 6f7d2e568..afd578c31 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/FeatureStartOperation.java
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/FeatureStartOperation.java
@@ -14,6 +14,7 @@ import java.io.IOException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.WrongGitFlowStateException;
import org.eclipse.egit.gitflow.internal.CoreText;
@@ -53,4 +54,9 @@ public final class FeatureStartOperation extends AbstractFeatureOperation {
}
start(monitor, branchName, head);
}
+
+ @Override
+ public ISchedulingRule getSchedulingRule() {
+ return null;
+ }
}
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/HotfixStartOperation.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/HotfixStartOperation.java
index eca9834a7..ebd84798a 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/HotfixStartOperation.java
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/HotfixStartOperation.java
@@ -10,6 +10,7 @@ package org.eclipse.egit.gitflow.op;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.egit.gitflow.GitFlowRepository;
/**
@@ -30,4 +31,9 @@ public final class HotfixStartOperation extends AbstractHotfixOperation {
start(monitor, branchName, repository.findHead(repository.getConfig().getMaster()));
}
+
+ @Override
+ public ISchedulingRule getSchedulingRule() {
+ return null;
+ }
}
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/ReleaseStartOperation.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/ReleaseStartOperation.java
index f61664e13..9112f0bfc 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/ReleaseStartOperation.java
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/ReleaseStartOperation.java
@@ -14,6 +14,7 @@ import static java.lang.String.format;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import static org.eclipse.egit.gitflow.Activator.error;
import static org.eclipse.jgit.lib.Constants.*;
@@ -33,6 +34,8 @@ import org.eclipse.osgi.util.NLS;
public final class ReleaseStartOperation extends AbstractReleaseOperation {
private String startCommitSha1;
+ private boolean isHead;
+
/**
* start release from given commit
*
@@ -42,8 +45,7 @@ public final class ReleaseStartOperation extends AbstractReleaseOperation {
*/
public ReleaseStartOperation(GitFlowRepository repository,
String startCommitSha1, String releaseName) {
- super(repository, releaseName);
- this.startCommitSha1 = startCommitSha1;
+ this(repository, startCommitSha1, releaseName, isHead(repository, startCommitSha1));
}
/**
@@ -51,12 +53,17 @@ public final class ReleaseStartOperation extends AbstractReleaseOperation {
*
* @param repository
* @param releaseName
- * @throws WrongGitFlowStateException
*/
public ReleaseStartOperation(GitFlowRepository repository,
- String releaseName) throws WrongGitFlowStateException {
+ String releaseName) {
+ this(repository, findHead(repository), releaseName, true);
+ }
+
+ private ReleaseStartOperation(GitFlowRepository repository,
+ String startCommitSha1, String releaseName, boolean isHead) {
super(repository, releaseName);
- this.startCommitSha1 = repository.findHead().getName();
+ this.startCommitSha1 = startCommitSha1;
+ this.isHead = isHead;
}
@Override
@@ -98,4 +105,30 @@ public final class ReleaseStartOperation extends AbstractReleaseOperation {
return null != repository.getRepository().resolve(
R_TAGS + repository.getConfig().getVersionTagPrefix() + versionName);
}
+
+ @Override
+ public ISchedulingRule getSchedulingRule() {
+ if (isHead) {
+ return null;
+ } else {
+ return super.getSchedulingRule();
+ }
+ }
+
+ private static boolean isHead(final GitFlowRepository gfRepo, final String sha1) {
+ try {
+ RevCommit head = gfRepo.findHead();
+ return sha1.equals(head.getName());
+ } catch (WrongGitFlowStateException e) {
+ return false;
+ }
+ }
+
+ private static String findHead(GitFlowRepository repository) {
+ try {
+ return repository.findHead().getName();
+ } catch (WrongGitFlowStateException e) {
+ throw new IllegalStateException(e);
+ }
+ }
}

Back to the top