Skip to content

The Unified and Autonomous Development Platform

Removed branch model to avoid sync issue between db and git

robin shine0e37b79ac5e3
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Git.java b/commons.git/src/main/java/com/pmease/commons/git/Git.java
index 02fc063f22..ab4c28000c 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/Git.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/Git.java
@@ -97,7 +97,7 @@ public class Git implements Serializable {
throw new GeneralException(String.format("Branch %s already exists.", branchName));
new UpdateRefCommand(repoDir).refName(Git.REFS_HEADS + branchName).revision(commitHash)
- .call();
+ .oldRevision(GitUtils.NULL_SHA1).call();
return this;
}
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
index eee156132a..8f8a045526 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
@@ -159,4 +159,25 @@ public class GitUtils {
return joinPath(splitPath(path));
}
+
+ /**
+ * Convert a git reference name to branch name.
+ *
+ * @param refName
+ * name of the git reference
+ * @return
+ * name of the branch, or <tt>null</tt> if specified ref
+ * does not represent a branch
+ */
+ public static @Nullable String ref2branch(String refName) {
+ if (refName.startsWith(Git.REFS_HEADS))
+ return refName.substring(Git.REFS_HEADS.length());
+ else
+ return null;
+ }
+
+ public static String branch2ref(String branch) {
+ return Git.REFS_HEADS + branch;
+ }
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
index a3ab739468..523f0bfb13 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
@@ -20,8 +20,8 @@ import com.pmease.commons.util.ClassUtils;
import com.pmease.gitplex.core.listeners.ConfigListener;
import com.pmease.gitplex.core.listeners.LifecycleListener;
import com.pmease.gitplex.core.listeners.PullRequestListener;
+import com.pmease.gitplex.core.listeners.RepositoryListener;
import com.pmease.gitplex.core.manager.AuthorizationManager;
-import com.pmease.gitplex.core.manager.BranchManager;
import com.pmease.gitplex.core.manager.BranchWatchManager;
import com.pmease.gitplex.core.manager.ConfigManager;
import com.pmease.gitplex.core.manager.DataManager;
@@ -41,7 +41,6 @@ import com.pmease.gitplex.core.manager.TeamManager;
import com.pmease.gitplex.core.manager.UserManager;
import com.pmease.gitplex.core.manager.VerificationManager;
import com.pmease.gitplex.core.manager.impl.DefaultAuthorizationManager;
-import com.pmease.gitplex.core.manager.impl.DefaultBranchManager;
import com.pmease.gitplex.core.manager.impl.DefaultBranchWatchManager;
import com.pmease.gitplex.core.manager.impl.DefaultConfigManager;
import com.pmease.gitplex.core.manager.impl.DefaultDataManager;
@@ -139,7 +138,6 @@ public class CoreModule extends AbstractPluginModule {
*/
bind(StorageManager.class).to(DefaultStorageManager.class);
bind(AuthorizationManager.class).to(DefaultAuthorizationManager.class);
- bind(BranchManager.class).to(DefaultBranchManager.class);
bind(ConfigManager.class).to(DefaultConfigManager.class);
bind(DataManager.class).to(DefaultDataManager.class);
bind(PullRequestCommentManager.class).to(DefaultPullRequestCommentManager.class);
@@ -159,11 +157,11 @@ public class CoreModule extends AbstractPluginModule {
bind(PullRequestNotificationManager.class).to(DefaultPullRequestNotificationManager.class);
bind(AbstractRealm.class).to(SecurityRealm.class);
-
+
+ contribute(RepositoryListener.class, DefaultPullRequestManager.class);
contribute(PullRequestListener.class, DefaultPullRequestNotificationManager.class);
contribute(PullRequestListener.class, DefaultPullRequestWatchManager.class);
contribute(ConfigListener.class, DefaultPullRequestManager.class);
- contribute(LifecycleListener.class, DefaultBranchManager.class);
contribute(LifecycleListener.class, DefaultPullRequestManager.class);
contribute(LifecycleListener.class, DefaultUserManager.class);
contribute(LifecycleListener.class, DefaultRepositoryManager.class);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/AffinalBranchMatcher.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/AffinalBranchMatcher.java
index bd27d584f8..836f7989ef 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/AffinalBranchMatcher.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/AffinalBranchMatcher.java
@@ -4,9 +4,9 @@ import java.io.Serializable;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.util.trimmable.Trimmable;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.Repository;
@Editable
-public interface AffinalBranchMatcher extends Trimmable, Serializable {
- boolean matches(Branch branch);
+public interface AffinalBranchMatcher extends Serializable, Trimmable {
+ boolean matches(Repository repository, String branch);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/GlobalBranchMatcher.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/GlobalBranchMatcher.java
index 8a5b6b413e..e64bdadf26 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/GlobalBranchMatcher.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/GlobalBranchMatcher.java
@@ -4,9 +4,9 @@ import java.io.Serializable;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.util.trimmable.Trimmable;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.Repository;
@Editable
public interface GlobalBranchMatcher extends Trimmable, Serializable {
- boolean matches(Branch branch);
+ boolean matches(Repository repository, String branch);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/LocalBranchMatcher.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/LocalBranchMatcher.java
index 7640a2819d..58dee91a51 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/LocalBranchMatcher.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/LocalBranchMatcher.java
@@ -3,10 +3,8 @@ package com.pmease.gitplex.core.branchmatcher;
import java.io.Serializable;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.commons.util.trimmable.Trimmable;
-import com.pmease.gitplex.core.model.Branch;
@Editable
-public interface LocalBranchMatcher extends Trimmable, Serializable {
- boolean matches(Branch branch);
+public interface LocalBranchMatcher extends Serializable {
+ boolean matches(String branch);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByIds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByNames.java
similarity index 53%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByIds.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByNames.java
index c65880e1d4..791d1c8243 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByIds.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByNames.java
@@ -8,35 +8,34 @@ import javax.validation.constraints.Size;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitName;
-import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.editable.BranchChoice;
import com.pmease.gitplex.core.editable.BranchChoice.Scope;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
+import com.pmease.gitplex.core.model.Repository;
@SuppressWarnings("serial")
@Editable(name="Specify Branch Names", order=100)
-public class MatchAffinalBranchesByIds implements AffinalBranchMatcher {
+public class MatchAffinalBranchesByNames implements AffinalBranchMatcher {
- private List<Long> branchIds = new ArrayList<>();
+ private List<RepoAndBranch> repoAndBranches = new ArrayList<>();
@Editable(name="Branch Names")
@BranchChoice(Scope.AFFINAL)
@OmitName
@NotNull
@Size(min=1, message="At least one branch has to be selected.")
- public List<Long> getBranchIds() {
- return branchIds;
+ public List<RepoAndBranch> getRepoAndBranches() {
+ return repoAndBranches;
}
- public void setBranchIds(List<Long> branchIds) {
- this.branchIds = branchIds;
+ public void setRepoAndBranches(List<RepoAndBranch> repoAndBranches) {
+ this.repoAndBranches = repoAndBranches;
}
@Override
- public boolean matches(Branch branch) {
- for (Long branchId: getBranchIds()) {
- if (branchId.equals(branch.getId()))
+ public boolean matches(Repository repository, String branch) {
+ for (RepoAndBranch each: getRepoAndBranches()) {
+ if (each.getRepoId().equals(repository.getId()) && each.getBranch().equals(branch))
return true;
}
return false;
@@ -44,11 +43,11 @@ public class MatchAffinalBranchesByIds implements AffinalBranchMatcher {
@Override
public Object trim(Object context) {
- GitPlex.getInstance(BranchManager.class).trim(branchIds);
- if (branchIds.isEmpty())
- return null;
- else
+ RepoAndBranch.trim(repoAndBranches);
+ if (!repoAndBranches.isEmpty())
return this;
+ else
+ return null;
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByPatterns.java
index e4422b5fc6..d6f735471e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByPatterns.java
@@ -5,7 +5,7 @@ import org.hibernate.validator.constraints.NotEmpty;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitName;
import com.pmease.commons.util.pattern.WildcardUtils;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.Repository;
@SuppressWarnings("serial")
@Editable(order=200, name="Specify Branch Patterns")
@@ -28,13 +28,13 @@ public class MatchAffinalBranchesByPatterns implements AffinalBranchMatcher {
}
@Override
- public Object trim(Object context) {
- return this;
+ public boolean matches(Repository repository, String branch) {
+ return WildcardUtils.matchPath(getBranchPatterns(), repository.getBranchFQN(branch));
}
@Override
- public boolean matches(Branch branch) {
- return WildcardUtils.matchPath(getBranchPatterns(), branch.getFQN());
+ public Object trim(Object context) {
+ return this;
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllAffinalBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllAffinalBranches.java
index f4c11c3b1d..5ca1e3a106 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllAffinalBranches.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllAffinalBranches.java
@@ -1,7 +1,7 @@
package com.pmease.gitplex.core.branchmatcher;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.Repository;
@SuppressWarnings("serial")
@Editable(name="All Branches from All Repositories", order=300)
@@ -13,7 +13,7 @@ public class MatchAllAffinalBranches implements AffinalBranchMatcher {
}
@Override
- public boolean matches(Branch branch) {
+ public boolean matches(Repository repository, String branch) {
return true;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllGlobalBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllGlobalBranches.java
index a835d2ced6..f1e36c3445 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllGlobalBranches.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllGlobalBranches.java
@@ -1,7 +1,7 @@
package com.pmease.gitplex.core.branchmatcher;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.Repository;
@SuppressWarnings("serial")
@Editable(name="All Branches from All Repositories", order=300)
@@ -13,7 +13,7 @@ public class MatchAllGlobalBranches implements GlobalBranchMatcher {
}
@Override
- public boolean matches(Branch branch) {
+ public boolean matches(Repository repository, String branch) {
return true;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllLocalBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllLocalBranches.java
index b6bcb26a81..1916c35975 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllLocalBranches.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllLocalBranches.java
@@ -1,20 +1,14 @@
package com.pmease.gitplex.core.branchmatcher;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.gitplex.core.model.Branch;
@SuppressWarnings("serial")
@Editable(name="All Branches", order=300)
public class MatchAllLocalBranches implements LocalBranchMatcher {
@Override
- public boolean matches(Branch branch) {
+ public boolean matches(String branch) {
return true;
}
- @Override
- public Object trim(Object context) {
- return this;
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByIds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByNames.java
similarity index 53%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByIds.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByNames.java
index 6721b4f1f5..b129122b32 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByIds.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByNames.java
@@ -8,35 +8,34 @@ import javax.validation.constraints.Size;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitName;
-import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.editable.BranchChoice;
import com.pmease.gitplex.core.editable.BranchChoice.Scope;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
+import com.pmease.gitplex.core.model.Repository;
@SuppressWarnings("serial")
@Editable(name="Specify Branch Names", order=100)
-public class MatchGlobalBranchesByIds implements GlobalBranchMatcher {
+public class MatchGlobalBranchesByNames implements GlobalBranchMatcher {
- private List<Long> branchIds = new ArrayList<>();
+ private List<RepoAndBranch> repoAndBranches = new ArrayList<>();
@Editable(name="Branch Names")
@BranchChoice(Scope.GLOBAL)
@OmitName
@NotNull
@Size(min=1, message="At least one branch has to be selected.")
- public List<Long> getBranchIds() {
- return branchIds;
+ public List<RepoAndBranch> getRepoAndBranches() {
+ return repoAndBranches;
}
- public void setBranchIds(List<Long> branchIds) {
- this.branchIds = branchIds;
+ public void setRepoAndBranches(List<RepoAndBranch> repoAndBranches) {
+ this.repoAndBranches = repoAndBranches;
}
@Override
- public boolean matches(Branch branch) {
- for (Long branchId: getBranchIds()) {
- if (branchId.equals(branch.getId()))
+ public boolean matches(Repository repository, String branch) {
+ for (RepoAndBranch each: getRepoAndBranches()) {
+ if (each.getRepoId().equals(repository.getId()) && each.getBranch().equals(branch))
return true;
}
return false;
@@ -44,11 +43,11 @@ public class MatchGlobalBranchesByIds implements GlobalBranchMatcher {
@Override
public Object trim(Object context) {
- GitPlex.getInstance(BranchManager.class).trim(branchIds);
- if (branchIds.isEmpty())
- return null;
- else
+ RepoAndBranch.trim(repoAndBranches);
+ if (!repoAndBranches.isEmpty())
return this;
+ else
+ return null;
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByPatterns.java
index 7c5b718039..dfe2817e36 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByPatterns.java
@@ -5,7 +5,7 @@ import org.hibernate.validator.constraints.NotEmpty;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitName;
import com.pmease.commons.util.pattern.WildcardUtils;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.Repository;
@SuppressWarnings("serial")
@Editable(order=200, name="Specify Branch Patterns")
@@ -33,8 +33,8 @@ public class MatchGlobalBranchesByPatterns implements GlobalBranchMatcher {
}
@Override
- public boolean matches(Branch branch) {
- return WildcardUtils.matchPath(getBranchPatterns(), branch.getFQN());
+ public boolean matches(Repository repository, String branch) {
+ return WildcardUtils.matchPath(getBranchPatterns(), repository.getBranchFQN(branch));
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByIds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByIds.java
deleted file mode 100644
index 2563ff0033..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByIds.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.pmease.gitplex.core.branchmatcher;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.commons.editable.annotation.OmitName;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.editable.BranchChoice;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
-
-@SuppressWarnings("serial")
-@Editable(name="Specify Branch Names", order=100)
-public class MatchLocalBranchesByIds implements LocalBranchMatcher {
-
- private List<Long> branchIds = new ArrayList<>();
-
- @Editable(name="Branch Names")
- @BranchChoice
- @OmitName
- @NotNull
- @Size(min=1, message="At least one branch has to be selected.")
- public List<Long> getBranchIds() {
- return branchIds;
- }
-
- public void setBranchIds(List<Long> branchIds) {
- this.branchIds = branchIds;
- }
-
- @Override
- public boolean matches(Branch branch) {
- for (Long branchId: getBranchIds()) {
- if (branchId.equals(branch.getId()))
- return true;
- }
- return false;
- }
-
- @Override
- public Object trim(Object context) {
- GitPlex.getInstance(BranchManager.class).trim(branchIds);
- if (branchIds.isEmpty())
- return null;
- else
- return this;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByNames.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByNames.java
new file mode 100644
index 0000000000..985ab175ef
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByNames.java
@@ -0,0 +1,41 @@
+package com.pmease.gitplex.core.branchmatcher;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.pmease.commons.editable.annotation.Editable;
+import com.pmease.commons.editable.annotation.OmitName;
+import com.pmease.gitplex.core.editable.BranchChoice;
+
+@SuppressWarnings("serial")
+@Editable(name="Specify Branch Names", order=100)
+public class MatchLocalBranchesByNames implements LocalBranchMatcher {
+
+ private List<String> branches = new ArrayList<>();
+
+ @Editable(name="Branch Names")
+ @BranchChoice
+ @OmitName
+ @NotNull
+ @Size(min=1, message="At least one branch has to be selected.")
+ public List<String> getBranches() {
+ return branches;
+ }
+
+ public void setBranches(List<String> branches) {
+ this.branches = branches;
+ }
+
+ @Override
+ public boolean matches(String branch) {
+ for (String each: getBranches()) {
+ if (each.equals(branch))
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByPatterns.java
index c72d2c8f45..b767713e05 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByPatterns.java
@@ -5,7 +5,6 @@ import org.hibernate.validator.constraints.NotEmpty;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitName;
import com.pmease.commons.util.pattern.WildcardUtils;
-import com.pmease.gitplex.core.model.Branch;
@SuppressWarnings("serial")
@Editable(order=200, name="Specify Branch Patterns")
@@ -26,13 +25,8 @@ public class MatchLocalBranchesByPatterns implements LocalBranchMatcher {
}
@Override
- public Object trim(Object context) {
- return this;
- }
-
- @Override
- public boolean matches(Branch branch) {
- return WildcardUtils.matchPath(getBranchPatterns(), branch.getName());
+ public boolean matches(String branch) {
+ return WildcardUtils.matchPath(getBranchPatterns(), branch);
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
index fbc810a8ed..40f44ccb46 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
@@ -37,7 +37,7 @@ public class ChangeComments implements Serializable {
if (change.getNewPath() != null) {
int end = commits.indexOf(change.getNewRev());
Preconditions.checkState(end != -1);
- if (!getContent(blobs, change.getNewBlobInfo(), request.getTarget().getRepository()).isEmpty()) {
+ if (!getContent(blobs, change.getNewBlobInfo(), request.getTargetRepo()).isEmpty()) {
for (int i=commits.size()-1; i>end; i--) {
String commit = commits.get(i);
Map<String, List<InlineComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, request);
@@ -45,9 +45,9 @@ public class ChangeComments implements Serializable {
if (commentsOnFile != null) {
Preconditions.checkState(!commentsOnFile.isEmpty());
BlobIdent blobInfo = commentsOnFile.get(0).getBlobInfo();
- List<String> fileContent = getContent(blobs, blobInfo, request.getTarget().getRepository());
+ List<String> fileContent = getContent(blobs, blobInfo, request.getTargetRepo());
if (!fileContent.isEmpty()) {
- List<String> newContent = getContent(blobs, change.getNewBlobInfo(), request.getTarget().getRepository());
+ List<String> newContent = getContent(blobs, change.getNewBlobInfo(), request.getTargetRepo());
Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);
for (InlineComment comment: commentsOnFile) {
Integer line = lineMap.get(comment.getLine());
@@ -69,7 +69,7 @@ public class ChangeComments implements Serializable {
if (change.getOldPath() != null) {
int begin = commits.indexOf(change.getOldRev());
Preconditions.checkState(begin != -1);
- if (!getContent(blobs, change.getOldBlobInfo(), request.getTarget().getRepository()).isEmpty()
+ if (!getContent(blobs, change.getOldBlobInfo(), request.getTargetRepo()).isEmpty()
&& !change.getOldRev().equals(change.getNewRev())) {
List<InlineComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRev(), request).get(change.getOldPath());
if (commentsOnFile != null) {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
index 6930d999c7..969f5cd8ab 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
@@ -12,7 +12,6 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
import com.pmease.gitplex.core.gatekeeper.checkresult.Ignored;
import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -40,17 +39,17 @@ public abstract class AbstractGateKeeper implements GateKeeper {
}
@Override
- public CheckResult checkFile(User user, Branch branch, String file) {
+ public CheckResult checkFile(User user, Repository repository, String branch, String file) {
if (isEnabled())
- return doCheckFile(user, branch, file);
+ return doCheckFile(user, repository, branch, file);
else
return ignored();
}
@Override
- public CheckResult checkCommit(User user, Branch branch, String commit) {
+ public CheckResult checkCommit(User user, Repository repository, String branch, String commit) {
if (isEnabled())
- return doCheckCommit(user, branch, commit);
+ return doCheckCommit(user, repository, branch, commit);
else
return ignored();
}
@@ -86,7 +85,7 @@ public abstract class AbstractGateKeeper implements GateKeeper {
* @return
* result of the check
*/
- protected abstract CheckResult doCheckFile(User user, Branch branch, String file);
+ protected abstract CheckResult doCheckFile(User user, Repository repository, String branch, String file);
/**
* Check if specified user can push specified commit to specified branch, without considering enable flag.
@@ -100,7 +99,7 @@ public abstract class AbstractGateKeeper implements GateKeeper {
* @return
* result of the check
*/
- protected abstract CheckResult doCheckCommit(User user, Branch branch, String commit);
+ protected abstract CheckResult doCheckCommit(User user, Repository repository, String branch, String commit);
/**
* Check if specified user can create/delete specified reference in specified repository,
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java
index 5dda6ce70c..838dfd86e8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java
@@ -11,10 +11,9 @@ import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.editable.TeamChoice;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;
+import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSelection;
import com.pmease.gitplex.core.manager.TeamManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Team;
@@ -27,7 +26,7 @@ import com.pmease.gitplex.core.model.User;
+ "specified branches to specified teams.")
public class BranchProtection extends AbstractGateKeeper {
- private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();
+ private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByNames();
private List<Long> teamIds = new ArrayList<>();
@@ -56,9 +55,6 @@ public class BranchProtection extends AbstractGateKeeper {
@Override
protected GateKeeper trim(Repository repository) {
- if (branchSelection.trim(repository) == null)
- return null;
-
GitPlex.getInstance(TeamManager.class).trim(teamIds);
if (teamIds.isEmpty())
return null;
@@ -90,13 +86,13 @@ public class BranchProtection extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return getGateKeeper().checkFile(user, branch, file);
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return getGateKeeper().checkFile(user, repository, branch, file);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return getGateKeeper().checkCommit(user, branch, commit);
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return getGateKeeper().checkCommit(user, repository, branch, commit);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java
index 61272e666e..9e6ff09267 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java
@@ -6,11 +6,10 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;
+import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSelection;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@Editable(icon="fa-lock", order=300, category=GateKeeper.CATEGORY_COMMONLY_USED,
@@ -19,7 +18,7 @@ import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
public class BuildVerificationOfBranch extends AbstractGateKeeper {
- private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();
+ private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByNames();
private int buildCount = 1;
@@ -40,10 +39,7 @@ public class BuildVerificationOfBranch extends AbstractGateKeeper {
@Override
protected GateKeeper trim(Repository repository) {
- if (branchSelection.trim(repository) == null)
- return null;
- else
- return this;
+ return this;
}
@Editable(order=100, description="For each specified branch, this specified number of builds has to be "
@@ -97,13 +93,13 @@ public class BuildVerificationOfBranch extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return getGateKeeper().checkFile(user, branch, file);
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return getGateKeeper().checkFile(user, repository, branch, file);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return getGateKeeper().checkCommit(user, branch, commit);
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return getGateKeeper().checkCommit(user, repository, branch, commit);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java
index 863c621cd2..4625b7a769 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java
@@ -1,7 +1,6 @@
package com.pmease.gitplex.core.gatekeeper;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -28,24 +27,24 @@ public abstract class CompositeGateKeeper extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(final User user, final Branch branch, final String file) {
+ protected CheckResult doCheckFile(final User user, final Repository repository, final String branch, final String file) {
return aggregate(new Checker() {
@Override
public CheckResult check(GateKeeper gateKeeper) {
- return gateKeeper.checkFile(user, branch, file);
+ return gateKeeper.checkFile(user, repository, branch, file);
}
});
}
@Override
- protected CheckResult doCheckCommit(final User user, final Branch branch, final String commit) {
+ protected CheckResult doCheckCommit(final User user, final Repository repository, final String branch, final String commit) {
return aggregate(new Checker() {
@Override
public CheckResult check(GateKeeper gateKeeper) {
- return gateKeeper.checkCommit(user, branch, commit);
+ return gateKeeper.checkCommit(user, repository, branch, commit);
}
});
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java
index ac7ef9360f..31e2dca649 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java
@@ -2,7 +2,6 @@ package com.pmease.gitplex.core.gatekeeper;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -22,12 +21,12 @@ public class DefaultGateKeeper extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return ignored();
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return ignored();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java
index 0bef3d099f..7c5531516c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java
@@ -16,9 +16,8 @@ import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSel
import com.pmease.gitplex.core.gatekeeper.helper.pathselection.SpecifyTargetPathsByDirectories;
import com.pmease.gitplex.core.gatekeeper.helper.pathselection.TargetPathSelection;
import com.pmease.gitplex.core.manager.TeamManager;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Team;
import com.pmease.gitplex.core.model.User;
@@ -72,9 +71,6 @@ public class DirectoryAndFileProtection extends AbstractGateKeeper {
@Override
protected GateKeeper trim(Repository repository) {
- if (branchSelection.trim(repository) == null)
- return null;
-
GitPlex.getInstance(TeamManager.class).trim(teamIds);
if (teamIds.isEmpty())
return null;
@@ -116,13 +112,13 @@ public class DirectoryAndFileProtection extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return getGateKeeper().checkFile(user, branch, file);
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return getGateKeeper().checkFile(user, repository, branch, file);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return getGateKeeper().checkCommit(user, branch, commit);
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return getGateKeeper().checkCommit(user, repository, branch, commit);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
index 4aac3897a1..b0109725e0 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
@@ -5,7 +5,6 @@ import java.io.Serializable;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.util.trimmable.Trimmable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.core.model.Repository;
@@ -50,7 +49,7 @@ public interface GateKeeper extends Trimmable, Serializable {
* @return
* result of the check.
*/
- CheckResult checkFile(User user, Branch branch, String file);
+ CheckResult checkFile(User user, Repository repository, String branch, String file);
/**
* Check if specified user can push specified commit to specified branch.
@@ -64,7 +63,7 @@ public interface GateKeeper extends Trimmable, Serializable {
* @return
* result of the check
*/
- CheckResult checkCommit(User user, Branch branch, String commit);
+ CheckResult checkCommit(User user, Repository repository, String branch, String commit);
/**
* Check if specified user can push specified reference to specified repository.
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java
index 476372af69..46534ccc6e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java
@@ -5,11 +5,10 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;
+import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSelection;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -17,7 +16,7 @@ import com.pmease.gitplex.core.model.User;
"Use this gate keeper to prevent history of certain branches from being rewritten via forced push.")
public class HistoryProtection extends AbstractGateKeeper {
- private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();
+ private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByNames();
@Editable(name="Branches to Be Protected", order=100)
@Valid
@@ -32,10 +31,7 @@ public class HistoryProtection extends AbstractGateKeeper {
@Override
protected GateKeeper trim(Repository repository) {
- if (branchSelection.trim(repository) == null)
- return null;
- else
- return this;
+ return this;
}
private GateKeeper getGateKeeper() {
@@ -52,13 +48,13 @@ public class HistoryProtection extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return getGateKeeper().checkFile(user, branch, file);
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return getGateKeeper().checkFile(user, repository, branch, file);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return getGateKeeper().checkCommit(user, branch, commit);
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return getGateKeeper().checkCommit(user, repository, branch, commit);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java
index 6fc16843f7..af7e401f6e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java
@@ -2,12 +2,11 @@ package com.pmease.gitplex.core.gatekeeper;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
+import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -36,8 +35,8 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- CheckResult result = getGateKeeper().checkFile(user, branch, file);
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ CheckResult result = getGateKeeper().checkFile(user, repository, branch, file);
if (result instanceof Passed)
result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));
@@ -48,8 +47,8 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- CheckResult result = getGateKeeper().checkCommit(user, branch, commit);
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ CheckResult result = getGateKeeper().checkCommit(user, repository, branch, commit);
if (result instanceof Passed)
result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java
index 5e7f041af1..91efcf97ca 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java
@@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Review;
@@ -17,7 +16,7 @@ public class IfApprovedByRepositoryOwner extends AbstractGateKeeper {
@Override
public CheckResult doCheckRequest(PullRequest request) {
- User repoOwner = request.getTarget().getRepository().getOwner();
+ User repoOwner = request.getTargetRepo().getOwner();
Review.Result result = repoOwner.checkReviewSince(request.getReferentialUpdate());
@@ -39,13 +38,13 @@ public class IfApprovedByRepositoryOwner extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return check(user, repository);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return check(user, repository);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java
index 0b7853e9f7..ba1a88d420 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java
@@ -7,7 +7,6 @@ import javax.validation.constraints.Min;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Review;
@@ -36,7 +35,7 @@ public class IfApprovedByRepositoryWriters extends AbstractGateKeeper {
@Override
public CheckResult doCheckRequest(PullRequest request) {
Collection<User> authorizedUsers = SecurityUtils.findUsersCan(
- request.getTarget().getRepository(), RepositoryOperation.PUSH);
+ request.getTargetRepo(), RepositoryOperation.PUSH);
int approvals = 0;
int pendings = 0;
@@ -85,13 +84,13 @@ public class IfApprovedByRepositoryWriters extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return check(user, repository);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return check(user, repository);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java
index 4aa2607eda..1bffe145a1 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java
@@ -8,7 +8,6 @@ import javax.validation.constraints.Min;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
@@ -94,12 +93,12 @@ public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return check(user);
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java
index 5a96d8ce4d..2e1fd90193 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java
@@ -9,7 +9,6 @@ import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.editable.UserChoice;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Review;
@@ -67,12 +66,12 @@ public class IfApprovedBySpecifiedUser extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return check(user);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java
index ebd8b10fc8..5312b31e15 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java
@@ -8,7 +8,6 @@ import javax.validation.constraints.Min;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
@@ -130,12 +129,12 @@ public class IfGetMinScoreFromSpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return check(user);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java
index 7eb417c315..f41750dffa 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java
@@ -3,12 +3,11 @@ package com.pmease.gitplex.core.gatekeeper;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Membership;
-import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.User;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Review;
+import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@Editable(order=600, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=
@@ -28,12 +27,12 @@ public class IfNotDisapprovedBySpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "'."));
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "'."));
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java
index 0cad138c7f..c2ea8bcd11 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java
@@ -4,9 +4,9 @@ import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.util.pattern.WildcardUtils;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -36,17 +36,17 @@ public class IfPushToSpecifiedRefs extends AbstractGateKeeper {
@Override
protected CheckResult doCheckRequest(PullRequest request) {
- return doCheckRef(request.getSubmitter(), request.getTarget().getRepository(), request.getTarget().getHeadRef());
+ return doCheckRef(request.getSubmitter(), request.getTargetRepo(), request.getTargetRef());
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return doCheckRef(user, branch.getRepository(), branch.getHeadRef());
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return doCheckRef(user, repository, GitUtils.branch2ref(branch));
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return doCheckRef(user, branch.getRepository(), branch.getHeadRef());
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return doCheckRef(user, repository, GitUtils.branch2ref(branch));
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java
index 0b0ce57672..d24ad47e71 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java
@@ -3,9 +3,8 @@ package com.pmease.gitplex.core.gatekeeper;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@Editable(order=100, icon="fa-ext fa-repo-lock", description="This gate keeper will be passed if the push "
@@ -21,13 +20,13 @@ public class IfPushWithoutRewritingHistory extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return ignored();
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- if (branch.getRepository().git().isAncestor(branch.getHeadCommitHash(), commit))
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ if (repository.git().isAncestor(repository.getObjectId(branch).name(), commit))
return passed(Lists.newArrayList("Push operation does not rewrite history."));
else
return failed(Lists.newArrayList("Push operation rewrites history."));
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java
index fe0b91c867..727d4933c0 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java
@@ -4,11 +4,11 @@ import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.util.pattern.WildcardUtils;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -35,8 +35,8 @@ public class IfSubmitToSpecifiedBranchPatterns extends AbstractGateKeeper {
this.branchPatterns = branchPatterns;
}
- private CheckResult checkBranch(String branchName) {
- if (WildcardUtils.matchPath(getBranchPatterns(), branchName))
+ private CheckResult checkBranch(Repository repository, String branch) {
+ if (WildcardUtils.matchPath(getBranchPatterns(), branch))
return passed(Lists.newArrayList("Target branch matches pattern '" + branchPatterns + "'."));
else
return failed(Lists.newArrayList("Target branch does not match pattern '" + branchPatterns + "'."));
@@ -44,24 +44,24 @@ public class IfSubmitToSpecifiedBranchPatterns extends AbstractGateKeeper {
@Override
public CheckResult doCheckRequest(PullRequest request) {
- return checkBranch(request.getTarget().getName());
+ return checkBranch(request.getTargetRepo(), request.getTargetBranch());
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return checkBranch(branch.getName());
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return checkBranch(repository, branch);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return checkBranch(branch.getName());
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return checkBranch(repository, branch);
}
@Override
protected CheckResult doCheckRef(User user, Repository repository, String refName) {
- String branchName = Branch.parseName(refName);
- if (branchName != null)
- return checkBranch(branchName);
+ String branch = GitUtils.ref2branch(refName);
+ if (branch != null)
+ return checkBranch(repository, branch);
else
return ignored();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java
index 0598e0ee8e..eff70a304f 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java
@@ -6,17 +6,13 @@ import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
-import com.google.common.collect.Lists;
-import com.pmease.gitplex.core.GitPlex;
-
import org.apache.commons.lang3.StringUtils;
+import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.git.GitUtils;
import com.pmease.gitplex.core.editable.BranchChoice;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -26,68 +22,54 @@ import com.pmease.gitplex.core.model.User;
"This gate keeper will be passed if the commit is submitted to specified branches.")
public class IfSubmitToSpecifiedBranches extends AbstractGateKeeper {
- private List<Long> branchIds = new ArrayList<>();
+ private List<String> branches = new ArrayList<>();
@Editable(name="Branches", description="Select branches to check.")
@BranchChoice
@NotNull
@Size(min=1)
- public List<Long> getBranchIds() {
- return branchIds;
+ public List<String> getBranches() {
+ return branches;
}
- public void setBranchIds(List<Long> branchIds) {
- this.branchIds = branchIds;
+ public void setBranches(List<String> branches) {
+ this.branches = branches;
}
@Override
public CheckResult doCheckRequest(PullRequest request) {
- return checkBranch(request.getTarget().getName());
- }
-
- @Override
- protected GateKeeper trim(Repository repository) {
- GitPlex.getInstance(BranchManager.class).trim(branchIds);
- if (branchIds.isEmpty())
- return null;
- else
- return this;
+ return checkBranch(request.getTargetRepo(), request.getTargetBranch());
}
- private CheckResult checkBranch(String branchName) {
- List<String> branchNames = new ArrayList<>();
- Dao dao = GitPlex.getInstance(Dao.class);
- for (Long branchId: branchIds)
- branchNames.add(dao.load(Branch.class, branchId).getName());
-
- if (branchIds.size() > 1) {
- if (branchNames.contains(branchName))
- return passed(Lists.newArrayList("Target branch is one of '" + StringUtils.join(branchNames, ", ") + "'."));
+ private CheckResult checkBranch(Repository repository, String branch) {
+ if (branches.size() > 1) {
+ if (branches.contains(branch))
+ return passed(Lists.newArrayList("Target branch is one of '" + StringUtils.join(branches, ", ") + "'."));
else
- return failed(Lists.newArrayList("Target branch is not any one of '" + StringUtils.join(branchNames, ", ") + "'."));
+ return failed(Lists.newArrayList("Target branch is not any one of '" + StringUtils.join(branches, ", ") + "'."));
} else {
- if (branchNames.contains(branchName))
- return passed(Lists.newArrayList("Target branch is '" + branchNames.get(0) + "'."));
+ if (branches.contains(branch))
+ return passed(Lists.newArrayList("Target branch is '" + branches.get(0) + "'."));
else
- return failed(Lists.newArrayList("Target branch is not '" + branchNames.get(0) + "'."));
+ return failed(Lists.newArrayList("Target branch is not '" + branches.get(0) + "'."));
}
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return checkBranch(branch.getName());
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return checkBranch(repository, branch);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return checkBranch(branch.getName());
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return checkBranch(repository, branch);
}
@Override
protected CheckResult doCheckRef(User user, Repository repository, String refName) {
- String branchName = Branch.parseName(refName);
- if (branchName != null)
- return checkBranch(branchName);
+ String branch = GitUtils.ref2branch(refName);
+ if (branch != null)
+ return checkBranch(repository, branch);
else
return ignored();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java
index 32659c9dd5..999833cd88 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java
@@ -3,9 +3,8 @@ package com.pmease.gitplex.core.gatekeeper;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@Editable(order=150, icon="fa-ext fa-file-diff", description="This gate keeper will be passed if the pull request "
@@ -26,12 +25,12 @@ public class IfSubmitWithGerritStylePatch extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return ignored();
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return ignored();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java
index 8d6f5ae845..eef13a5c41 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java
@@ -3,7 +3,6 @@ package com.pmease.gitplex.core.gatekeeper;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -15,7 +14,7 @@ public class IfSubmittedByRepositoryOwner extends AbstractGateKeeper {
@Override
public CheckResult doCheckRequest(PullRequest request) {
- return check(request.getSubmitter(), request.getTarget().getRepository());
+ return check(request.getSubmitter(), request.getTargetRepo());
}
private CheckResult check(User user, Repository repository) {
@@ -26,13 +25,13 @@ public class IfSubmittedByRepositoryOwner extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return check(user, repository);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return check(user, repository);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java
index 37485c7bd5..7f20e2958f 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java
@@ -3,7 +3,6 @@ package com.pmease.gitplex.core.gatekeeper;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -17,7 +16,7 @@ public class IfSubmittedByRepositoryWriter extends AbstractGateKeeper {
@Override
public CheckResult doCheckRequest(PullRequest request) {
- return check(request.getSubmitter(), request.getTarget().getRepository());
+ return check(request.getSubmitter(), request.getTargetRepo());
}
private CheckResult check(User user, Repository repository) {
@@ -28,13 +27,13 @@ public class IfSubmittedByRepositoryWriter extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
+ return check(user, repository);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- return check(user, branch.getRepository());
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ return check(user, repository);
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java
index 949eeb0c43..de13f343f2 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java
@@ -3,7 +3,6 @@ package com.pmease.gitplex.core.gatekeeper;
import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
@@ -28,12 +27,12 @@ public class IfSubmittedBySpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return check(user);
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java
index cc49d4f6a4..37df472b62 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java
@@ -8,7 +8,6 @@ import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.editable.UserChoice;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -53,12 +52,12 @@ public class IfSubmittedBySpecifiedUser extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
return check(user);
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java
index fecfd84ce1..5dbcb0d48e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java
@@ -11,7 +11,6 @@ import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.util.pattern.WildcardUtils;
import com.pmease.gitplex.core.editable.DirectoryChoice;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.Repository;
@@ -53,7 +52,7 @@ public class IfTouchSpecifiedDirectories extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
if (file == null)
return passed(new ArrayList<String>());
for (String each: directories) {
@@ -64,8 +63,8 @@ public class IfTouchSpecifiedDirectories extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- for (String file: branch.getRepository().git().listChangedFiles(branch.getHeadCommitHash(), commit, null)) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ for (String file: repository.git().listChangedFiles(repository.getObjectId(branch).name(), commit, null)) {
for (String each: directories) {
if (WildcardUtils.matchPath(each + "/**", file))
return passed(Lists.newArrayList("Touched directory '" + each + "'."));
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java
index 9a644d696a..bbd811d6e1 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java
@@ -8,7 +8,6 @@ import com.google.common.collect.Lists;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.util.pattern.WildcardUtils;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.Repository;
@@ -46,7 +45,7 @@ public class IfTouchSpecifiedFilePatterns extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
if (file == null)
return passed(new ArrayList<String>());
else if (WildcardUtils.matchPath(filePatterns, file))
@@ -56,8 +55,8 @@ public class IfTouchSpecifiedFilePatterns extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
- for (String file: branch.getRepository().git().listChangedFiles(branch.getHeadCommitHash(), commit, null)) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
+ for (String file: repository.git().listChangedFiles(repository.getObjectId(branch).name(), commit, null)) {
if (WildcardUtils.matchPath(filePatterns, file))
return passed(Lists.newArrayList("Touched files match patterns '" + filePatterns + "'."));
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java
index ace98fd104..d4fba7458f 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java
@@ -9,7 +9,6 @@ import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.manager.VerificationManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestVerification;
@@ -116,7 +115,7 @@ public class IfVerifiedByBuilds extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckFile(User user, Branch branch, String file) {
+ protected CheckResult doCheckFile(User user, Repository repository, String branch, String file) {
if (blockMode)
return blocking(Lists.newArrayList("Not verified by build."));
else
@@ -124,7 +123,7 @@ public class IfVerifiedByBuilds extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {
+ protected CheckResult doCheckCommit(User user, Repository repository, String branch, String commit) {
if (blockMode) {
return blocking(Lists.newArrayList("Has to be verified by builds."));
} else {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByIds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByNames.java
similarity index 60%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByIds.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByNames.java
index 468afba898..8af65deef2 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByIds.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByNames.java
@@ -8,45 +8,34 @@ import javax.validation.constraints.Size;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitName;
-import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.editable.BranchChoice;
import com.pmease.gitplex.core.gatekeeper.GateKeeper;
import com.pmease.gitplex.core.gatekeeper.IfSubmitToSpecifiedBranches;
-import com.pmease.gitplex.core.manager.BranchManager;
@SuppressWarnings("serial")
@Editable(name="Specify Branch Names", order=100)
-public class SpecifyTargetBranchesByIds implements TargetBranchSelection {
+public class SpecifyTargetBranchesByNames implements TargetBranchSelection {
- private List<Long> branchIds = new ArrayList<>();
+ private List<String> branches = new ArrayList<>();
@Editable(name="Branch Names")
@BranchChoice
@OmitName
@NotNull
@Size(min=1, message="At least one branch has to be selected.")
- public List<Long> getBranchIds() {
- return branchIds;
+ public List<String> getBranches() {
+ return branches;
}
- public void setBranchIds(List<Long> branchIds) {
- this.branchIds = branchIds;
+ public void setBranches(List<String> branches) {
+ this.branches = branches;
}
@Override
public GateKeeper getGateKeeper() {
IfSubmitToSpecifiedBranches gateKeeper = new IfSubmitToSpecifiedBranches();
- gateKeeper.getBranchIds().addAll(branchIds);
+ gateKeeper.getBranches().addAll(branches);
return gateKeeper;
}
- @Override
- public Object trim(Object context) {
- GitPlex.getInstance(BranchManager.class).trim(branchIds);
- if (branchIds.isEmpty())
- return null;
- else
- return this;
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java
index 9718e3b860..e079ea9165 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java
@@ -26,11 +26,6 @@ public class SpecifyTargetBranchesByPatterns implements TargetBranchSelection {
this.branchPatterns = branchPatterns;
}
- @Override
- public Object trim(Object context) {
- return this;
- }
-
@Override
public GateKeeper getGateKeeper() {
IfSubmitToSpecifiedBranchPatterns gateKeeper = new IfSubmitToSpecifiedBranchPatterns();
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/TargetBranchSelection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/TargetBranchSelection.java
index 3da7241ec5..b48bb0648e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/TargetBranchSelection.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/TargetBranchSelection.java
@@ -3,11 +3,10 @@ package com.pmease.gitplex.core.gatekeeper.helper.branchselection;
import java.io.Serializable;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.commons.util.trimmable.Trimmable;
import com.pmease.gitplex.core.gatekeeper.GateKeeper;
@Editable
-public interface TargetBranchSelection extends Trimmable, Serializable {
+public interface TargetBranchSelection extends Serializable {
GateKeeper getGateKeeper();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java
index 93b6cc70e8..78b3806c83 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java
@@ -16,17 +16,13 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.SecurityUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.eclipse.jgit.lib.ObjectId;
import com.google.common.base.Preconditions;
import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.hibernate.UnitOfWork;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.util.StringUtils;
import com.pmease.gitplex.core.listeners.RepositoryListener;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -36,22 +32,13 @@ public class GitPostReceiveCallback extends HttpServlet {
public static final String PATH = "/git-postreceive-callback";
- private static final Logger logger = LoggerFactory.getLogger(GitPostReceiveCallback.class);
-
private final Dao dao;
- private final BranchManager branchManager;
-
- private final UnitOfWork unitOfWork;
-
private final Provider<Set<RepositoryListener>> listenersProvider;
@Inject
- public GitPostReceiveCallback(Dao dao, BranchManager branchManager, UnitOfWork unitOfWork,
- Provider<Set<RepositoryListener>> listenersProvider) {
+ public GitPostReceiveCallback(Dao dao, Provider<Set<RepositoryListener>> listenersProvider) {
this.dao = dao;
- this.branchManager = branchManager;
- this.unitOfWork = unitOfWork;
this.listenersProvider = listenersProvider;
}
@@ -93,9 +80,19 @@ public class GitPostReceiveCallback extends HttpServlet {
String newCommitHash = StringUtils.reverse(fields.get(pos));
pos++;
String field = fields.get(pos);
- String oldCommitHash = StringUtils.reverse(field.substring(0, 40));
- onRefUpdated(repository, refName, oldCommitHash, newCommitHash);
+// String oldCommitHash = StringUtils.reverse(field.substring(0, 40));
+
+ String branch = GitUtils.ref2branch(refName);
+ if (branch != null) {
+ if (!newCommitHash.equals(GitUtils.NULL_SHA1))
+ repository.cacheObjectId(branch, ObjectId.fromString(newCommitHash));
+ else
+ repository.cacheObjectId(branch, null);
+ }
+ for (RepositoryListener listener: listenersProvider.get())
+ listener.onRefUpdate(repository, refName, newCommitHash);
+
field = field.substring(40);
if (field.length() == 0)
break;
@@ -105,53 +102,4 @@ public class GitPostReceiveCallback extends HttpServlet {
}
- private void onRefUpdated(Repository repository, String refName, String oldCommitHash, final String newCommitHash) {
- String branchName = Branch.parseName(refName);
- if (branchName != null) {
- if (oldCommitHash.equals(GitUtils.NULL_SHA1)) {
- Branch branch = new Branch();
- branch.setRepository(repository);
- branch.setName(branchName);
- branch.setHeadCommitHash(newCommitHash);
- repository.getBranches().add(branch);
- if (repository.getBranches().size() == 1) {
- repository.git().updateDefaultBranch(branchName);
- branch.setDefault(true);
- }
- branchManager.save(branch);
- } else if (newCommitHash.equals(GitUtils.NULL_SHA1)) {
- Branch branch = branchManager.findBy(repository, branchName);
- Preconditions.checkNotNull(branch);
-
- repository.getBranches().remove(branch);
- branchManager.delete(branch);
- if (repository.git().resolveDefaultBranch().equals(branchName) && !repository.getBranches().isEmpty())
- repository.git().updateDefaultBranch(repository.getBranches().iterator().next().getName());
- } else {
- Branch branch = branchManager.findBy(repository, branchName);
- Preconditions.checkNotNull(branch);
-
- branch.setHeadCommitHash(newCommitHash);
- branchManager.save(branch);
- }
- }
-
- if (!newCommitHash.equals(GitUtils.NULL_SHA1)) {
- final Long repositoryId = repository.getId();
- unitOfWork.asyncCall(new Runnable() {
-
- @Override
- public void run() {
- Repository repository = dao.load(Repository.class, repositoryId);
- try {
- for (RepositoryListener listener: listenersProvider.get())
- listener.commitReceived(repository, newCommitHash);
- } catch (Exception e) {
- logger.error("Error notifying commit of repository '" + repository + "'", e);
- }
- }
-
- });
- }
- }
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java
index ee874aff6f..31de0e61cf 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java
@@ -23,13 +23,10 @@ import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.util.StringUtils;
import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
-import com.pmease.gitplex.core.manager.BranchManager;
+import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.core.permission.ObjectPermission;
@@ -44,14 +41,11 @@ public class GitUpdateCallback extends HttpServlet {
private final Dao dao;
- private final BranchManager branchManager;
-
private final UserManager userManager;
@Inject
- public GitUpdateCallback(Dao dao, BranchManager branchManager, UserManager userManager) {
+ public GitUpdateCallback(Dao dao, UserManager userManager) {
this.dao = dao;
- this.branchManager = branchManager;
this.userManager = userManager;
}
@@ -116,37 +110,24 @@ public class GitUpdateCallback extends HttpServlet {
if (!user.asSubject().isPermitted(ObjectPermission.ofRepoAdmin(repository)))
error(output, "Only repository administrators can update gitplex refs.");
} else {
- String branchName = Branch.parseName(refName);
- if (branchName != null) { // push branch ref
+ String branch = GitUtils.ref2branch(refName);
+ if (branch != null) { // push branch ref
if (oldCommitHash.equals(GitUtils.NULL_SHA1)) { // create new branch
checkRef(user, repository, refName, output);
} else {
- Branch branch = branchManager.findBy(repository, branchName);
- Preconditions.checkNotNull(branch);
-
if (newCommitHash.equals(GitUtils.NULL_SHA1)) { // deleting a branch ref
GateKeeper gateKeeper = repository.getGateKeeper();
- CheckResult checkResult = gateKeeper.checkFile(user, branch, null);
+ CheckResult checkResult = gateKeeper.checkFile(user, repository, branch, null);
if (!(checkResult instanceof Passed)) {
List<String> messages = new ArrayList<>();
for (String each: checkResult.getReasons())
messages.add(each);
error(output, messages.toArray(new String[messages.size()]));
- } else {
- boolean hasOpen = false;
- for (PullRequest each: branch.getIncomingRequests()) {
- if (each.isOpen()) {
- hasOpen = true;
- break;
- }
- }
- if (hasOpen)
- error(output, "There are pull requests opening against this branch.");
}
} else {
GateKeeper gateKeeper = repository.getGateKeeper();
- CheckResult checkResult = gateKeeper.checkCommit(user, branch, newCommitHash);
+ CheckResult checkResult = gateKeeper.checkCommit(user, repository, branch, newCommitHash);
if (!(checkResult instanceof Passed)) {
List<String> messages = new ArrayList<>();
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/listeners/RepositoryListener.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/listeners/RepositoryListener.java
index 805828a8b2..811f4560a4 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/listeners/RepositoryListener.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/listeners/RepositoryListener.java
@@ -1,12 +1,16 @@
package com.pmease.gitplex.core.listeners;
+import javax.annotation.Nullable;
+
import com.pmease.commons.loader.ExtensionPoint;
import com.pmease.gitplex.core.model.Repository;
@ExtensionPoint
public interface RepositoryListener {
- void repositoryRemoved(Repository repository);
+ void beforeDelete(Repository repository);
+
+ void afterDelete(Repository repository);
- void commitReceived(Repository repository, String commitHash);
+ void onRefUpdate(Repository repository, String refName, @Nullable String newCommitHash);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/BranchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/BranchManager.java
deleted file mode 100644
index 814481eefe..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/BranchManager.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.pmease.gitplex.core.manager;
-
-import java.util.Collection;
-
-import javax.annotation.Nullable;
-
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.Repository;
-
-public interface BranchManager {
-
- /**
- * Find branch by repository and branch name.
- *
- * @param repository
- * repository to find branch inside
- * @param branchName
- * name of the branch to find
- * @return
- * found branch, or <tt>null</tt> if not found
- */
- public @Nullable Branch findBy(Repository repository, String branchName);
-
- public @Nullable Branch findBy(String branchFQN);
-
- /**
- * Delete all refs pointed to this branch and its associated pull requests and
- * pull request updates.
- *
- * @param branch
- * branch whose refs, pull request refs, and pull request update refs
- * to be deleted
- */
- public void deleteRefs(Branch branch);
-
- /**
- * Delete the branch record from database, as well as removing the branch from
- * corresponding git repository. This method will proceed even if there are
- * open pull requests associating with the branch. This is designed to be so
- * in order to make sure branch deletion always succeeds as otherwise repository
- * sanity check might encounter difficulties if the branch ref does not exist
- * in Git.
- *
- * @param branch
- * branch to be deleted
- */
- public void delete(Branch branch);
-
- public void save(Branch branch);
-
- public void trim(Collection<Long> branchIds);
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/BranchWatchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/BranchWatchManager.java
index 1d2ed29ae4..3699bbe37a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/BranchWatchManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/BranchWatchManager.java
@@ -10,4 +10,6 @@ public interface BranchWatchManager {
Collection<BranchWatch> findBy(User user, Repository repository);
+ Collection<BranchWatch> findBy(Repository repository, String branch);
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java
index 0f9e425c2e..621ea71924 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java
@@ -7,22 +7,23 @@ import java.util.List;
import javax.annotation.Nullable;
import com.pmease.gitplex.core.listeners.ConfigListener;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
public interface PullRequestManager extends ConfigListener {
- @Nullable PullRequest findOpen(Branch target, Branch source);
+ @Nullable
+ PullRequest findOpen(RepoAndBranch target, RepoAndBranch source);
- Collection<PullRequest> findOpenTo(Branch target, Repository source);
+ Collection<PullRequest> queryOpenTo(RepoAndBranch target, @Nullable Repository sourceRepo);
- Collection<PullRequest> findOpenFrom(Branch source, Repository target);
+ Collection<PullRequest> queryOpenFrom(RepoAndBranch source, @Nullable Repository targetRepo);
- Collection<PullRequest> findOpen(Branch sourceOrTarget);
-
+ Collection<PullRequest> queryOpen(RepoAndBranch sourceOrTarget);
+
boolean canIntegrate(PullRequest request);
/**
@@ -71,7 +72,7 @@ public interface PullRequestManager extends ConfigListener {
List<IntegrationStrategy> getApplicableIntegrationStrategies(PullRequest request);
- void restoreSource(PullRequest request);
+ void restoreSourceBranch(PullRequest request);
/**
* Get last visit date of specified pull request for current user.
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/RepositoryManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/RepositoryManager.java
index e87440cd25..9064bd2902 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/RepositoryManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/RepositoryManager.java
@@ -33,5 +33,4 @@ public interface RepositoryManager {
void save(Repository repository);
void delete(Repository repository);
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultBranchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultBranchManager.java
deleted file mode 100644
index fd180228f1..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultBranchManager.java
+++ /dev/null
@@ -1,193 +0,0 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import com.google.common.collect.BiMap;
-import com.google.common.collect.HashBiMap;
-import com.pmease.commons.hibernate.Sessional;
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.UnitOfWork;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.util.Pair;
-import com.pmease.commons.util.StringUtils;
-import com.pmease.gitplex.core.listeners.LifecycleListener;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.manager.RepositoryManager;
-import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Repository;
-
-@Singleton
-public class DefaultBranchManager implements BranchManager, LifecycleListener {
-
- private final Dao dao;
-
- private final PullRequestManager pullRequestManager;
-
- private final UserManager userManager;
-
- private final RepositoryManager repositoryManager;
-
- private final UnitOfWork unitOfWork;
-
- private final BiMap<Pair<Long, String>, Long> nameToId = HashBiMap.create();
-
- private final ReadWriteLock idLock = new ReentrantReadWriteLock();
-
- @Inject
- public DefaultBranchManager(Dao dao, PullRequestManager pullRequestManager, UserManager userManager,
- RepositoryManager repositoryManager, UnitOfWork unitOfWork) {
- this.dao = dao;
- this.pullRequestManager = pullRequestManager;
- this.userManager = userManager;
- this.repositoryManager = repositoryManager;
- this.unitOfWork = unitOfWork;
- }
-
- @Sessional
- @Override
- public Branch findBy(Repository repository, String branchName) {
- idLock.readLock().lock();
- try {
- Long id = nameToId.get(new Pair<>(repository.getId(), branchName));
- if (id != null)
- return dao.load(Branch.class, id);
- else
- return null;
- } finally {
- idLock.readLock().unlock();
- }
- }
-
- @Sessional
- @Override
- public Branch findBy(String branchFQN) {
- String repositoryName = StringUtils.substringBeforeLast(branchFQN, "/");
- Repository repository = repositoryManager.findBy(repositoryName);
- if (repository != null)
- return findBy(repository, StringUtils.substringAfterLast(branchFQN, "/"));
- else
- return null;
- }
-
- @Transactional
- @Override
- public void delete(final Branch branch) {
- for (PullRequest request: branch.getIncomingRequests())
- pullRequestManager.delete(request);
-
- for (PullRequest request: branch.getOutgoingRequests()) {
- if (request.isOpen())
- pullRequestManager.discard(request, "Source branch is deleted.");
- request.setSourceFQN(branch.getFQN());
- request.setSource(null);
- dao.persist(request);
- }
- dao.remove(branch);
-
- deleteRefs(branch);
-
- dao.afterCommit(new Runnable() {
-
- @Override
- public void run() {
- idLock.writeLock().lock();
- try {
- nameToId.inverse().remove(branch.getId());
- } finally {
- idLock.writeLock().unlock();
- }
- }
-
- });
- }
-
- @Sessional
- @Override
- public void deleteRefs(Branch branch) {
- branch.getRepository().git().deleteBranch(branch.getName());
- }
-
- @Override
- public void trim(Collection<Long> branchIds) {
- for (Iterator<Long> it = branchIds.iterator(); it.hasNext();) {
- if (dao.get(Branch.class, it.next()) == null)
- it.remove();
- }
- }
-
- @Transactional
- @Override
- public void save(final Branch branch) {
- branch.setLastUpdater(userManager.getCurrent());
-
- dao.persist(branch);
-
- /**
- * Source branch update is key to the logic as it has to create
- * pull request update, so we should not postpone it to be executed
- * in a executor service like target branch update below
- */
- for (PullRequest request: branch.getOutgoingRequests()) {
- if (request.isOpen())
- pullRequestManager.onSourceBranchUpdate(request, true);
- }
-
- final Long branchId = branch.getId();
- dao.afterCommit(new Runnable() {
-
- @Override
- public void run() {
- idLock.writeLock().lock();
- try {
- nameToId.inverse().put(branch.getId(), new Pair<>(branch.getRepository().getId(), branch.getName()));
- } finally {
- idLock.writeLock().unlock();
- }
-
- unitOfWork.asyncCall(new Runnable() {
-
- @Override
- public void run() {
- Branch branch = dao.load(Branch.class, branchId);
-
- for (PullRequest request: branch.getIncomingRequests()) {
- if (request.isOpen())
- pullRequestManager.onTargetBranchUpdate(request);
- }
- }
-
- });
- }
-
- });
- }
-
- @Sessional
- @Override
- public void systemStarting() {
- for (Branch branch: dao.allOf(Branch.class))
- nameToId.inverse().put(branch.getId(), new Pair<>(branch.getRepository().getId(), branch.getName()));
- }
-
- @Override
- public void systemStarted() {
- }
-
- @Override
- public void systemStopping() {
- }
-
- @Override
- public void systemStopped() {
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultBranchWatchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultBranchWatchManager.java
index 03f86b00d3..a40225ce40 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultBranchWatchManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultBranchWatchManager.java
@@ -30,7 +30,15 @@ public class DefaultBranchWatchManager implements BranchWatchManager {
public Collection<BranchWatch> findBy(User user, Repository repository) {
EntityCriteria<BranchWatch> criteria = EntityCriteria.of(BranchWatch.class);
criteria.add(Restrictions.eq("user", user));
- criteria.createCriteria("branch").add(Restrictions.eq("repository", repository));
+ criteria.add(Restrictions.eq("repository", repository));
+ return dao.query(criteria);
+ }
+
+ @Override
+ public Collection<BranchWatch> findBy(Repository repository, String branch) {
+ EntityCriteria<BranchWatch> criteria = EntityCriteria.of(BranchWatch.class);
+ criteria.add(Restrictions.eq("repository", repository));
+ criteria.add(Restrictions.eq("branch", branch));
return dao.query(criteria);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
index 264128897c..b66c1d618a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
@@ -22,12 +22,16 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.eclipse.jetty.util.ConcurrentHashSet;
+import org.eclipse.jgit.lib.ObjectId;
+import org.hibernate.Query;
+import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.joda.time.DateTime;
import org.slf4j.Logger;
@@ -36,6 +40,7 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.pmease.commons.git.Git;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.git.command.MergeCommand.FastForwardMode;
import com.pmease.commons.hibernate.Sessional;
import com.pmease.commons.hibernate.Transactional;
@@ -44,21 +49,18 @@ import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.hibernate.dao.EntityCriteria;
import com.pmease.commons.markdown.MarkdownManager;
import com.pmease.commons.util.FileUtils;
-import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.MentionParser;
import com.pmease.gitplex.core.listeners.LifecycleListener;
import com.pmease.gitplex.core.listeners.PullRequestListener;
-import com.pmease.gitplex.core.manager.BranchManager;
+import com.pmease.gitplex.core.listeners.RepositoryListener;
import com.pmease.gitplex.core.manager.ConfigManager;
import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.manager.PullRequestNotificationManager;
import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
-import com.pmease.gitplex.core.manager.RepositoryManager;
import com.pmease.gitplex.core.manager.ReviewInvitationManager;
import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Config;
import com.pmease.gitplex.core.model.IntegrationPolicy;
import com.pmease.gitplex.core.model.IntegrationPreview;
@@ -69,12 +71,13 @@ import com.pmease.gitplex.core.model.PullRequestActivity;
import com.pmease.gitplex.core.model.PullRequestComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.PullRequestVisit;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.ReviewInvitation;
import com.pmease.gitplex.core.model.User;
@Singleton
-public class DefaultPullRequestManager implements PullRequestManager, LifecycleListener {
+public class DefaultPullRequestManager implements PullRequestManager, RepositoryListener, LifecycleListener {
private static final Logger logger = LoggerFactory.getLogger(DefaultPullRequestManager.class);
@@ -86,8 +89,6 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
private final PullRequestCommentManager pullRequestCommentManager;
- private final BranchManager branchManager;
-
private final UserManager userManager;
private final MarkdownManager markdownManager;
@@ -116,14 +117,13 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
@Inject
public DefaultPullRequestManager(Dao dao, PullRequestUpdateManager pullRequestUpdateManager,
- BranchManager branchManager, StorageManager storageManager,
- ReviewInvitationManager reviewInvitationManager, UserManager userManager,
- PullRequestNotificationManager notificationManager, ConfigManager configManager,
- PullRequestCommentManager pullRequestCommentManager, MarkdownManager markdownManager,
- UnitOfWork unitOfWork, Set<PullRequestListener> pullRequestListeners) {
+ StorageManager storageManager, ReviewInvitationManager reviewInvitationManager,
+ UserManager userManager, PullRequestNotificationManager notificationManager,
+ ConfigManager configManager, PullRequestCommentManager pullRequestCommentManager,
+ MarkdownManager markdownManager, UnitOfWork unitOfWork,
+ Set<PullRequestListener> pullRequestListeners) {
this.dao = dao;
this.pullRequestUpdateManager = pullRequestUpdateManager;
- this.branchManager = branchManager;
this.storageManager = storageManager;
this.reviewInvitationManager = reviewInvitationManager;
this.pullRequestCommentManager = pullRequestCommentManager;
@@ -134,15 +134,6 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
this.pullRequestListeners = pullRequestListeners;
}
- @Sessional
- @Override
- public PullRequest findOpen(Branch target, Branch source) {
- return dao.find(EntityCriteria.of(PullRequest.class)
- .add(ofTarget(target))
- .add(ofSource(source))
- .add(ofOpen()));
- }
-
@Transactional
@Override
public void delete(PullRequest request) {
@@ -160,37 +151,16 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
request.deleteRefs();
}
- @Sessional
- @Override
- public Collection<PullRequest> findOpen(Branch sourceOrTarget) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
- criteria.add(ofOpen());
- criteria.add(Restrictions.or(ofSource(sourceOrTarget), ofTarget(sourceOrTarget)));
- return dao.query(criteria);
- }
-
@Transactional
@Override
- public void restoreSource(PullRequest request) {
- Preconditions.checkState(request.getSourceFQN() != null && request.getSource() == null && !request.isOpen());
-
- String repositoryFQN = Branch.getRepositoryFQNByFQN(request.getSourceFQN());
- Repository repository = GitPlex.getInstance(RepositoryManager.class).findBy(repositoryFQN);
- if (repository == null)
- throw new RuntimeException("Unable to find repository: " + repositoryFQN);
- String branchName = Branch.getNameByFQN(request.getSourceFQN());
- Branch branch = GitPlex.getInstance(BranchManager.class).findBy(repository, branchName);
- if (branch == null) {
- branch = new Branch();
- branch.setRepository(repository);
- branch.setName(branchName);
- branch.setHeadCommitHash(request.getLatestUpdate().getHeadCommitHash());
- branchManager.save(branch);
- repository.git().createBranch(branch.getName(), branch.getHeadCommitHash());
+ public void restoreSourceBranch(PullRequest request) {
+ Preconditions.checkState(!request.isOpen() && request.getSourceRepo() != null);
+
+ if (request.getSource().getHead(false) == null) {
+ request.getSourceRepo().git().createBranch(
+ request.getSourceBranch(),
+ request.getLatestUpdate().getHeadCommitHash());
}
-
- request.setSource(branch);
- dao.persist(request);
}
@Transactional
@@ -271,14 +241,15 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
User user = userManager.getCurrent();
- Git git = request.getTarget().getRepository().git();
+ Repository targetRepo = request.getTargetRepo();
+ Git git = targetRepo.git();
IntegrationStrategy strategy = request.getIntegrationStrategy();
if ((strategy == MERGE_ALWAYS || strategy == MERGE_IF_NECESSARY || strategy == MERGE_WITH_SQUASH)
&& !preview.getIntegrated().equals(preview.getRequestHead()) && comment != null) {
File tempDir = FileUtils.createTempDir();
try {
Git tempGit = new Git(tempDir);
- tempGit.clone(git.repoDir().getAbsolutePath(), false, true, true, request.getTarget().getName());
+ tempGit.clone(git.repoDir().getAbsolutePath(), false, true, true, request.getTargetBranch());
tempGit.updateRef("HEAD", preview.getIntegrated(), null, null);
tempGit.reset(null, null);
@@ -291,16 +262,19 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
}
}
if (strategy == REBASE_SOURCE_ONTO_TARGET || strategy == MERGE_WITH_SQUASH) {
- Git sourceGit = request.getSource().getRepository().git();
- sourceGit.updateRef(request.getSource().getHeadRef(), integrated, preview.getRequestHead(),
+ Repository sourceRepo = request.getSourceRepo();
+ Git sourceGit = sourceRepo.git();
+ String sourceRef = request.getSourceRef();
+ sourceGit.updateRef(sourceRef, integrated, preview.getRequestHead(),
"Pull request #" + request.getId());
- request.getSource().setHeadCommitHash(integrated);
- branchManager.save(request.getSource());
+ sourceRepo.cacheObjectId(request.getSourceBranch(), ObjectId.fromString(integrated));
+ onRefUpdate(sourceRepo, sourceRef, integrated);
}
- git.updateRef(request.getTarget().getHeadRef(), integrated,
- preview.getTargetHead(), "Pull request #" + request.getId());
- request.getTarget().setHeadCommitHash(integrated);
- branchManager.save(request.getTarget());
+
+ String targetRef = request.getTargetRef();
+ git.updateRef(targetRef, integrated, preview.getTargetHead(), "Pull request #" + request.getId());
+ targetRepo.cacheObjectId(request.getTargetBranch(), ObjectId.fromString(integrated));
+ onRefUpdate(targetRepo, targetRef, integrated);
PullRequestActivity activity = new PullRequestActivity();
activity.setRequest(request);
@@ -372,9 +346,9 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
@Override
public List<IntegrationStrategy> getApplicableIntegrationStrategies(PullRequest request) {
List<IntegrationStrategy> strategies = null;
- for (IntegrationPolicy policy: request.getTarget().getRepository().getIntegrationPolicies()) {
- if (policy.getTargetBranches().matches(request.getTarget())
- && policy.getSourceBranches().matches(request.getSource())) {
+ for (IntegrationPolicy policy: request.getTargetRepo().getIntegrationPolicies()) {
+ if (policy.getTargetBranches().matches(request.getTargetBranch())
+ && policy.getSourceBranches().matches(request.getSourceRepo(), request.getSourceBranch())) {
strategies = policy.getIntegrationStrategies();
break;
}
@@ -405,8 +379,8 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
@Transactional
private void closeIfMerged(PullRequest request) {
- Git git = request.getTarget().getRepository().git();
- if (git.isAncestor(request.getLatestUpdate().getHeadCommitHash(), request.getTarget().getHeadCommitHash())) {
+ Git git = request.getTargetRepo().git();
+ if (git.isAncestor(request.getLatestUpdate().getHeadCommitHash(), request.getTarget().getHead())) {
PullRequestActivity activity = new PullRequestActivity();
activity.setRequest(request);
activity.setAction(PullRequestActivity.Action.INTEGRATE);
@@ -427,14 +401,13 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
@Transactional
@Override
public void onSourceBranchUpdate(PullRequest request, boolean notify) {
- if (request.getLatestUpdate().getHeadCommitHash().equals(request.getSource().getHeadCommitHash()))
+ if (request.getLatestUpdate().getHeadCommitHash().equals(request.getSource().getHead()))
return;
PullRequestUpdate update = new PullRequestUpdate();
update.setRequest(request);
update.setDate(new Date());
- update.setHeadCommitHash(request.getSource().getHeadCommitHash());
- update.setUser(request.getSource().getLastUpdater());
+ update.setHeadCommitHash(request.getSource().getHead());
request.addUpdate(update);
pullRequestUpdateManager.save(update, notify);
@@ -505,26 +478,6 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
}
}
- @Sessional
- @Override
- public Collection<PullRequest> findOpenTo(Branch target, Repository source) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
- criteria.add(Restrictions.eq("target", target));
- criteria.add(Restrictions.isNull("closeStatus"));
- criteria.createCriteria("source").add(Restrictions.eq("repository", source));
- return dao.query(criteria);
- }
-
- @Sessional
- @Override
- public Collection<PullRequest> findOpenFrom(Branch source, Repository target) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
- criteria.add(Restrictions.eq("source", source));
- criteria.add(Restrictions.isNull("closeStatus"));
- criteria.createCriteria("target").add(Restrictions.eq("repository", target));
- return dao.query(criteria);
- }
-
private int getIntegrationPreviewWorkers() {
Integer workers = configManager.getQosSetting().getIntegrationPreviewWorkers();
if (workers == null)
@@ -573,9 +526,9 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
IntegrationPreview preview = request.getLastIntegrationPreview();
if (request.isOpen() && (preview == null || preview.isObsolete(request))) {
String requestHead = request.getLatestUpdate().getHeadCommitHash();
- String targetHead = request.getTarget().getHeadCommitHash();
- Git git = request.getTarget().getRepository().git();
- preview = new IntegrationPreview(request.getTarget().getHeadCommitHash(),
+ String targetHead = request.getTarget().getHead();
+ Git git = request.getTargetRepo().git();
+ preview = new IntegrationPreview(targetHead,
request.getLatestUpdate().getHeadCommitHash(), request.getIntegrationStrategy(), null);
request.setLastIntegrationPreview(preview);
String integrateRef = request.getIntegrateRef();
@@ -589,7 +542,7 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
try {
Git tempGit = new Git(tempDir);
tempGit.clone(git.repoDir().getAbsolutePath(), false, true, true,
- request.getTarget().getName());
+ request.getTargetBranch());
String integrated;
@@ -706,4 +659,111 @@ public class DefaultPullRequestManager implements PullRequestManager, LifecycleL
integrationPreviewExecutor.shutdown();
}
+ @Transactional
+ @Override
+ public void beforeDelete(Repository repository) {
+ for (PullRequest request: repository.getOutgoingRequests()) {
+ if (!request.getTargetRepo().equals(repository) && request.isOpen())
+ discard(request, "Source repository is deleted.");
+ }
+
+ Query query = dao.getSession().createQuery("update PullRequest set sourceRepo=null where "
+ + "sourceRepo = :repo and targetRepo != :repo");
+ query.setParameter("repo", repository);
+ query.executeUpdate();
+ }
+
+ @Override
+ public void afterDelete(Repository repository) {
+ }
+
+ @Transactional
+ @Override
+ public void onRefUpdate(Repository repository, String refName, @Nullable String newCommitHash) {
+ final String branch = GitUtils.ref2branch(refName);
+ if (branch != null) {
+ RepoAndBranch repoAndBranch = new RepoAndBranch(repository, branch);
+ if (newCommitHash != null) {
+ /**
+ * Source branch update is key to the logic as it has to create
+ * pull request update, so we should not postpone it to be executed
+ * in a executor service like target branch update below
+ */
+ Criterion criterion = Restrictions.and(ofOpen(), ofSource(repoAndBranch));
+ for (PullRequest request: dao.query(EntityCriteria.of(PullRequest.class).add(criterion)))
+ onSourceBranchUpdate(request, true);
+
+ final Long repoId = repository.getId();
+ dao.afterCommit(new Runnable() {
+
+ @Override
+ public void run() {
+ unitOfWork.asyncCall(new Runnable() {
+
+ @Override
+ public void run() {
+ RepoAndBranch repoAndBranch = new RepoAndBranch(repoId, branch);
+ Criterion criterion = Restrictions.and(ofOpen(), ofTarget(repoAndBranch));
+ for (PullRequest request: dao.query(EntityCriteria.of(PullRequest.class).add(criterion)))
+ onTargetBranchUpdate(request);
+ }
+
+ });
+ }
+
+ });
+ } else {
+ Criterion criterion = Restrictions.and(
+ ofOpen(),
+ Restrictions.or(ofSource(repoAndBranch), ofTarget(repoAndBranch)));
+ for (PullRequest request: dao.query(EntityCriteria.of(PullRequest.class).add(criterion))) {
+ if (request.getTargetRepo().equals(repository) && request.getTargetBranch().equals(branch))
+ discard(request, "Target branch is deleted.");
+ else
+ discard(request, "Source branch is deleted.");
+ }
+ }
+ }
+ }
+
+ @Sessional
+ @Override
+ public PullRequest findOpen(RepoAndBranch target, RepoAndBranch source) {
+ return dao.find(EntityCriteria.of(PullRequest.class)
+ .add(ofTarget(target)).add(ofSource(source)).add(ofOpen()));
+ }
+
+ @Sessional
+ @Override
+ public Collection<PullRequest> queryOpenTo(RepoAndBranch target, @Nullable Repository sourceRepo) {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ criteria.add(ofTarget(target));
+
+ if (sourceRepo != null)
+ criteria.add(Restrictions.eq("sourceRepo", sourceRepo));
+ criteria.add(ofOpen());
+ return dao.query(criteria);
+ }
+
+ @Sessional
+ @Override
+ public Collection<PullRequest> queryOpenFrom(RepoAndBranch source, @Nullable Repository targetRepo) {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ criteria.add(ofSource(source));
+
+ if (targetRepo != null)
+ criteria.add(Restrictions.eq("targetRepo", targetRepo));
+ criteria.add(ofOpen());
+ return dao.query(criteria);
+ }
+
+ @Sessional
+ @Override
+ public Collection<PullRequest> queryOpen(RepoAndBranch sourceOrTarget) {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ criteria.add(ofOpen());
+ criteria.add(Restrictions.or(ofSource(sourceOrTarget), ofTarget(sourceOrTarget)));
+ return dao.query(criteria);
+ }
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
index 0d70f5e4d3..094bd89c65 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
@@ -49,14 +49,14 @@ public class DefaultPullRequestUpdateManager implements PullRequestUpdateManager
FileUtils.cleanDir(storageManager.getCacheDir(update));
PullRequest request = update.getRequest();
- String sourceHead = request.getSource().getHeadCommitHash();
+ String sourceHead = request.getSource().getHead();
- if (!request.getTarget().getRepository().equals(request.getSource().getRepository())) {
- request.getTarget().getRepository().git().fetch(
- request.getSource().getRepository().git(),
- "+" + request.getSource().getHeadRef() + ":" + update.getHeadRef());
+ if (!request.getTargetRepo().equals(request.getSourceRepo())) {
+ request.getTargetRepo().git().fetch(
+ request.getSourceRepo().git(),
+ "+" + request.getSourceRef() + ":" + update.getHeadRef());
} else {
- request.getTarget().getRepository().git().updateRef(update.getHeadRef(),
+ request.getTargetRepo().git().updateRef(update.getHeadRef(),
sourceHead, null, null);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java
index 3ee997f6eb..53b29622d5 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java
@@ -26,6 +26,7 @@ import com.pmease.commons.git.Commit;
import com.pmease.commons.hibernate.Transactional;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.util.Pair;
+import com.pmease.gitplex.core.manager.BranchWatchManager;
import com.pmease.gitplex.core.manager.MailManager;
import com.pmease.gitplex.core.manager.PullRequestWatchManager;
import com.pmease.gitplex.core.manager.UrlManager;
@@ -49,15 +50,19 @@ public class DefaultPullRequestWatchManager implements PullRequestWatchManager {
private final UserManager userManager;
+ private final BranchWatchManager branchWatchManager;
+
private final MailManager mailManager;
private final UrlManager urlManager;
@Inject
- public DefaultPullRequestWatchManager(Dao dao, UserManager userManager, MailManager mailManager,
+ public DefaultPullRequestWatchManager(Dao dao, UserManager userManager,
+ BranchWatchManager branchWatchManager, MailManager mailManager,
UrlManager urlManager) {
this.dao = dao;
this.userManager = userManager;
+ this.branchWatchManager = branchWatchManager;
this.mailManager = mailManager;
this.urlManager = urlManager;
}
@@ -65,7 +70,7 @@ public class DefaultPullRequestWatchManager implements PullRequestWatchManager {
@Transactional
@Override
public void onOpened(PullRequest request) {
- for (BranchWatch branchWatch: request.getTarget().getWatches()) {
+ for (BranchWatch branchWatch: branchWatchManager.findBy(request.getTargetRepo(), request.getTargetBranch())) {
watch(request, branchWatch.getUser(),
"You are set to watch this pull request as you are watching the target branch.");
}
@@ -84,11 +89,6 @@ public class DefaultPullRequestWatchManager implements PullRequestWatchManager {
@Transactional
private void addParticipantsToWatchList(PullRequestUpdate update) {
- if (update.getUser() != null) {
- watch(update.getRequest(), update.getUser(),
- "You are set to watch this pull request as you updated it.");
- }
-
// we use a name-email pair to filter off duplicate person as equals method of PersonIdent also takes
// "when" field into account
Set<Pair<String, String>> nameEmailPairs = new HashSet<>();
@@ -121,10 +121,7 @@ public class DefaultPullRequestWatchManager implements PullRequestWatchManager {
public void onUpdated(PullRequestUpdate update) {
addParticipantsToWatchList(update);
- if (update.getUser() != null)
- notify(update.getRequest(), Sets.newHashSet(update.getUser()), UPDATED);
- else
- notify(update.getRequest(), new HashSet<User>(), UPDATED);
+ notify(update.getRequest(), new HashSet<User>(), UPDATED);
}
@Transactional
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java
index 07b6a1ba9c..fa63285cda 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java
@@ -3,10 +3,7 @@ package com.pmease.gitplex.core.manager.impl;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -16,13 +13,13 @@ import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.commons.io.IOUtils;
+import org.hibernate.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
-import com.pmease.commons.git.BriefCommit;
import com.pmease.commons.git.Git;
import com.pmease.commons.hibernate.Sessional;
import com.pmease.commons.hibernate.Transactional;
@@ -33,11 +30,9 @@ import com.pmease.commons.util.Pair;
import com.pmease.commons.util.StringUtils;
import com.pmease.gitplex.core.listeners.LifecycleListener;
import com.pmease.gitplex.core.listeners.RepositoryListener;
-import com.pmease.gitplex.core.manager.BranchManager;
import com.pmease.gitplex.core.manager.RepositoryManager;
import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -50,8 +45,6 @@ public class DefaultRepositoryManager implements RepositoryManager, LifecycleLis
private final Provider<Set<RepositoryListener>> listenersProvider;
- private final BranchManager branchManager;
-
private final StorageManager storageManager;
private final UserManager userManager;
@@ -65,11 +58,9 @@ public class DefaultRepositoryManager implements RepositoryManager, LifecycleLis
private final ReadWriteLock idLock = new ReentrantReadWriteLock();
@Inject
- public DefaultRepositoryManager(Dao dao, BranchManager branchManager,
- UserManager userManager, StorageManager storageManager,
+ public DefaultRepositoryManager(Dao dao, UserManager userManager, StorageManager storageManager,
Provider<Set<RepositoryListener>> listenersProvider) {
this.dao = dao;
- this.branchManager = branchManager;
this.storageManager = storageManager;
this.userManager = userManager;
this.listenersProvider = listenersProvider;
@@ -114,13 +105,12 @@ public class DefaultRepositoryManager implements RepositoryManager, LifecycleLis
@Transactional
@Override
public void delete(final Repository repository) {
- for (Branch branch: repository.getBranches())
- branchManager.delete(branch);
-
- for (Repository each: repository.getForks()) {
- each.setForkedFrom(null);
- save(each);
- }
+ for (RepositoryListener listener: listenersProvider.get())
+ listener.beforeDelete(repository);
+
+ Query query = dao.getSession().createQuery("update Repository set forkedFrom=null where forkedFrom=:forkedFrom");
+ query.setParameter("forkedFrom", repository);
+ query.executeUpdate();
dao.remove(repository);
@@ -141,7 +131,7 @@ public class DefaultRepositoryManager implements RepositoryManager, LifecycleLis
});
for (RepositoryListener listener: listenersProvider.get())
- listener.repositoryRemoved(repository);
+ listener.afterDelete(repository);
}
@Sessional
@@ -259,52 +249,6 @@ public class DefaultRepositoryManager implements RepositoryManager, LifecycleLis
gitPostReceiveHookFile.setExecutable(true);
}
- logger.debug("Syncing branches of repository '{}'...", repository);
-
- Map<String, Branch> branchesInDB = new HashMap<String, Branch>();
- Map<String, BriefCommit> branchesInGit = repository.git().listHeadCommits();
- for (Iterator<Branch> it = repository.getBranches().iterator(); it.hasNext();) {
- Branch branch = it.next();
- if (branchesInGit.containsKey(branch.getName())) {
- branchesInDB.put(branch.getName(), branch);
- } else {
- branchManager.delete(branch);
- it.remove();
- }
- }
-
- for (Map.Entry<String, BriefCommit> entry: branchesInGit.entrySet()) {
- Branch branch = branchesInDB.get(entry.getKey());
- if (branch == null) {
- branch = new Branch();
- branch.setName(entry.getKey());
- branch.setHeadCommitHash(entry.getValue().getHash());
- branch.setRepository(repository);
- repository.getBranches().add(branch);
- branchManager.save(branch);
- } else if (!branch.getHeadCommitHash().equals(entry.getValue().getHash())) {
- branch.setHeadCommitHash(entry.getValue().getHash());
- branchManager.save(branch);
- }
- }
-
- String defaultBranchName = repository.git().resolveDefaultBranch();
- if (!branchesInGit.isEmpty() && !branchesInGit.containsKey(defaultBranchName)) {
- defaultBranchName = branchesInGit.keySet().iterator().next();
- repository.git().updateDefaultBranch(defaultBranchName);
- }
-
- for (Branch branch: repository.getBranches()) {
- if (branch.getName().equals(defaultBranchName)) {
- if (!branch.isDefault()) {
- branch.setDefault(true);
- branchManager.save(branch);
- }
- } else if (branch.isDefault()) {
- branch.setDefault(false);
- branchManager.save(branch);
- }
- }
}
@Sessional
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
index be392dae6e..b87bd73977 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
@@ -36,7 +36,7 @@ public class DefaultStorageManager implements StorageManager {
@Override
public File getCacheDir(PullRequest request) {
- File repoCacheDir = getCacheDir(request.getTarget().getRepository());
+ File repoCacheDir = getCacheDir(request.getTargetRepo());
return createIfNotExist(new File(repoCacheDir, "requests/" + request.getId()));
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Branch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Branch.java
deleted file mode 100644
index 18598c51a2..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Branch.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import javax.annotation.Nullable;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
-
-import org.apache.commons.lang3.StringUtils;
-import org.hibernate.annotations.Cache;
-import org.hibernate.annotations.CacheConcurrencyStrategy;
-
-import com.pmease.commons.git.Commit;
-import com.pmease.commons.git.Git;
-import com.pmease.commons.hibernate.AbstractEntity;
-
-@SuppressWarnings("serial")
-@Entity
-@Table(uniqueConstraints={
- @UniqueConstraint(columnNames={"repository", "name"})
-})
-@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
-public class Branch extends AbstractEntity {
-
- private static final String FQN_SEPARATOR = ":";
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private Repository repository;
-
- @ManyToOne(fetch=FetchType.LAZY)
- private User lastUpdater;
-
- @Column(nullable=false)
- private String name;
-
- private boolean isDefault;
-
- @OneToMany(mappedBy="target")
- private Collection<PullRequest> incomingRequests = new ArrayList<>();
-
- @OneToMany(mappedBy="source")
- private Collection<PullRequest> outgoingRequests = new ArrayList<>();
-
- @OneToMany(mappedBy="branch", cascade=CascadeType.REMOVE)
- private Collection<BranchWatch> watches = new ArrayList<>();
-
- private String headCommitHash;
-
- public Repository getRepository() {
- return repository;
- }
-
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
-
- public User getLastUpdater() {
- return lastUpdater;
- }
-
- public void setLastUpdater(User lastUpdater) {
- this.lastUpdater = lastUpdater;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Collection<PullRequest> getIncomingRequests() {
- return incomingRequests;
- }
-
- public void setIncomingRequests(Collection<PullRequest> incomingRequests) {
- this.incomingRequests = incomingRequests;
- }
-
- public Collection<PullRequest> getOutgoingRequests() {
- return outgoingRequests;
- }
-
- public void setOutgoingRequests(Collection<PullRequest> outgoingRequests) {
- this.outgoingRequests = outgoingRequests;
- }
-
- public Collection<BranchWatch> getWatches() {
- return watches;
- }
-
- public void setWatches(Collection<BranchWatch> watches) {
- this.watches = watches;
- }
-
- /**
- * Get head commit this branch pointing to.
- *
- * @return
- * head commit of this branch
- */
- public String getHeadCommitHash() {
- return headCommitHash;
- }
-
- public void setHeadCommitHash(String headCommitHash) {
- this.headCommitHash = headCommitHash;
- }
-
- public Commit getHeadCommit() {
- return getRepository().getCommit(getHeadCommitHash());
- }
-
- public String getHeadRef() {
- return Git.REFS_HEADS + name;
- }
-
- public String getFQN() {
- return getRepository().getFQN() + FQN_SEPARATOR + getName();
- }
-
- public boolean isDefault() {
- return isDefault;
- }
-
- public void setDefault(boolean isDefault) {
- this.isDefault = isDefault;
- }
-
- /**
- * Convert a git reference name to branch name.
- *
- * @param refName
- * name of the git reference
- * @return
- * name of the branch, or <tt>null</tt> if specified ref
- * does not represent a branch
- */
- public static @Nullable String parseName(String refName) {
- if (refName.startsWith(Git.REFS_HEADS))
- return refName.substring(Git.REFS_HEADS.length());
- else
- return null;
- }
-
- @Override
- public String toString() {
- return getFQN();
- }
-
- public static String getNameByFQN(String branchFQN) {
- return StringUtils.substringAfterLast(branchFQN, FQN_SEPARATOR);
- }
-
- public static String getRepositoryFQNByFQN(String branchFQN) {
- return StringUtils.substringBeforeLast(branchFQN, FQN_SEPARATOR);
- }
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/BranchWatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/BranchWatch.java
index c59678b08e..01bb806f3c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/BranchWatch.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/BranchWatch.java
@@ -1,5 +1,6 @@
package com.pmease.gitplex.core.model;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
@@ -18,13 +19,24 @@ public class BranchWatch extends AbstractEntity {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
- private Branch branch;
+ private Repository repository;
- public Branch getBranch() {
+ @Column(nullable=false)
+ private String branch;
+
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
+
+ public String getBranch() {
return branch;
}
- public void setBranch(Branch branch) {
+ public void setBranch(String branch) {
this.branch = branch;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPreview.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPreview.java
index faa0e0ccd8..93e874319e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPreview.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPreview.java
@@ -77,9 +77,9 @@ public class IntegrationPreview implements Serializable {
public boolean isObsolete(PullRequest request) {
if (getRequestHead().equals(request.getLatestUpdate().getHeadCommitHash())
- && getTargetHead().equals(request.getTarget().getHeadCommitHash())
+ && getTargetHead().equals(request.getTarget().getHead())
&& getIntegrationStrategy() == request.getIntegrationStrategy()
- && (getIntegrated() == null || getIntegrated().equals(request.getTarget().getRepository().getObjectId(request.getIntegrateRef(), true).getName()))) {
+ && (getIntegrated() == null || getIntegrated().equals(request.getTarget().getHead()))) {
return false;
} else {
return true;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
index eb3cd4279d..088a116b5d 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
@@ -13,7 +13,6 @@ import java.util.Set;
import java.util.concurrent.Callable;
import javax.annotation.Nullable;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
@@ -23,6 +22,8 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
@@ -31,6 +32,7 @@ import com.google.common.base.Preconditions;
import com.pmease.commons.git.Change;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.AbstractEntity;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.hibernate.dao.EntityCriteria;
@@ -144,13 +146,15 @@ public class PullRequest extends AbstractEntity {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
- private Branch target;
+ private Repository targetRepo;
+
+ @Column(nullable=false)
+ private String targetBranch;
@ManyToOne(fetch=FetchType.LAZY)
- private Branch source;
+ private Repository sourceRepo;
- // record name of source branch so that we can restore it even after source branch is deleted
- private String sourceFQN;
+ private String sourceBranch;
@Column(nullable=false)
private String baseCommitHash;
@@ -176,28 +180,36 @@ public class PullRequest extends AbstractEntity {
@Column(nullable=false)
private IntegrationStrategy integrationStrategy;
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestUpdate> updates = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<ReviewInvitation> reviewInvitations = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestVerification> verifications = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestComment> comments = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestActivity> activities = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestNotification> notifications = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestVisit> visits = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="request")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestWatch> watches = new ArrayList<>();
private transient CheckResult checkResult;
@@ -270,47 +282,65 @@ public class PullRequest extends AbstractEntity {
this.assignee = assignee;
}
- /**
- * Get target branch of this request.
- *
- * @return
- * target branch of this request
- */
- public Branch getTarget() {
- return target;
+ public Repository getTargetRepo() {
+ return targetRepo;
+ }
+
+ public RepoAndBranch getTarget() {
+ return new RepoAndBranch(getTargetRepo(), getTargetBranch());
+ }
+
+ public void setTarget(RepoAndBranch target) {
+ setTargetRepo(target.getRepository());
+ setTargetBranch(target.getBranch());
+ }
+
+ public void setSource(RepoAndBranch source) {
+ setSourceRepo(source.getRepository());
+ setSourceBranch(source.getBranch());
+ }
+
+ public void setTargetRepo(Repository targetRepo) {
+ this.targetRepo = targetRepo;
}
- public void setTarget(@Nullable Branch target) {
- this.target = target;
+ public String getTargetBranch() {
+ return targetBranch;
+ }
+
+ public void setTargetBranch(String targetBranch) {
+ this.targetBranch = targetBranch;
}
- /**
- * Get source branch of this request.
- *
- * @return
- * source branch of this request, or <tt>null</tt> if source branch
- * is deleted. In case of source branch being deleted, the pull request
- * may still in opened state for review, but can not be updated with
- * new commits
- */
@Nullable
- public Branch getSource() {
- return source;
+ public Repository getSourceRepo() {
+ return sourceRepo;
}
- public void setSource(@Nullable Branch source) {
- this.source = source;
+ public void setSourceRepo(Repository sourceRepo) {
+ this.sourceRepo = sourceRepo;
}
- @Nullable
- public String getSourceFQN() {
- return sourceFQN;
+ public String getSourceBranch() {
+ return sourceBranch;
}
- public void setSourceFQN(String sourceFQN) {
- this.sourceFQN = sourceFQN;
+ public void setSourceBranch(String sourceBranch) {
+ this.sourceBranch = sourceBranch;
}
+ public RepoAndBranch getSource() {
+ return new RepoAndBranch(getSourceRepo(), getSourceBranch());
+ }
+
+ public String getTargetRef() {
+ return GitUtils.branch2ref(getTargetBranch());
+ }
+
+ public String getSourceRef() {
+ return GitUtils.branch2ref(getSourceBranch());
+ }
+
public String getBaseCommitHash() {
return baseCommitHash;
}
@@ -320,12 +350,12 @@ public class PullRequest extends AbstractEntity {
}
public Commit getBaseCommit() {
- return getTarget().getRepository().getCommit(getBaseCommitHash());
+ return getTargetRepo().getCommit(getBaseCommitHash());
}
public Git git() {
if (sandbox == null)
- return getTarget().getRepository().git();
+ return getTargetRepo().git();
else
return sandbox;
}
@@ -463,7 +493,7 @@ public class PullRequest extends AbstractEntity {
*/
public CheckResult getCheckResult() {
if (checkResult == null)
- checkResult = getTarget().getRepository().getGateKeeper().checkRequest(this);
+ checkResult = getTargetRepo().getGateKeeper().checkRequest(this);
return checkResult;
}
@@ -526,10 +556,10 @@ public class PullRequest extends AbstractEntity {
if (effectiveUpdates == null) {
effectiveUpdates = new ArrayList<PullRequestUpdate>();
- Git git = getTarget().getRepository().git();
+ Git git = getTargetRepo().git();
for (int i=getSortedUpdates().size()-1; i>=0; i--) {
PullRequestUpdate update = getSortedUpdates().get(i);
- if (!git.isAncestor(update.getHeadCommitHash(), getTarget().getHeadCommitHash()))
+ if (!git.isAncestor(update.getHeadCommitHash(), getTarget().getHead()))
effectiveUpdates.add(update);
else
break;
@@ -554,8 +584,8 @@ public class PullRequest extends AbstractEntity {
}
public Collection<String> findTouchedFiles() {
- Git git = getTarget().getRepository().git();
- return git.listChangedFiles(getTarget().getHeadCommitHash(), getLatestUpdate().getHeadCommitHash(), null);
+ Git git = getTargetRepo().git();
+ return git.listChangedFiles(getTarget().getHead(), getLatestUpdate().getHeadCommitHash(), null);
}
@JsonView(ExternalView.class)
@@ -574,7 +604,7 @@ public class PullRequest extends AbstractEntity {
* Delete refs of this pull request, without touching refs of its updates.
*/
public void deleteRefs() {
- Git git = getTarget().getRepository().git();
+ Git git = getTargetRepo().git();
git.deleteRef(getBaseRef(), null, null);
git.deleteRef(getIntegrateRef(), null, null);
}
@@ -681,12 +711,16 @@ public class PullRequest extends AbstractEntity {
return Restrictions.isNotNull("closeStatus");
}
- public static Criterion ofTarget(Branch target) {
- return Restrictions.eq("target", target);
+ public static Criterion ofTarget(RepoAndBranch target) {
+ return Restrictions.and(
+ Restrictions.eq("targetRepo", target.getRepository()),
+ Restrictions.eq("targetBranch", target.getBranch()));
}
- public static Criterion ofSource(Branch source) {
- return Restrictions.eq("source", source);
+ public static Criterion ofSource(RepoAndBranch source) {
+ return Restrictions.and(
+ Restrictions.eq("sourceRepo", source.getRepository()),
+ Restrictions.eq("sourceBranch", source.getBranch()));
}
public static Criterion ofSubmitter(User submitter) {
@@ -728,8 +762,8 @@ public class PullRequest extends AbstractEntity {
public Set<String> getPendingCommits() {
if (pendingCommits == null) {
pendingCommits = new HashSet<>();
- Repository repo = getTarget().getRepository();
- for (Commit commit: repo.git().log(getTarget().getHeadCommitHash(), getLatestUpdate().getHeadCommitHash(), null, 0, 0))
+ Repository repo = getTargetRepo();
+ for (Commit commit: repo.git().log(getTarget().getHead(), getLatestUpdate().getHeadCommitHash(), null, 0, 0))
pendingCommits.add(commit.getHash());
}
return pendingCommits;
@@ -763,9 +797,8 @@ public class PullRequest extends AbstractEntity {
if (mergedCommits == null) {
mergedCommits = new HashSet<>();
- Branch target = getTarget();
- Repository repo = target.getRepository();
- for (Commit commit: repo.git().log(getBaseCommitHash(), target.getHeadCommitHash(), null, 0, 0))
+ Repository repo = getTargetRepo();
+ for (Commit commit: repo.git().log(getBaseCommitHash(), getTarget().getHead(), null, 0, 0))
mergedCommits.add(commit);
}
return mergedCommits;
@@ -845,7 +878,7 @@ public class PullRequest extends AbstractEntity {
if (invitation.isPreferred())
alreadyInvited.add(invitation.getReviewer());
}
- ObjectPermission readPerm = ObjectPermission.ofRepoPull(getTarget().getRepository());
+ ObjectPermission readPerm = ObjectPermission.ofRepoPull(getTargetRepo());
for (User user: GitPlex.getInstance(Dao.class).allOf(User.class)) {
if (user.asSubject().isPermitted(readPerm) && !alreadyInvited.contains(user))
reviewers.add(user);
@@ -872,7 +905,7 @@ public class PullRequest extends AbstractEntity {
}
public String getUrl() {
- return GitPlex.getInstance().guessServerUrl() + "/" + getTarget().getRepository().getFQN()
+ return GitPlex.getInstance().guessServerUrl() + "/" + getTargetRepo().getFQN()
+ "/pull_requests/" + getId() + "/overview";
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
index 987aa3918b..c01e9bb47e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
@@ -6,7 +6,6 @@ import java.util.Date;
import java.util.List;
import javax.annotation.Nullable;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
@@ -17,6 +16,8 @@ import javax.persistence.OneToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
import com.google.common.base.Preconditions;
import com.pmease.commons.git.BlobIdent;
@@ -51,7 +52,8 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
private boolean resolved;
- @OneToMany(mappedBy="comment", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="comment")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestCommentReply> replies = new ArrayList<>();
@Embedded
@@ -103,7 +105,7 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
@Override
public Repository getRepository() {
- return request.getTarget().getRepository();
+ return request.getTargetRepo();
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestOperation.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestOperation.java
index ae1fe39aac..f9e9a68cc5 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestOperation.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestOperation.java
@@ -16,7 +16,7 @@ public enum PullRequestOperation {
@Override
public boolean canOperate(PullRequest request) {
if (!SecurityUtils.getSubject().isPermitted(
- ObjectPermission.ofRepoPush(request.getTarget().getRepository()))) {
+ ObjectPermission.ofRepoPush(request.getTargetRepo()))) {
return false;
} else {
return GitPlex.getInstance(PullRequestManager.class).canIntegrate(request);
@@ -82,16 +82,18 @@ public enum PullRequestOperation {
PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
if (request.isOpen()
|| !SecurityUtils.canModify(request)
- || request.getSource() == null
+ || request.getTarget().getHead(false) == null
+ || request.getSourceRepo() == null
+ || request.getSource().getHead(false) == null
|| pullRequestManager.findOpen(request.getTarget(), request.getSource()) != null) {
return false;
}
// now check if source branch is integrated into target branch
- Git git = request.getTarget().getRepository().git();
- String sourceHead = request.getSource().getHeadCommitHash();
+ Git git = request.getTargetRepo().git();
+ String sourceHead = request.getSource().getHead();
return git.parseRevision(sourceHead, false) == null
- || !git.isAncestor(sourceHead, request.getTarget().getHeadCommitHash());
+ || !git.isAncestor(sourceHead, request.getTarget().getHead());
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java
index 026668a0dc..6319950a18 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java
@@ -13,13 +13,15 @@ import java.util.Map;
import java.util.Stack;
import java.util.concurrent.Callable;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
@@ -39,16 +41,14 @@ public class PullRequestUpdate extends AbstractEntity {
@JoinColumn(nullable=false)
private PullRequest request;
- @ManyToOne
- private User user;
-
@Column(nullable=false)
private String headCommitHash;
@Column(nullable=false)
private Date date;
- @OneToMany(mappedBy="update", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="update")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<Review> reviews = new ArrayList<Review>();
private transient List<Commit> commits;
@@ -63,14 +63,6 @@ public class PullRequestUpdate extends AbstractEntity {
this.request = request;
}
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
public String getHeadCommitHash() {
return headCommitHash;
}
@@ -116,7 +108,7 @@ public class PullRequestUpdate extends AbstractEntity {
}
public void deleteRefs() {
- Git git = getRequest().getTarget().getRepository().git();
+ Git git = getRequest().getTargetRepo().git();
git.deleteRef(getHeadRef(), null, null);
}
@@ -160,13 +152,13 @@ public class PullRequestUpdate extends AbstractEntity {
public CachedInfo call() throws Exception {
CachedInfo cachedInfo = new CachedInfo();
- Git git = getRequest().getTarget().getRepository().git();
+ Git git = getRequest().getTargetRepo().git();
List<Commit> log = git.log(getBaseCommitHash(), getHeadCommitHash(), null, 0, 0);
if (log.isEmpty())
- log = Lists.newArrayList(getRequest().getTarget().getRepository().getCommit(getHeadCommitHash()));
+ log = Lists.newArrayList(getRequest().getTargetRepo().getCommit(getHeadCommitHash()));
cachedInfo.setLogCommits(log);
- String mergeBase = git.calcMergeBase(getHeadCommitHash(), getRequest().getTarget().getHeadCommitHash());
+ String mergeBase = git.calcMergeBase(getHeadCommitHash(), getRequest().getTarget().getHead());
if (git.isAncestor(getBaseCommitHash(), mergeBase)) {
cachedInfo.setChangedFiles(git.listChangedFiles(mergeBase, getHeadCommitHash(), null));
@@ -186,7 +178,7 @@ public class PullRequestUpdate extends AbstractEntity {
* This way changed files of this update will exclude merged changes
* from target branch if there is any.
*/
- String branchName = getRequest().getTarget().getName();
+ String branchName = getRequest().getTargetBranch();
tempGit.clone(git.repoDir().getAbsolutePath(), false, true, true, branchName);
tempGit.updateRef("HEAD", mergeBase, null, null);
tempGit.reset(null, null);
@@ -264,7 +256,7 @@ public class PullRequestUpdate extends AbstractEntity {
mergedCommits.put(commit.getHash(), scoredCommit);
}
- headCommit = mergedCommits.get(getRequest().getTarget().getHeadCommitHash());
+ headCommit = mergedCommits.get(getRequest().getTarget().getHead());
if (headCommit != null) {
headCommit.setScore(0);
updateAffinityScores(mergedCommits, headCommit);
@@ -276,7 +268,7 @@ public class PullRequestUpdate extends AbstractEntity {
commits.add(commit.getCommit());
}
- getRequest().getTarget().getRepository().cacheCommits(commits);
+ getRequest().getTargetRepo().cacheCommits(commits);
Collections.reverse(commits);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/RepoAndBranch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/RepoAndBranch.java
new file mode 100644
index 0000000000..1f469c51ce
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/RepoAndBranch.java
@@ -0,0 +1,91 @@
+package com.pmease.gitplex.core.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jgit.lib.ObjectId;
+
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+
+public class RepoAndBranch implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String SEPARATOR = "-";
+
+ private final Long repoId;
+
+ private final String branch;
+
+ private transient Repository repository;
+
+ public RepoAndBranch(Long repoId, String branch) {
+ this.repoId = repoId;
+ this.branch = branch;
+ }
+
+ public RepoAndBranch(Repository repository, String branch) {
+ this.repoId = repository.getId();
+ this.branch = branch;
+
+ this.repository = repository;
+ }
+
+ public RepoAndBranch(String id) {
+ this(Long.valueOf(StringUtils.substringBefore(id, SEPARATOR)),
+ StringUtils.substringAfter(id, SEPARATOR));
+ }
+
+ public Long getRepoId() {
+ return repoId;
+ }
+
+ public String getBranch() {
+ return branch;
+ }
+
+ public static void trim(Collection<RepoAndBranch> repoAndBranches) {
+ Dao dao = GitPlex.getInstance(Dao.class);
+ for (Iterator<RepoAndBranch> it = repoAndBranches.iterator(); it.hasNext();) {
+ if (dao.get(Repository.class, it.next().getRepoId()) == null)
+ it.remove();
+ }
+ }
+
+ public Repository getRepository() {
+ if (repository == null)
+ repository = GitPlex.getInstance(Dao.class).load(Repository.class, repoId);
+ return repository;
+ }
+
+ public String getFQN() {
+ return getRepository().getBranchFQN(branch);
+ }
+
+ public String getId() {
+ return repoId + SEPARATOR + branch;
+ }
+
+ @Nullable
+ public String getHead(boolean mustExist) {
+ ObjectId commitId = getRepository().getObjectId(getBranch(), mustExist);
+ return commitId!=null?commitId.name():null;
+ }
+
+ public String getHead() {
+ return getHead(true);
+ }
+
+ public boolean isDefault() {
+ return getRepository().getDefaultBranch().equals(getBranch());
+ }
+
+ public void delete() {
+ getRepository().deleteBranch(getBranch());
+ }
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
index 50f6d336eb..5093f5e590 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
@@ -14,7 +14,6 @@ import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import javax.annotation.Nullable;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -45,6 +44,8 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.base.Optional;
@@ -57,6 +58,7 @@ import com.pmease.commons.git.BlobText;
import com.pmease.commons.git.Change;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.git.Submodule;
import com.pmease.commons.git.exception.ObjectNotExistException;
import com.pmease.commons.hibernate.AbstractEntity;
@@ -68,7 +70,7 @@ import com.pmease.commons.util.StringUtils;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.gatekeeper.AndGateKeeper;
import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-import com.pmease.gitplex.core.manager.BranchManager;
+import com.pmease.gitplex.core.listeners.RepositoryListener;
import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.permission.object.ProtectedObject;
import com.pmease.gitplex.core.permission.object.UserBelonging;
@@ -113,11 +115,16 @@ public class Repository extends AbstractEntity implements UserBelonging {
@Column(nullable=false)
private Date createdAt = new Date();
- @OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)
- private Collection<Authorization> authorizations = new ArrayList<>();
-
+ @OneToMany(mappedBy="targetRepo")
+ @OnDelete(action=OnDeleteAction.CASCADE)
+ private Collection<PullRequest> incomingRequests = new ArrayList<>();
+
+ @OneToMany(mappedBy="sourceRepo")
+ private Collection<PullRequest> outgoingRequests = new ArrayList<>();
+
@OneToMany(mappedBy="repository")
- private Collection<Branch> branches = new ArrayList<>();
+ @OnDelete(action=OnDeleteAction.CASCADE)
+ private Collection<Authorization> authorizations = new ArrayList<>();
@OneToMany(mappedBy="forkedFrom")
private Collection<Repository> forks = new ArrayList<>();
@@ -134,7 +141,9 @@ public class Repository extends AbstractEntity implements UserBelonging {
private transient Map<String, Map<String, Ref>> refsCache = new HashMap<>();
- private transient Branch defaultBranch;
+ private transient Collection<String> branches;
+
+ private transient String defaultBranch;
public User getOwner() {
return owner;
@@ -198,6 +207,22 @@ public class Repository extends AbstractEntity implements UserBelonging {
return getOwner();
}
+ public Collection<PullRequest> getIncomingRequests() {
+ return incomingRequests;
+ }
+
+ public void setIncomingRequests(Collection<PullRequest> incomingRequests) {
+ this.incomingRequests = incomingRequests;
+ }
+
+ public Collection<PullRequest> getOutgoingRequests() {
+ return outgoingRequests;
+ }
+
+ public void setOutgoingRequests(Collection<PullRequest> outgoingRequests) {
+ this.outgoingRequests = outgoingRequests;
+ }
+
public Collection<Authorization> getAuthorizations() {
return authorizations;
}
@@ -222,23 +247,12 @@ public class Repository extends AbstractEntity implements UserBelonging {
this.forks = forks;
}
- /**
- * Get branches for this repository from database. The result might be
- * different from actual branches in repository. To get actual
- * branches in repository, call {@link BranchManager#listBranches(Repository)}
- * instead.
- *
- * @return
- * collection of branches available in database for this repository
- */
- public Collection<Branch> getBranches() {
+ public Collection<String> getBranches() {
+ if (branches == null)
+ branches = git().listBranches();
return branches;
}
- public void setBranches(Collection<Branch> branches) {
- this.branches = branches;
- }
-
@Override
public boolean has(ProtectedObject object) {
if (object instanceof Repository) {
@@ -358,16 +372,9 @@ public class Repository extends AbstractEntity implements UserBelonging {
return GitPlex.getInstance().guessServerUrl() + "/" + getFQN();
}
- public Branch getDefaultBranch() {
- if (defaultBranch == null) {
- for (Branch branch: getBranches()) {
- if (branch.isDefault()) {
- defaultBranch = branch;
- break;
- }
- }
- Preconditions.checkNotNull(defaultBranch);
- }
+ public String getDefaultBranch() {
+ if (defaultBranch == null)
+ defaultBranch = git().resolveDefaultBranch();
return defaultBranch;
}
@@ -375,7 +382,7 @@ public class Repository extends AbstractEntity implements UserBelonging {
if (revision != null)
return revision;
else
- return getDefaultBranch().getName();
+ return getDefaultBranch();
}
/**
@@ -397,7 +404,7 @@ public class Repository extends AbstractEntity implements UserBelonging {
Blob blob = blobCache.get(ident);
if (blob == null) {
try (FileRepository jgitRepo = openAsJGitRepo(); RevWalk revWalk = new RevWalk(jgitRepo)) {
- ObjectId commitId = getObjectId(ident.revision, true);
+ ObjectId commitId = getObjectId(ident.revision);
RevTree revTree = revWalk.parseCommit(commitId).getTree();
TreeWalk treeWalk = TreeWalk.forPath(jgitRepo, ident.path, revTree);
if (treeWalk != null) {
@@ -433,7 +440,7 @@ public class Repository extends AbstractEntity implements UserBelonging {
public InputStream getInputStream(BlobIdent ident) {
try (FileRepository jgitRepo = openAsJGitRepo(); RevWalk revWalk = new RevWalk(jgitRepo)) {
- ObjectId commitId = getObjectId(ident.revision, true);
+ ObjectId commitId = getObjectId(ident.revision);
RevTree revTree = revWalk.parseCommit(commitId).getTree();
TreeWalk treeWalk = TreeWalk.forPath(jgitRepo, ident.path, revTree);
if (treeWalk != null) {
@@ -501,8 +508,12 @@ public class Repository extends AbstractEntity implements UserBelonging {
return optional.orNull();
}
- public void cacheObjectId(String revision, ObjectId objectId) {
- objectIdCache.put(revision, Optional.of(objectId));
+ public ObjectId getObjectId(String revision) {
+ return getObjectId(revision, true);
+ }
+
+ public void cacheObjectId(String revision, @Nullable ObjectId objectId) {
+ objectIdCache.put(revision, Optional.fromNullable(objectId));
}
public List<Change> getChanges(String fromCommit, String toCommit) {
@@ -597,7 +608,7 @@ public class Repository extends AbstractEntity implements UserBelonging {
cache = null;
}
- final AnyObjectId commitId = getObjectId(revision, true);
+ final AnyObjectId commitId = getObjectId(revision);
try (FileRepository jgitRepo = openAsJGitRepo()) {
long time = System.currentTimeMillis();
@@ -660,4 +671,15 @@ public class Repository extends AbstractEntity implements UserBelonging {
return submodules;
}
+
+ public String getBranchFQN(String branch) {
+ return getFQN() + ":" + branch;
+ }
+
+ public void deleteBranch(String branch) {
+ git().deleteBranch(branch);
+ for (RepositoryListener listener: GitPlex.getExtensions(RepositoryListener.class))
+ listener.onRefUpdate(this, GitUtils.branch2ref(branch), null);
+ }
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java
index 6d9a8e7b4b..89ff8d3d66 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java
@@ -3,7 +3,6 @@ package com.pmease.gitplex.core.model;
import java.util.ArrayList;
import java.util.Collection;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -15,6 +14,8 @@ import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.base.Objects;
@@ -44,10 +45,12 @@ public class Team extends AbstractEntity {
@Column(nullable=false)
private RepositoryOperation authorizedOperation = RepositoryOperation.NO_ACCESS;
- @OneToMany(mappedBy="team", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="team")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<Membership> memberships = new ArrayList<Membership>();
- @OneToMany(mappedBy="team", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="team")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<Authorization> authorizations = new ArrayList<Authorization>();
public User getOwner() {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
index eb0e1d8da1..7c3e953985 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
@@ -12,6 +11,8 @@ import javax.persistence.OneToMany;
import org.eclipse.jgit.lib.PersonIdent;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
@@ -41,40 +42,50 @@ public class User extends AbstractUser implements ProtectedObject {
private int reviewEffort;
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="user")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<Membership> memberships = new ArrayList<>();
@OneToMany(mappedBy="owner")
private Collection<Repository> repositories = new ArrayList<>();
- @OneToMany(mappedBy="owner", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="owner")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<Team> teams = new ArrayList<Team>();
@OneToMany(mappedBy="submitter")
private Collection<PullRequest> submittedRequests = new ArrayList<>();
- @OneToMany(mappedBy="reviewer", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="reviewer")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<Review> reviews = new ArrayList<Review>();
- @OneToMany(mappedBy="reviewer", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="reviewer")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<ReviewInvitation> reviewInvitations = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="user")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestComment> requestComments = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="user")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestCommentReply> requestCommentReplies = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="user")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<BranchWatch> branchWatches = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="user")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestWatch> requestWatches = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="user")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestNotification> requestNotifications = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
+ @OneToMany(mappedBy="user")
+ @OnDelete(action=OnDeleteAction.CASCADE)
private Collection<PullRequestVisit> requestVisits = new ArrayList<>();
@Editable(order=100)
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
index c46292e783..1bfa86a64d 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
@@ -10,8 +10,8 @@ import com.pmease.commons.hibernate.dao.EntityCriteria;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.Comment;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.Team;
@@ -31,7 +31,7 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
}
public static boolean canModify(PullRequest request) {
- Repository repository = request.getTarget().getRepository();
+ Repository repository = request.getTargetRepo();
if (SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoAdmin(repository))) {
return true;
} else {
@@ -42,7 +42,7 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
}
public static boolean canModify(Review review) {
- Repository repository = review.getUpdate().getRequest().getTarget().getRepository();
+ Repository repository = review.getUpdate().getRequest().getTargetRepo();
if (SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoAdmin(repository))) {
return true;
} else {
@@ -64,19 +64,26 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
}
}
- public static boolean canCreate(Repository repository, String branchName) {
+ public static boolean canCreate(RepoAndBranch repoAndBranch) {
+ return canCreate(repoAndBranch.getRepository(), repoAndBranch.getBranch());
+ }
+
+ public static boolean canCreate(Repository repository, String branch) {
User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();
return currentUser != null
&& currentUser.asSubject().isPermitted(ObjectPermission.ofRepoPush(repository))
- && repository.getGateKeeper().checkRef(currentUser, repository, Git.REFS_HEADS + branchName).isPassed();
+ && repository.getGateKeeper().checkRef(currentUser, repository, Git.REFS_HEADS + branch).isPassed();
}
- public static boolean canModify(Branch branch) {
+ public static boolean canModify(RepoAndBranch repoAndBranch) {
+ return canModify(repoAndBranch.getRepository(), repoAndBranch.getBranch());
+ }
+
+ public static boolean canModify(Repository repository, String branch) {
User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();
- Repository repository = branch.getRepository();
return currentUser != null
&& currentUser.asSubject().isPermitted(ObjectPermission.ofRepoPush(repository))
- && repository.getGateKeeper().checkRef(currentUser, repository, Git.REFS_HEADS + branch.getName()).isPassed();
+ && repository.getGateKeeper().checkRef(currentUser, repository, Git.REFS_HEADS + branch).isPassed();
}
public static boolean canManage(User account) {
diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/DirectionProtectionTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/DirectionProtectionTest.java
index 72a0151cf9..9f0d739df9 100644
--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/DirectionProtectionTest.java
+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/DirectionProtectionTest.java
@@ -2,6 +2,7 @@ package com.pmease.gitplex.core.gatekeeper;
import static org.junit.Assert.assertTrue;
+import org.eclipse.jgit.lib.ObjectId;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -11,9 +12,8 @@ import com.pmease.commons.git.AbstractGitTest;
import com.pmease.commons.git.Git;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.loader.AppLoader;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;
+import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
import com.pmease.gitplex.core.gatekeeper.helper.pathselection.SpecifyTargetPathsByDirectories;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.Team;
@@ -29,16 +29,6 @@ public class DirectionProtectionTest extends AbstractGitTest {
super.setup();
Mockito.when(AppLoader.getInstance(Dao.class)).thenReturn(dao);
- Branch branch1 = new Branch();
- branch1.setId(1L);
- branch1.setName("branch1");
- Mockito.when(dao.load(Branch.class, 1L)).thenReturn(branch1);
-
- Branch branch2 = new Branch();
- branch2.setId(2L);
- branch2.setName("branch2");
- Mockito.when(dao.load(Branch.class, 2L)).thenReturn(branch2);
-
Team team = new Team();
team.setName("team");
team.setId(1L);
@@ -53,8 +43,8 @@ public class DirectionProtectionTest extends AbstractGitTest {
@Test
public void testCheckFile() {
DirectoryAndFileProtection pathProtection = new DirectoryAndFileProtection();
- SpecifyTargetBranchesByIds branchSelection = new SpecifyTargetBranchesByIds();
- branchSelection.setBranchIds(Lists.newArrayList(1L));
+ SpecifyTargetBranchesByNames branchSelection = new SpecifyTargetBranchesByNames();
+ branchSelection.setBranches(Lists.newArrayList("branch1"));
pathProtection.setBranchSelection(branchSelection);
SpecifyTargetPathsByDirectories pathSelection = new SpecifyTargetPathsByDirectories();
@@ -76,24 +66,19 @@ public class DirectionProtectionTest extends AbstractGitTest {
User user2 = new User();
user2.setId(2L);
- Branch branch1 = new Branch();
- branch1.setId(1L);
- branch1.setName("branch1");
- Branch branch2 = new Branch();
- branch2.setId(2L);
- branch2.setName("branch2");
- assertTrue(pathProtection.checkFile(user1, branch1, "src/test.java").isPassed());
- assertTrue(pathProtection.checkFile(user1, branch1, "doc/test.pdf").isPassed());
- assertTrue(pathProtection.checkFile(user2, branch1, "src/test.java").isPending());
- assertTrue(pathProtection.checkFile(user2, branch2, "src/test.java").isPassed());
+ Repository repo = new Repository();
+ assertTrue(pathProtection.checkFile(user1, repo, "branch1", "src/test.java").isPassed());
+ assertTrue(pathProtection.checkFile(user1, repo, "branch1", "doc/test.pdf").isPassed());
+ assertTrue(pathProtection.checkFile(user2, repo, "branch1", "src/test.java").isPending());
+ assertTrue(pathProtection.checkFile(user2, repo, "branch2", "src/test.java").isPassed());
}
@SuppressWarnings("serial")
@Test
public void testCheckCommit() {
DirectoryAndFileProtection pathProtection = new DirectoryAndFileProtection();
- SpecifyTargetBranchesByIds branchSelection = new SpecifyTargetBranchesByIds();
- branchSelection.setBranchIds(Lists.newArrayList(1L));
+ SpecifyTargetBranchesByNames branchSelection = new SpecifyTargetBranchesByNames();
+ branchSelection.setBranches(Lists.newArrayList("branch1"));
pathProtection.setBranchSelection(branchSelection);
SpecifyTargetPathsByDirectories pathSelection = new SpecifyTargetPathsByDirectories();
@@ -106,19 +91,16 @@ public class DirectionProtectionTest extends AbstractGitTest {
git.checkout("master", "branch1");
git.checkout("master", "branch2");
-
- Branch branch1 = new Branch();
- branch1.setName("branch1");
- branch1.setHeadCommitHash(git.parseRevision("branch1", true));
- branch1.setId(1L);
- branch1.setRepository(new Repository() {
+
+ Repository repo = new Repository() {
@Override
public Git git() {
return git;
}
- });
+ };
+ repo.cacheObjectId("branch1", ObjectId.fromString(git.parseRevision("branch1", true)));
User user1 = new User();
user1.setId(1L);
@@ -128,15 +110,15 @@ public class DirectionProtectionTest extends AbstractGitTest {
addFileAndCommit("src/file2", "", "add src/file2");
- assertTrue(pathProtection.checkCommit(user1, branch1, git.parseRevision("branch2", true)).isPassed());
- assertTrue(pathProtection.checkCommit(user2, branch1, git.parseRevision("branch2", true)).isPending());
+ assertTrue(pathProtection.checkCommit(user1, repo, "branch1", git.parseRevision("branch2", true)).isPassed());
+ assertTrue(pathProtection.checkCommit(user2, repo, "branch1", git.parseRevision("branch2", true)).isPending());
git.checkout("master", "branch3");
addFileAndCommit("docs/file2", "", "add docs/file2");
- assertTrue(pathProtection.checkCommit(user1, branch1, git.parseRevision("branch3", true)).isPassed());
- assertTrue(pathProtection.checkCommit(user2, branch1, git.parseRevision("branch3", true)).isPassed());
+ assertTrue(pathProtection.checkCommit(user1, repo, "branch1", git.parseRevision("branch3", true)).isPassed());
+ assertTrue(pathProtection.checkCommit(user2, repo, "branch1", git.parseRevision("branch3", true)).isPassed());
}
}
diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.java
index b19d356189..2717ffcca0 100644
--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.java
+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.java
@@ -3,6 +3,7 @@ package com.pmease.gitplex.core.gatekeeper;
import java.util.ArrayList;
import java.util.Collection;
+import org.eclipse.jgit.lib.ObjectId;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mock;
@@ -12,7 +13,6 @@ import com.pmease.commons.git.AbstractGitTest;
import com.pmease.commons.git.Git;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.loader.AppLoader;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestUpdate;
@@ -31,15 +31,6 @@ public class IfApprovedByMajoritiesOfSpecifiedTeamTest extends AbstractGitTest {
super.setup();
Mockito.when(AppLoader.getInstance(Dao.class)).thenReturn(dao);
- Branch branch1 = new Branch();
- branch1.setId(1L);
- branch1.setName("branch1");
- Mockito.when(dao.load(Branch.class, 1L)).thenReturn(branch1);
-
- Branch branch2 = new Branch();
- branch2.setId(2L);
- branch2.setName("branch2");
- Mockito.when(dao.load(Branch.class, 2L)).thenReturn(branch2);
Team team = new Team();
team.setName("team");
@@ -73,9 +64,7 @@ public class IfApprovedByMajoritiesOfSpecifiedTeamTest extends AbstractGitTest {
User user1 = new User();
user1.setId(1L);
- Branch branch1 = new Branch();
- branch1.setId(1L);
- Assert.assertTrue(gateKeeper.checkFile(user1, branch1, "src/file").isPending());
+ Assert.assertTrue(gateKeeper.checkFile(user1, new Repository(), "branch1", "src/file").isPending());
}
@SuppressWarnings("serial")
@@ -90,34 +79,35 @@ public class IfApprovedByMajoritiesOfSpecifiedTeamTest extends AbstractGitTest {
IfApprovedByMajoritiesOfSpecifiedTeam gateKeeper = new IfApprovedByMajoritiesOfSpecifiedTeam();
gateKeeper.setTeamId(1L);
- PullRequest request = new PullRequest();
- request.setId(1L);
- request.setTarget(new Branch());
- request.getTarget().setName("master");
- request.getTarget().setHeadCommitHash(git.parseRevision("master", true));
- request.getTarget().setRepository(new Repository() {
+ Repository targetRepo = new Repository() {
@Override
public Git git() {
return git;
}
- });
- request.getTarget().getRepository().setId(1L);
- request.getTarget().getRepository().setOwner(new User());
- request.getTarget().getRepository().getOwner().setId(1L);
+ };
+ targetRepo.setId(1L);
+ targetRepo.setOwner(new User());
+ targetRepo.getOwner().setId(1L);
+ targetRepo.cacheObjectId("master", ObjectId.fromString(git.parseRevision("master", true)));
- request.setSource(new Branch());
- request.getSource().setName("dev");
- request.getSource().setHeadCommitHash(git.parseRevision("dev", true));
- request.getSource().setRepository(new Repository() {
-
+ PullRequest request = new PullRequest();
+ request.setId(1L);
+ request.setTargetRepo(targetRepo);
+ request.setTargetBranch("master");
+
+ Repository sourceRepo = new Repository() {
+
@Override
public Git git() {
return git;
}
- });
+ };
+ sourceRepo.cacheObjectId("dev", ObjectId.fromString(git.parseRevision("dev", true)));
+ request.setSourceRepo(sourceRepo);
+ request.setSourceBranch("dev");
request.setSubmitter(new User());
request.getSubmitter().setId(2L);
diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestTest.java
index dd2af2f965..4071b574eb 100644
--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestTest.java
+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestTest.java
@@ -1,5 +1,6 @@
package com.pmease.gitplex.core.model;
+import org.eclipse.jgit.lib.ObjectId;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
@@ -21,10 +22,8 @@ public class PullRequestTest extends AbstractGitTest {
@Test
public void shouldReturnAllUpdatesAsEffectiveIfTheyAreFastForward() {
PullRequest request = new PullRequest();
- Branch target = new Branch();
- target.setName("master");
- target.setRepository(repository);
- request.setTarget(target);
+ request.setTargetRepo(repository);
+ request.setTargetBranch("master");
addFileAndCommit("a", "", "commit");
@@ -32,7 +31,7 @@ public class PullRequestTest extends AbstractGitTest {
addFileAndCommit("b", "", "commit");
- target.setHeadCommitHash(git.parseRevision("master", true));
+ repository.cacheObjectId("master", ObjectId.fromString(git.parseRevision("master", true)));
request.setBaseCommitHash(git.parseRevision("master", true));
@@ -58,10 +57,8 @@ public class PullRequestTest extends AbstractGitTest {
@Test
public void shouldReturnLatestUpdateAsEffectiveIfAllOthersHaveBeenMerged() {
PullRequest request = new PullRequest();
- Branch target = new Branch();
- target.setName("master");
- target.setRepository(repository);
- request.setTarget(target);
+ request.setTargetRepo(repository);
+ request.setTargetBranch("master");
addFileAndCommit("a", "", "master:1");
@@ -96,7 +93,7 @@ public class PullRequestTest extends AbstractGitTest {
git.merge(secondRef, null, null, null, null);
- target.setHeadCommitHash(git.parseRevision("master", true));
+ repository.cacheObjectId("master", ObjectId.fromString(git.parseRevision("master", true)));
Assert.assertEquals(1, request.getEffectiveUpdates().size());
Assert.assertEquals(2L, request.getEffectiveUpdates().get(0).getId().longValue());
diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java
index c47c633d5d..361109461e 100644
--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java
+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java
@@ -2,6 +2,7 @@ package com.pmease.gitplex.core.model;
import java.io.File;
+import org.eclipse.jgit.lib.ObjectId;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
@@ -62,10 +63,8 @@ public class PullRequestUpdateTest extends AbstractGitTest {
@Test
public void testResolveChangedFilesWhenThereIsNoMerge() {
PullRequest request = new PullRequest();
- Branch target = new Branch();
- target.setRepository(repository);
- target.setName("master");
- request.setTarget(target);
+ request.setTargetRepo(repository);
+ request.setTargetBranch("master");
addFileAndCommit("a", "", "master:1");
@@ -98,7 +97,7 @@ public class PullRequestUpdateTest extends AbstractGitTest {
bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
request.addUpdate(update2);
- target.setHeadCommitHash(bareGit.parseRevision("master", true));
+ repository.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
Assert.assertEquals(Sets.newHashSet("c"), update2.getChangedFiles());
Assert.assertEquals(Sets.newHashSet("b"), update1.getChangedFiles());
@@ -107,10 +106,8 @@ public class PullRequestUpdateTest extends AbstractGitTest {
@Test
public void testResolveChangedFilesWhenThereIsMerge() {
PullRequest request = new PullRequest();
- Branch target = new Branch();
- target.setRepository(repository);
- target.setName("master");
- request.setTarget(target);
+ request.setTargetRepo(repository);
+ request.setTargetBranch("master");
addFileAndCommit("1", "", "master:1");
@@ -143,7 +140,7 @@ public class PullRequestUpdateTest extends AbstractGitTest {
bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
request.addUpdate(update2);
- target.setHeadCommitHash(bareGit.parseRevision("master", true));
+ repository.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
Assert.assertEquals(Sets.newHashSet("4"), update2.getChangedFiles());
}
@@ -151,10 +148,8 @@ public class PullRequestUpdateTest extends AbstractGitTest {
@Test
public void testGetCommitsWhenTargetBranchIsMergedToSourceBranch() {
PullRequest request = new PullRequest();
- Branch target = new Branch();
- target.setRepository(repository);
- target.setName("master");
- request.setTarget(target);
+ request.setTargetRepo(repository);
+ request.setTargetBranch("master");
addFileAndCommit("0", "", "0");
@@ -191,7 +186,7 @@ public class PullRequestUpdateTest extends AbstractGitTest {
bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
request.addUpdate(update2);
- target.setHeadCommitHash(bareGit.parseRevision("master", true));
+ repository.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
Assert.assertEquals(2, update1.getCommits().size());
Assert.assertEquals("d1", update1.getCommits().get(0).getMessage());
@@ -204,10 +199,8 @@ public class PullRequestUpdateTest extends AbstractGitTest {
@Test
public void testGetCommitsWhenSourceBranchIsMergedToTargetBranch() {
PullRequest request = new PullRequest();
- Branch target = new Branch();
- target.setRepository(repository);
- target.setName("master");
- request.setTarget(target);
+ request.setTargetRepo(repository);
+ request.setTargetBranch("master");
addFileAndCommit("0", "", "0");
@@ -250,7 +243,7 @@ public class PullRequestUpdateTest extends AbstractGitTest {
request.addUpdate(update2);
- target.setHeadCommitHash(bareGit.parseRevision("master", true));
+ repository.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
Assert.assertEquals(2, update2.getCommits().size());
Assert.assertEquals("d2", update2.getCommits().get(0).getMessage());
diff --git a/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/BranchResource.java b/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/BranchResource.java
deleted file mode 100644
index 9b8d900ee4..0000000000
--- a/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/BranchResource.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package com.pmease.gitplex.rest.resource;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.shiro.authz.UnauthorizedException;
-import org.hibernate.criterion.Restrictions;
-
-import com.google.common.collect.Lists;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.jersey.ValidQueryParams;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.permission.ObjectPermission;
-import com.pmease.gitplex.core.security.SecurityUtils;
-
-@Path("/branches")
-@Consumes(MediaType.WILDCARD)
-@Produces(MediaType.APPLICATION_JSON)
-@Singleton
-public class BranchResource {
-
- private final Dao dao;
-
- private final BranchManager branchManager;
-
- @Inject
- public BranchResource(Dao dao, BranchManager branchManager) {
- this.dao = dao;
- this.branchManager = branchManager;
- }
-
- @GET
- @Path("/{id}")
- public Branch get(@PathParam("id") Long id) {
- Branch branch = dao.load(Branch.class, id);
- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPull(branch.getRepository())))
- throw new UnauthorizedException();
- return branch;
- }
-
- @ValidQueryParams
- @GET
- public Collection<Branch> query(@QueryParam("repository") Long repositoryId, @QueryParam("name") String name,
- @QueryParam("path") String path) {
- if (path != null) {
- Branch branch = branchManager.findBy(path);
- if (branch != null)
- return Lists.newArrayList(branch);
- else
- return new ArrayList<>();
- }
-
- EntityCriteria<Branch> criteria = EntityCriteria.of(Branch.class);
- if (repositoryId != null)
- criteria.add(Restrictions.eq("repository.id", repositoryId));
- if (name != null)
- criteria.add(Restrictions.eq("name", name));
- List<Branch> branches = dao.query(criteria);
-
- for (Branch branch: branches) {
- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPull(branch.getRepository()))) {
- throw new UnauthorizedException("Unauthorized access to branch " + branch);
- }
- }
-
- return branches;
- }
-
- @DELETE
- @Path("/{id}")
- public void delete(@PathParam("id") Long id) {
- Branch branch = dao.load(Branch.class, id);
-
- if (!SecurityUtils.canModify(branch))
- throw new UnauthorizedException();
-
- dao.remove(branch);
- }
-
- @POST
- public Long save(@NotNull @Valid Branch branch) {
- if (!SecurityUtils.canModify(branch))
- throw new UnauthorizedException();
-
- dao.persist(branch);
-
- return branch.getId();
- }
-
-}
diff --git a/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/PullRequestResource.java b/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/PullRequestResource.java
deleted file mode 100644
index c820623370..0000000000
--- a/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/PullRequestResource.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.pmease.gitplex.rest.resource;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.authz.UnauthorizedException;
-import org.hibernate.criterion.Restrictions;
-
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.jersey.ValidQueryParams;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.permission.ObjectPermission;
-
-@Path("/pull_requests")
-@Consumes(MediaType.WILDCARD)
-@Produces(MediaType.APPLICATION_JSON)
-@Singleton
-public class PullRequestResource {
-
- private final Dao dao;
-
- private final BranchManager branchManager;
-
- @Inject
- public PullRequestResource(Dao dao, BranchManager branchManager) {
- this.dao = dao;
- this.branchManager = branchManager;
- }
-
- @GET
- @Path("/{id}")
- public PullRequest get(@PathParam("id") Long id) {
- PullRequest request = dao.load(PullRequest.class, id);
-
- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPull(request.getTarget().getRepository())))
- throw new UnauthorizedException();
-
- return request;
- }
-
- @ValidQueryParams
- @GET
- public Collection<PullRequest> query(
- @QueryParam("target") Long targetId, @QueryParam("targetPath") String targetPath,
- @QueryParam("source") Long sourceId, @QueryParam("sourcePath") String sourcePath,
- @QueryParam("submitter") Long submitterId, @QueryParam("status") String status) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
-
- if (targetId != null) {
- criteria.add(Restrictions.eq("target.id", targetId));
- } else if (targetPath != null) {
- Branch target = branchManager.findBy(targetPath);
- if (target != null)
- criteria.add(Restrictions.eq("target.id", target.getId()));
- else
- return new ArrayList<>();
- }
-
- if (sourceId != null) {
- criteria.add(Restrictions.eq("source.id", sourceId));
- } else if (sourcePath != null) {
- Branch source = branchManager.findBy(sourcePath);
- if (source != null)
- criteria.add(Restrictions.eq("source.id", source.getId()));
- else
- return new ArrayList<>();
- }
-
- if (submitterId != null)
- criteria.add(Restrictions.eq("submitter.id", submitterId));
- if (status != null) {
- if (status.equals("open"))
- criteria.add(PullRequest.CriterionHelper.ofOpen());
- else if (status.equals("closed"))
- criteria.add(PullRequest.CriterionHelper.ofClosed());
- else
- throw new IllegalArgumentException("status");
- }
-
- List<PullRequest> requests = dao.query(criteria);
-
- for (PullRequest request: requests) {
- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPull(request.getTarget().getRepository())))
- throw new UnauthorizedException("Unauthorized access to pull request " + request.getTarget() + "/" + request.getId());
- }
- return requests;
- }
-
-}
diff --git a/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/VerificationResource.java b/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/VerificationResource.java
index 5aec40a776..ebbc63f74f 100644
--- a/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/VerificationResource.java
+++ b/gitplex.rest/src/main/java/com/pmease/gitplex/rest/resource/VerificationResource.java
@@ -48,7 +48,7 @@ public class VerificationResource {
@Path("/{id}")
public PullRequestVerification get(@PathParam("id") Long id) {
PullRequestVerification verification = dao.load(PullRequestVerification.class, id);
- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPull(verification.getRequest().getTarget().getRepository())))
+ if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPull(verification.getRequest().getTargetRepo())))
throw new UnauthorizedException();
return verification;
}
@@ -71,7 +71,7 @@ public class VerificationResource {
for (PullRequestVerification verification: verifications) {
if (!SecurityUtils.getSubject().isPermitted(
- ObjectPermission.ofRepoPull(verification.getRequest().getTarget().getRepository()))) {
+ ObjectPermission.ofRepoPull(verification.getRequest().getTargetRepo()))) {
throw new UnauthorizedException("Unauthorized access to verification "
+ verification.getRequest() + "/" + verification.getId());
}
@@ -84,7 +84,7 @@ public class VerificationResource {
@Path("/{id}")
public void delete(@PathParam("id") Long id) {
PullRequestVerification verification = dao.load(PullRequestVerification.class, id);
- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPush(verification.getRequest().getTarget().getRepository())))
+ if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPush(verification.getRequest().getTargetRepo())))
throw new UnauthorizedException();
verificationManager.delete(verification);
@@ -92,7 +92,7 @@ public class VerificationResource {
@POST
public Long save(@NotNull @Valid PullRequestVerification verification) {
- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPush(verification.getRequest().getTarget().getRepository())))
+ if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPush(verification.getRequest().getTargetRepo())))
throw new UnauthorizedException();
verificationManager.save(verification);
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java
index 864aeeeadc..70d2561cfe 100644
--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java
+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java
@@ -281,7 +281,7 @@ public class DefaultIndexManager implements IndexManager {
@Override
public IndexResult index(final Repository repository, final String revision) {
- final AnyObjectId commitId = repository.getObjectId(revision, true);
+ final AnyObjectId commitId = repository.getObjectId(revision);
logger.info("Indexing commit '{}' of repository '{}'...", commitId.getName(), repository);
@@ -340,21 +340,9 @@ public class DefaultIndexManager implements IndexManager {
return String.valueOf(INDEX_VERSION);
}
- @Override
- public void repositoryRemoved(Repository repository) {
- for (IndexListener listener: listeners)
- listener.indexRemoving(repository);
- FileUtils.deleteDir(storageManager.getIndexDir(repository));
- }
-
- @Override
- public void commitReceived(Repository repository, String commitHash) {
- index(repository, commitHash);
- }
-
@Override
public boolean isIndexed(Repository repository, String revision) {
- AnyObjectId commitId = repository.getObjectId(revision, true);
+ AnyObjectId commitId = repository.getObjectId(revision);
File indexDir = storageManager.getIndexDir(repository);
try (Directory directory = FSDirectory.open(indexDir)) {
if (DirectoryReader.indexExists(directory)) {
@@ -373,4 +361,21 @@ public class DefaultIndexManager implements IndexManager {
private String getLockName(Repository repository) {
return "index: " + repository.getId();
}
+
+ @Override
+ public void beforeDelete(Repository repository) {
+ }
+
+ @Override
+ public void afterDelete(Repository repository) {
+ for (IndexListener listener: listeners)
+ listener.indexRemoving(repository);
+ FileUtils.deleteDir(storageManager.getIndexDir(repository));
+ }
+
+ @Override
+ public void onRefUpdate(Repository repository, String refName, String newCommitHash) {
+ if (newCommitHash != null)
+ index(repository, newCommitHash);
+ }
}
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java
index 4eda047577..a6f68caf3d 100644
--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java
+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java
@@ -79,7 +79,7 @@ public class DefaultSearchManager implements SearchManager, IndexListener, Lifec
@Override
public List<QueryHit> search(Repository repository, String revision, final BlobQuery query)
throws InterruptedException {
- AnyObjectId commitId = repository.getObjectId(revision, true);
+ AnyObjectId commitId = repository.getObjectId(revision);
final List<QueryHit> hits = new ArrayList<>();
diff --git a/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java b/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java
index 8ef4ce6cbd..a1ce943c91 100644
--- a/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java
+++ b/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java
@@ -274,7 +274,7 @@ public class IndexAndSearchTest extends AbstractGitTest {
@Override
protected void teardown() {
super.teardown();
- indexManager.repositoryRemoved(repository);
+ indexManager.afterDelete(repository);
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
index 48d56bfc2c..635b3f4232 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
@@ -295,7 +295,7 @@ public class SourceViewPanel extends BlobViewPanel {
if (context.getState().blame) {
List<BlameCommit> commits = new ArrayList<>();
- String commitHash = context.getRepository().getObjectId(context.getState().file.revision, true).name();
+ String commitHash = context.getRepository().getObjectId(context.getState().file.revision).name();
for (Blame blame: context.getRepository().git().blame(commitHash, context.getState().file.path).values()) {
BlameCommit commit = new BlameCommit();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/symbollink/SymbolLinkPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/symbollink/SymbolLinkPanel.java
index 8788fd9b91..442708dd0c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/symbollink/SymbolLinkPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/symbollink/SymbolLinkPanel.java
@@ -42,7 +42,7 @@ public class SymbolLinkPanel extends BlobViewPanel {
if (targetPath != null) {
try ( FileRepository jgitRepo = context.getRepository().openAsJGitRepo();
RevWalk revWalk = new RevWalk(jgitRepo)) {
- ObjectId commitId = context.getRepository().getObjectId(context.getState().file.revision, true);
+ ObjectId commitId = context.getRepository().getObjectId(context.getState().file.revision);
RevTree revTree = revWalk.parseCommit(commitId).getTree();
TreeWalk treeWalk = TreeWalk.forPath(jgitRepo, targetPath, revTree);
if (treeWalk == null)
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchMultiChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchMultiChoice.java
index ca1727bca1..8bb681babf 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchMultiChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchMultiChoice.java
@@ -10,16 +10,16 @@ import org.apache.wicket.model.IModel;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.repochoice.AffinalRepositoryChoice;
@SuppressWarnings("serial")
-public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Branch>> {
+public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<RepoAndBranch>> {
- private IModel<Repository> currentRepositoryModel;
+ private IModel<Repository> currentRepoModel;
- private IModel<Repository> selectedRepositoryModel;
+ private IModel<Repository> selectedRepoModel;
private Long repoId;
@@ -30,18 +30,18 @@ public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Bran
*
* @param id
* id of the component
- * @param currentRepositoryModel
+ * @param currentRepoModel
* model of current repository. Note that the model object should never be null
* @param selectedBranchesModel
* model of selected branch
*/
- public AffinalBranchMultiChoice(String id, IModel<Repository> currentRepositoryModel,
- IModel<Collection<Branch>> selectedBranchesModel) {
+ public AffinalBranchMultiChoice(String id, IModel<Repository> currentRepoModel,
+ IModel<Collection<RepoAndBranch>> selectedBranchesModel) {
super(id, selectedBranchesModel);
- this.currentRepositoryModel = currentRepositoryModel;
+ this.currentRepoModel = currentRepoModel;
- selectedRepositoryModel = new IModel<Repository>() {
+ selectedRepoModel = new IModel<Repository>() {
@Override
public void detach() {
@@ -52,18 +52,18 @@ public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Bran
if (repoId != null) {
return GitPlex.getInstance(Dao.class).load(Repository.class, repoId);
} else {
- Collection<Branch> branches = getBranches();
- if (branches == null || branches.isEmpty())
- return AffinalBranchMultiChoice.this.currentRepositoryModel.getObject();
+ Collection<RepoAndBranch> repoAndBranches = getRepoAndBranches();
+ if (repoAndBranches == null || repoAndBranches.isEmpty())
+ return AffinalBranchMultiChoice.this.currentRepoModel.getObject();
else
- return branches.iterator().next().getRepository();
+ return repoAndBranches.iterator().next().getRepository();
}
}
@Override
public void setObject(Repository object) {
repoId = object.getId();
- setBranches(new HashSet<Branch>());
+ setRepoAndBranches(new HashSet<RepoAndBranch>());
}
};
@@ -79,7 +79,7 @@ public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Bran
setOutputMarkupId(true);
- add(new AffinalRepositoryChoice("repositoryChoice", currentRepositoryModel, selectedRepositoryModel).add(new AjaxFormComponentUpdatingBehavior("change") {
+ add(new AffinalRepositoryChoice("repositoryChoice", currentRepoModel, selectedRepoModel).add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
@@ -89,7 +89,7 @@ public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Bran
}));
- BranchChoiceProvider choiceProvider = new BranchChoiceProvider(selectedRepositoryModel);
+ BranchChoiceProvider choiceProvider = new BranchChoiceProvider(selectedRepoModel);
add(branchChoice = new BranchMultiChoice("branchChoice", getModel(), choiceProvider));
branchChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
@@ -102,12 +102,12 @@ public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Bran
});
}
- private Collection<Branch> getBranches() {
+ private Collection<RepoAndBranch> getRepoAndBranches() {
return getModelObject();
}
- private void setBranches(Collection<Branch> branches) {
- getModel().setObject(branches);
+ private void setRepoAndBranches(Collection<RepoAndBranch> repoAndBranches) {
+ getModel().setObject(repoAndBranches);
}
@Override
@@ -117,8 +117,8 @@ public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Bran
@Override
protected void onDetach() {
- currentRepositoryModel.detach();
- selectedRepositoryModel.detach();
+ currentRepoModel.detach();
+ selectedRepoModel.detach();
super.onDetach();
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchSingleChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchSingleChoice.java
index 39a8c9651c..3c8e1ee8f4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchSingleChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/AffinalBranchSingleChoice.java
@@ -5,12 +5,12 @@ import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.form.FormComponentPanel;
import org.apache.wicket.model.IModel;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.repochoice.AffinalRepositoryChoice;
@SuppressWarnings("serial")
-public class AffinalBranchSingleChoice extends FormComponentPanel<Branch> {
+public class AffinalBranchSingleChoice extends FormComponentPanel<RepoAndBranch> {
private IModel<Repository> currentRepositoryModel;
@@ -23,15 +23,15 @@ public class AffinalBranchSingleChoice extends FormComponentPanel<Branch> {
*
* @param id
* id of the component
- * @param currentRepositoryModel
+ * @param currentRepoModel
* model of current repository. Note that the model object should never be null
* @param selectedBranchModel
* model of selected branch
*/
- public AffinalBranchSingleChoice(String id, IModel<Repository> currentRepositoryModel, IModel<Branch> selectedBranchModel) {
+ public AffinalBranchSingleChoice(String id, IModel<Repository> currentRepoModel, IModel<RepoAndBranch> selectedBranchModel) {
super(id, selectedBranchModel);
- this.currentRepositoryModel = currentRepositoryModel;
+ this.currentRepositoryModel = currentRepoModel;
selectedRepositoryModel = new IModel<Repository>() {
@@ -41,17 +41,16 @@ public class AffinalBranchSingleChoice extends FormComponentPanel<Branch> {
@Override
public Repository getObject() {
- Branch branch = getBranch();
- if (branch == null) {
+ RepoAndBranch repoAndBranch = getRepoAndBranch();
+ if (repoAndBranch == null)
return AffinalBranchSingleChoice.this.currentRepositoryModel.getObject();
- } else {
- return branch.getRepository();
- }
+ else
+ return repoAndBranch.getRepository();
}
@Override
public void setObject(Repository object) {
- setBranch(object.getDefaultBranch());
+ setRepoAndBranch(new RepoAndBranch(object, object.getDefaultBranch()));
}
};
@@ -89,12 +88,12 @@ public class AffinalBranchSingleChoice extends FormComponentPanel<Branch> {
});
}
- private Branch getBranch() {
+ private RepoAndBranch getRepoAndBranch() {
return getModelObject();
}
- private void setBranch(Branch branch) {
- getModel().setObject(branch);
+ private void setRepoAndBranch(RepoAndBranch repoAndBranch) {
+ getModel().setObject(repoAndBranch);
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchChoiceProvider.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchChoiceProvider.java
index 2e055080d3..d66f2a0db9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchChoiceProvider.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchChoiceProvider.java
@@ -1,28 +1,24 @@
package com.pmease.gitplex.web.component.branch;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.wicket.model.IModel;
-import org.hibernate.criterion.MatchMode;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
import org.json.JSONException;
import org.json.JSONWriter;
-import com.google.common.collect.Lists;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.Constants;
import com.vaynberg.wicket.select2.ChoiceProvider;
import com.vaynberg.wicket.select2.Response;
@SuppressWarnings("serial")
-public class BranchChoiceProvider extends ChoiceProvider<Branch> {
+public class BranchChoiceProvider extends ChoiceProvider<RepoAndBranch> {
private IModel<Repository> repoModel;
@@ -31,40 +27,44 @@ public class BranchChoiceProvider extends ChoiceProvider<Branch> {
}
@Override
- public void query(String term, int page, Response<Branch> response) {
- EntityCriteria<Branch> criteria = EntityCriteria.of(Branch.class);
- criteria.add(Restrictions.eq("repository", repoModel.getObject()));
+ public void query(String term, int page, Response<RepoAndBranch> response) {
+ term = term.toLowerCase();
+ List<RepoAndBranch> repoAndBranches = new ArrayList<>();
+ Repository repository = repoModel.getObject();
+ for (String branch: repository.getBranches()) {
+ if (branch.toLowerCase().startsWith(term))
+ repoAndBranches.add(new RepoAndBranch(repository, branch));
+ }
- criteria.add(Restrictions.ilike("name", term, MatchMode.START));
- criteria.addOrder(Order.asc("name"));
- int first = page * Constants.DEFAULT_PAGE_SIZE;
+ Collections.sort(repoAndBranches, new Comparator<RepoAndBranch>() {
- List<Branch> branches = GitPlex.getInstance(Dao.class).query(criteria, first, Constants.DEFAULT_PAGE_SIZE+1);
- if (branches.size() > Constants.DEFAULT_PAGE_SIZE) {
- branches.remove(branches.size()-1);
- response.addAll(branches);
- response.setHasMore(true);
- } else {
- response.addAll(branches);
- response.setHasMore(false);
- }
+ @Override
+ public int compare(RepoAndBranch o1, RepoAndBranch o2) {
+ return o1.getBranch().compareTo(o2.getBranch());
+ }
+
+ });
+
+ int first = page * Constants.DEFAULT_SELECT2_PAGE_SIZE;
+ int last = first + Constants.DEFAULT_SELECT2_PAGE_SIZE;
+ response.setHasMore(last<repoAndBranches.size());
+ if (last > repoAndBranches.size())
+ last = repoAndBranches.size();
+ response.addAll(repoAndBranches.subList(first, last));
}
@Override
- public void toJson(Branch choice, JSONWriter writer) throws JSONException {
- writer.key("id").value(choice.getId()).key("name").value(StringEscapeUtils.escapeHtml4(choice.getName()));
+ public void toJson(RepoAndBranch choice, JSONWriter writer) throws JSONException {
+ writer.key("id").value(choice.getId()).key("name").value(StringEscapeUtils.escapeHtml4(choice.getBranch()));
}
@Override
- public Collection<Branch> toChoices(Collection<String> ids) {
- List<Branch> branches = Lists.newArrayList();
- Dao dao = GitPlex.getInstance(Dao.class);
- for (String each : ids) {
- Long id = Long.valueOf(each);
- branches.add(dao.load(Branch.class, id));
- }
+ public Collection<RepoAndBranch> toChoices(Collection<String> ids) {
+ List<RepoAndBranch> repoAndBranches = new ArrayList<>();
+ for (String each : ids)
+ repoAndBranches.add(new RepoAndBranch(each));
- return branches;
+ return repoAndBranches;
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchLink.java
index a315a14813..828281e325 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchLink.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchLink.java
@@ -7,19 +7,19 @@ import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.permission.ObjectPermission;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@SuppressWarnings("serial")
public class BranchLink extends Panel {
- public BranchLink(String id, IModel<Branch> model) {
+ public BranchLink(String id, IModel<RepoAndBranch> model) {
super(id, model);
}
- private Branch getBranch() {
- return (Branch) getDefaultModelObject();
+ private RepoAndBranch getRepoAndBranch() {
+ return (RepoAndBranch) getDefaultModelObject();
}
@Override
@@ -36,7 +36,7 @@ public class BranchLink extends Panel {
protected void onConfigure() {
super.onConfigure();
setEnabled(SecurityUtils.getSubject().isPermitted(
- ObjectPermission.ofRepoPull(getBranch().getRepository())));
+ ObjectPermission.ofRepoPull(getRepoAndBranch().getRepository())));
}
};
@@ -48,12 +48,12 @@ public class BranchLink extends Panel {
public String getObject() {
if (getPage() instanceof RepositoryPage) {
RepositoryPage page = (RepositoryPage) getPage();
- if (page.getRepository().equals(getBranch().getRepository()))
- return getBranch().getName();
+ if (page.getRepository().equals(getRepoAndBranch().getRepository()))
+ return getRepoAndBranch().getBranch();
else
- return getBranch().getFQN();
+ return getRepoAndBranch().getFQN();
} else {
- return getBranch().getFQN();
+ return getRepoAndBranch().getFQN();
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchMultiChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchMultiChoice.java
index 10b67ae2c3..e285f84673 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchMultiChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchMultiChoice.java
@@ -5,13 +5,13 @@ import java.util.Collection;
import org.apache.wicket.model.IModel;
import com.pmease.commons.wicket.component.select2.Select2MultiChoice;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.vaynberg.wicket.select2.ChoiceProvider;
@SuppressWarnings("serial")
-public class BranchMultiChoice extends Select2MultiChoice<Branch> {
+public class BranchMultiChoice extends Select2MultiChoice<RepoAndBranch> {
- public BranchMultiChoice(String id, IModel<Collection<Branch>> model, ChoiceProvider<Branch> provider) {
+ public BranchMultiChoice(String id, IModel<Collection<RepoAndBranch>> model, ChoiceProvider<RepoAndBranch> provider) {
super(id, model, provider);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchSingleChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchSingleChoice.java
index ff997cbe60..10184d5519 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchSingleChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/BranchSingleChoice.java
@@ -3,13 +3,13 @@ package com.pmease.gitplex.web.component.branch;
import org.apache.wicket.model.IModel;
import com.pmease.commons.wicket.component.select2.Select2Choice;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.vaynberg.wicket.select2.ChoiceProvider;
@SuppressWarnings("serial")
-public class BranchSingleChoice extends Select2Choice<Branch> {
+public class BranchSingleChoice extends Select2Choice<RepoAndBranch> {
- public BranchSingleChoice(String id, IModel<Branch> model, ChoiceProvider<Branch> branchesProvider) {
+ public BranchSingleChoice(String id, IModel<RepoAndBranch> model, ChoiceProvider<RepoAndBranch> branchesProvider) {
super(id, model, branchesProvider);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchMultiChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchMultiChoice.java
index 2184041f4a..11be13a8b1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchMultiChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchMultiChoice.java
@@ -10,12 +10,12 @@ import org.apache.wicket.model.IModel;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.repochoice.RepositoryChoice;
@SuppressWarnings("serial")
-public class GlobalBranchMultiChoice extends FormComponentPanel<Collection<Branch>> {
+public class GlobalBranchMultiChoice extends FormComponentPanel<Collection<RepoAndBranch>> {
private Long repoId;
@@ -31,8 +31,8 @@ public class GlobalBranchMultiChoice extends FormComponentPanel<Collection<Branc
* @param branchesModel
* model of selected branches
*/
- public GlobalBranchMultiChoice(String id, IModel<Collection<Branch>> branchesModel) {
- super(id, branchesModel);
+ public GlobalBranchMultiChoice(String id, IModel<Collection<RepoAndBranch>> repoAndBranchesModel) {
+ super(id, repoAndBranchesModel);
repositoryModel = new IModel<Repository>() {
@@ -45,18 +45,18 @@ public class GlobalBranchMultiChoice extends FormComponentPanel<Collection<Branc
if (repoId != null) {
return GitPlex.getInstance(Dao.class).load(Repository.class, repoId);
} else {
- Collection<Branch> branches = getBranches();
- if (branches == null || branches.isEmpty())
+ Collection<RepoAndBranch> repoAndBranches = getRepoAndBranches();
+ if (repoAndBranches == null || repoAndBranches.isEmpty())
return null;
else
- return branches.iterator().next().getRepository();
+ return repoAndBranches.iterator().next().getRepository();
}
}
@Override
public void setObject(Repository object) {
repoId = object.getId();
- setBranches(new HashSet<Branch>());
+ setRepoAndBranches(new HashSet<RepoAndBranch>());
}
};
@@ -95,12 +95,12 @@ public class GlobalBranchMultiChoice extends FormComponentPanel<Collection<Branc
});
}
- private Collection<Branch> getBranches() {
+ private Collection<RepoAndBranch> getRepoAndBranches() {
return getModelObject();
}
- private void setBranches(Collection<Branch> branches) {
- getModel().setObject(branches);
+ private void setRepoAndBranches(Collection<RepoAndBranch> repoAndBranches) {
+ getModel().setObject(repoAndBranches);
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchSingleChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchSingleChoice.java
index 0cfb609fe9..829a2b73ea 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchSingleChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branch/GlobalBranchSingleChoice.java
@@ -5,12 +5,12 @@ import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.form.FormComponentPanel;
import org.apache.wicket.model.IModel;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.repochoice.RepositoryChoice;
@SuppressWarnings("serial")
-public class GlobalBranchSingleChoice extends FormComponentPanel<Branch> {
+public class GlobalBranchSingleChoice extends FormComponentPanel<RepoAndBranch> {
private IModel<Repository> repositoryModel;
@@ -24,7 +24,7 @@ public class GlobalBranchSingleChoice extends FormComponentPanel<Branch> {
* @param branchModel
* model of selected branch
*/
- public GlobalBranchSingleChoice(String id, IModel<Branch> branchModel) {
+ public GlobalBranchSingleChoice(String id, IModel<RepoAndBranch> branchModel) {
super(id, branchModel);
repositoryModel = new IModel<Repository>() {
@@ -35,16 +35,16 @@ public class GlobalBranchSingleChoice extends FormComponentPanel<Branch> {
@Override
public Repository getObject() {
- Branch branch = getBranch();
- if (branch != null)
- return branch.getRepository();
+ RepoAndBranch repoAndBranch = getRepoAndBranch();
+ if (repoAndBranch != null)
+ return repoAndBranch.getRepository();
else
return null;
}
@Override
public void setObject(Repository object) {
- setBranch(object.getDefaultBranch());
+ setRepoAndBranch(new RepoAndBranch(object, object.getDefaultBranch()));
}
};
@@ -82,12 +82,12 @@ public class GlobalBranchSingleChoice extends FormComponentPanel<Branch> {
});
}
- private Branch getBranch() {
+ private RepoAndBranch getRepoAndBranch() {
return getModelObject();
}
- private void setBranch(Branch branch) {
- getModel().setObject(branch);
+ private void setRepoAndBranch(RepoAndBranch repoAndBranch) {
+ getModel().setObject(repoAndBranch);
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directorychooser/DirectoryChooser.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directorychooser/DirectoryChooser.java
index b97f29cfc4..6f27eec4b3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directorychooser/DirectoryChooser.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directorychooser/DirectoryChooser.java
@@ -16,13 +16,13 @@ import org.eclipse.jgit.lib.FileMode;
import com.pmease.commons.git.Git;
import com.pmease.commons.git.TreeNode;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
@SuppressWarnings("serial")
public abstract class DirectoryChooser extends Panel {
- public DirectoryChooser(String id, IModel<Branch> branchModel) {
- super(id, branchModel);
+ public DirectoryChooser(String id, IModel<RepoAndBranch> repoAndBranchModel) {
+ super(id, repoAndBranchModel);
}
@Override
@@ -37,9 +37,9 @@ public abstract class DirectoryChooser extends Panel {
@Override
public Iterator<? extends TreeNode> getRoots() {
- if (getBranch() != null) {
- Git git = getBranch().getRepository().git();
- List<TreeNode> roots = git.listTree(getBranch().getName(), null);
+ if (getRepoAndBranch() != null) {
+ Git git = getRepoAndBranch().getRepository().git();
+ List<TreeNode> roots = git.listTree(getRepoAndBranch().getBranch(), null);
if (roots != null) {
for (Iterator<TreeNode> it = roots.iterator(); it.hasNext();) {
if (it.next().getMode() != FileMode.TYPE_TREE)
@@ -61,7 +61,7 @@ public abstract class DirectoryChooser extends Panel {
@Override
public Iterator<? extends TreeNode> getChildren(TreeNode node) {
- List<TreeNode> children = getBranch().getRepository().git().listTree(getBranch().getName(), node.getPath() + "/");
+ List<TreeNode> children = getRepoAndBranch().getRepository().git().listTree(getRepoAndBranch().getBranch(), node.getPath() + "/");
for (Iterator<TreeNode> it = children.iterator(); it.hasNext();) {
if (it.next().getMode() != FileMode.TYPE_TREE)
it.remove();
@@ -96,8 +96,8 @@ public abstract class DirectoryChooser extends Panel {
});
}
- public Branch getBranch() {
- return (Branch) getDefaultModelObject();
+ public RepoAndBranch getRepoAndBranch() {
+ return (RepoAndBranch) getDefaultModelObject();
}
protected abstract MarkupContainer newLinkComponent(String id, IModel<TreeNode> node);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.java
index 982c6e80da..2e9765bc15 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.java
@@ -263,7 +263,7 @@ public abstract class FileListPanel extends Panel {
protected abstract void onSelect(AjaxRequestTarget target, BlobIdent file);
private ObjectId getCommitId() {
- return repoModel.getObject().getObjectId(directory.revision, true);
+ return repoModel.getObject().getObjectId(directory.revision);
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java
index 6bc3b499d2..02c15ef6d9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java
@@ -335,7 +335,7 @@ public abstract class FileNavigator extends Panel {
}
private ObjectId getCommitId() {
- return repoModel.getObject().getObjectId(file.revision, true);
+ return repoModel.getObject().getObjectId(file.revision);
}
protected abstract void onSelect(AjaxRequestTarget target, BlobIdent blobIdent);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerAvatar.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerAvatar.java
index d1d6c64fd5..c1d4ad2993 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerAvatar.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerAvatar.java
@@ -44,7 +44,7 @@ public class ReviewerAvatar extends RemoveableAvatar {
if (!request.isNew())
reviewEffective = request.isReviewEffective(getUser());
setEnabled(request.isOpen() && !reviewEffective
- && (request.getSubmitter().equals(currentUser) || SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoAdmin(request.getTarget().getRepository()))));
+ && (request.getSubmitter().equals(currentUser) || SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoAdmin(request.getTargetRepo()))));
}
@Override
@@ -60,7 +60,7 @@ public class ReviewerAvatar extends RemoveableAvatar {
each.setDate(new Date());
}
}
- request.getTarget().getRepository().getGateKeeper().checkRequest(request);
+ request.getTargetRepo().getGateKeeper().checkRequest(request);
Set<User> nowInvited = new HashSet<>();
for (ReviewInvitation each: request.getReviewInvitations()) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerChoice.java
index d9ff7c2e7c..c39766d4d8 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/ReviewerChoice.java
@@ -36,7 +36,7 @@ public abstract class ReviewerChoice extends SelectToAddChoice<User> {
User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();
setVisible(request.isOpen()
&& !request.getPotentialReviewers().isEmpty()
- && (request.getSubmitter().equals(currentUser) || SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoAdmin(request.getTarget().getRepository()))));
+ && (request.getSubmitter().equals(currentUser) || SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoAdmin(request.getTargetRepo()))));
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java
index 6ad7b04415..c69d5ba439 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java
@@ -10,22 +10,20 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.convert.ConversionException;
import com.pmease.commons.editable.PropertyDescriptor;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.branch.AffinalBranchMultiChoice;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@SuppressWarnings("serial")
-public class AffinalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
+public class AffinalBranchMultiChoiceEditor extends PropertyEditor<List<RepoAndBranch>> {
private AffinalBranchMultiChoice input;
- public AffinalBranchMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<Long>> propertyModel) {
+ public AffinalBranchMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<RepoAndBranch>> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -46,14 +44,11 @@ public class AffinalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
@Override
protected Object load() {
- List<Branch> branches = new ArrayList<>();
- if (getModelObject() != null) {
- Dao dao = GitPlex.getInstance(Dao.class);
- for (Long branchId: getModelObject())
- branches.add(dao.load(Branch.class, branchId));
- }
-
- return branches;
+ List<RepoAndBranch> repoAndBranches = getModelObject();
+ if (repoAndBranches != null)
+ return repoAndBranches;
+ else
+ return new ArrayList<>();
}
});
@@ -67,14 +62,12 @@ public class AffinalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
}
@Override
- protected List<Long> convertInputToValue() throws ConversionException {
- List<Long> branchIds = new ArrayList<>();
- Collection<Branch> branches = input.getConvertedInput();
- if (branches != null) {
- for (Branch branch: branches)
- branchIds.add(branch.getId());
- }
- return branchIds;
+ protected List<RepoAndBranch> convertInputToValue() throws ConversionException {
+ List<RepoAndBranch> repoAndBranches = new ArrayList<>();
+ Collection<RepoAndBranch> convertedInput = input.getConvertedInput();
+ if (convertedInput != null)
+ repoAndBranches.addAll(convertedInput);
+ return repoAndBranches;
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchSingleChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchSingleChoiceEditor.java
index d24706803f..d913260673 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchSingleChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchSingleChoiceEditor.java
@@ -1,27 +1,25 @@
package com.pmease.gitplex.web.editable.branch;
-import com.pmease.gitplex.core.GitPlex;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.convert.ConversionException;
import com.pmease.commons.editable.PropertyDescriptor;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.branch.AffinalBranchSingleChoice;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@SuppressWarnings("serial")
-public class AffinalBranchSingleChoiceEditor extends PropertyEditor<Long> {
+public class AffinalBranchSingleChoiceEditor extends PropertyEditor<RepoAndBranch> {
private AffinalBranchSingleChoice input;
- public AffinalBranchSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<Long> propertyModel) {
+ public AffinalBranchSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<RepoAndBranch> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -29,11 +27,7 @@ public class AffinalBranchSingleChoiceEditor extends PropertyEditor<Long> {
protected void onInitialize() {
super.onInitialize();
- Branch branch;
- if (getModelObject() != null)
- branch = GitPlex.getInstance(Dao.class).load(Branch.class, getModelObject());
- else
- branch = null;
+ RepoAndBranch repoAndBranch = getModelObject();
input = new AffinalBranchSingleChoice("input", new AbstractReadOnlyModel<Repository>() {
@@ -43,7 +37,7 @@ public class AffinalBranchSingleChoiceEditor extends PropertyEditor<Long> {
return page.getRepository();
}
- }, Model.of(branch));
+ }, Model.of(repoAndBranch));
add(input);
}
@@ -54,12 +48,8 @@ public class AffinalBranchSingleChoiceEditor extends PropertyEditor<Long> {
}
@Override
- protected Long convertInputToValue() throws ConversionException {
- Branch branch = input.getConvertedInput();
- if (branch != null)
- return branch.getId();
- else
- return null;
+ protected RepoAndBranch convertInputToValue() throws ConversionException {
+ return input.getConvertedInput();
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java
index b3f6fe1124..64dad0cb5e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java
@@ -10,19 +10,17 @@ import org.apache.wicket.model.IModel;
import org.eclipse.jgit.util.StringUtils;
import com.google.common.base.Preconditions;
+import com.pmease.commons.editable.DefaultPropertyDescriptor;
import com.pmease.commons.editable.EditableUtils;
import com.pmease.commons.editable.PropertyDescriptor;
-import com.pmease.commons.editable.DefaultPropertyDescriptor;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.BeanContext;
import com.pmease.commons.wicket.editable.EditSupport;
import com.pmease.commons.wicket.editable.NotDefinedLabel;
import com.pmease.commons.wicket.editable.PropertyContext;
import com.pmease.commons.wicket.editable.PropertyEditor;
import com.pmease.commons.wicket.editable.PropertyViewer;
-import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.editable.BranchChoice;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
@SuppressWarnings("serial")
public class BranchEditSupport implements EditSupport {
@@ -39,25 +37,24 @@ public class BranchEditSupport implements EditSupport {
if (propertyGetter.getAnnotation(BranchChoice.class) != null) {
if (List.class.isAssignableFrom(propertyGetter.getReturnType())
&& EditableUtils.getElementClass(propertyGetter.getGenericReturnType()) == Long.class) {
- return new PropertyContext<List<Long>>(propertyDescriptor) {
+ return new PropertyContext<List<RepoAndBranch>>(propertyDescriptor) {
@Override
- public PropertyViewer renderForView(String componentId, final IModel<List<Long>> model) {
+ public PropertyViewer renderForView(String componentId, final IModel<List<RepoAndBranch>> model) {
return new PropertyViewer(componentId, this) {
@Override
protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- List<Long> branchIds = model.getObject();
- if (branchIds != null && !branchIds.isEmpty()) {
- Dao dao = GitPlex.getInstance(Dao.class);
- List<String> branchNames = new ArrayList<>();
- for (Long branchId: branchIds) {
+ List<RepoAndBranch> repoAndBranches = model.getObject();
+ if (repoAndBranches != null && !repoAndBranches.isEmpty()) {
+ List<String> branches = new ArrayList<>();
+ for (RepoAndBranch each: repoAndBranches) {
if (isAffinal(getPropertyGetter()) || isGlobal(getPropertyGetter()))
- branchNames.add(dao.load(Branch.class, branchId).getFQN());
+ branches.add(each.getFQN());
else
- branchNames.add(dao.load(Branch.class, branchId).getName());
+ branches.add(each.getBranch());
}
- return new Label(id, StringUtils.join(branchNames, ", " ));
+ return new Label(id, StringUtils.join(branches, ", " ));
} else {
return new NotDefinedLabel(id);
}
@@ -67,7 +64,7 @@ public class BranchEditSupport implements EditSupport {
}
@Override
- public PropertyEditor<List<Long>> renderForEdit(String componentId, IModel<List<Long>> model) {
+ public PropertyEditor<List<RepoAndBranch>> renderForEdit(String componentId, IModel<List<RepoAndBranch>> model) {
if (isAffinal(getPropertyGetter()))
return new AffinalBranchMultiChoiceEditor(componentId, this, model);
else if (isGlobal(getPropertyGetter()))
@@ -78,21 +75,20 @@ public class BranchEditSupport implements EditSupport {
};
} else if (propertyGetter.getReturnType() == Long.class) {
- return new PropertyContext<Long>(propertyDescriptor) {
+ return new PropertyContext<RepoAndBranch>(propertyDescriptor) {
@Override
- public PropertyViewer renderForView(String componentId, final IModel<Long> model) {
+ public PropertyViewer renderForView(String componentId, final IModel<RepoAndBranch> model) {
return new PropertyViewer(componentId, this) {
@Override
protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- Long branchId = model.getObject();
- if (branchId != null) {
- Branch branch = GitPlex.getInstance(Dao.class).load(Branch.class, branchId);
+ RepoAndBranch repoAndBranch = model.getObject();
+ if (repoAndBranch != null) {
if (isAffinal(getPropertyGetter()) || isGlobal(getPropertyGetter()))
- return new Label(id, branch.getFQN());
+ return new Label(id, repoAndBranch.getFQN());
else
- return new Label(id, branch.getName());
+ return new Label(id, repoAndBranch.getBranch());
} else {
return new NotDefinedLabel(id);
}
@@ -102,7 +98,7 @@ public class BranchEditSupport implements EditSupport {
}
@Override
- public PropertyEditor<Long> renderForEdit(String componentId, IModel<Long> model) {
+ public PropertyEditor<RepoAndBranch> renderForEdit(String componentId, IModel<RepoAndBranch> model) {
if (isAffinal(getPropertyGetter()))
return new AffinalBranchSingleChoiceEditor(componentId, this, model);
else if (isGlobal(getPropertyGetter()))
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java
index 847b5f8458..159663dc68 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java
@@ -9,20 +9,18 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.convert.ConversionException;
import com.pmease.commons.editable.PropertyDescriptor;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.web.component.branch.GlobalBranchMultiChoice;
@SuppressWarnings("serial")
-public class GlobalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
+public class GlobalBranchMultiChoiceEditor extends PropertyEditor<List<RepoAndBranch>> {
private GlobalBranchMultiChoice input;
- public GlobalBranchMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<Long>> propertyModel) {
+ public GlobalBranchMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<RepoAndBranch>> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -30,16 +28,13 @@ public class GlobalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
protected void onInitialize() {
super.onInitialize();
- input = new GlobalBranchMultiChoice("input", new LoadableDetachableModel<Collection<Branch>>() {
+ input = new GlobalBranchMultiChoice("input", new LoadableDetachableModel<Collection<RepoAndBranch>>() {
@Override
- protected Collection<Branch> load() {
- List<Branch> branches = new ArrayList<>();
- if (getModelObject() != null) {
- Dao dao = GitPlex.getInstance(Dao.class);
- for (Long branchId: getModelObject())
- branches.add(dao.load(Branch.class, branchId));
- }
+ protected Collection<RepoAndBranch> load() {
+ List<RepoAndBranch> branches = new ArrayList<>();
+ if (getModelObject() != null)
+ branches.addAll(getModelObject());
return branches;
}
@@ -55,14 +50,14 @@ public class GlobalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
}
@Override
- protected List<Long> convertInputToValue() throws ConversionException {
- List<Long> branchIds = new ArrayList<>();
- Collection<Branch> branches = input.getConvertedInput();
- if (branches != null) {
- for (Branch branch: branches)
- branchIds.add(branch.getId());
- }
- return branchIds;
+ protected List<RepoAndBranch> convertInputToValue() throws ConversionException {
+ List<RepoAndBranch> repoAndBranches = new ArrayList<>();
+
+ Collection<RepoAndBranch> convertedInput = input.getConvertedInput();
+ if (convertedInput != null)
+ repoAndBranches.addAll(convertedInput);
+
+ return repoAndBranches;
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchSingleChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchSingleChoiceEditor.java
index 48249e8328..102d1b778d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchSingleChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchSingleChoiceEditor.java
@@ -1,24 +1,21 @@
package com.pmease.gitplex.web.editable.branch;
import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
import org.apache.wicket.util.convert.ConversionException;
import com.pmease.commons.editable.PropertyDescriptor;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.web.component.branch.GlobalBranchSingleChoice;
@SuppressWarnings("serial")
-public class GlobalBranchSingleChoiceEditor extends PropertyEditor<Long> {
+public class GlobalBranchSingleChoiceEditor extends PropertyEditor<RepoAndBranch> {
private GlobalBranchSingleChoice input;
- public GlobalBranchSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<Long> propertyModel) {
+ public GlobalBranchSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<RepoAndBranch> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -26,13 +23,7 @@ public class GlobalBranchSingleChoiceEditor extends PropertyEditor<Long> {
protected void onInitialize() {
super.onInitialize();
- Branch branch;
- if (getModelObject() != null)
- branch = GitPlex.getInstance(Dao.class).load(Branch.class, getModelObject());
- else
- branch = null;
-
- input = new GlobalBranchSingleChoice("input", Model.of(branch));
+ input = new GlobalBranchSingleChoice("input", getModel());
add(input);
}
@@ -43,12 +34,8 @@ public class GlobalBranchSingleChoiceEditor extends PropertyEditor<Long> {
}
@Override
- protected Long convertInputToValue() throws ConversionException {
- Branch branch = input.getConvertedInput();
- if (branch != null)
- return branch.getId();
- else
- return null;
+ protected RepoAndBranch convertInputToValue() throws ConversionException {
+ return input.getConvertedInput();
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchMultiChoiceEditor.java
index dea274ff38..674562ed4b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchMultiChoiceEditor.java
@@ -1,6 +1,5 @@
package com.pmease.gitplex.web.editable.branch;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -11,23 +10,21 @@ import org.apache.wicket.model.Model;
import org.apache.wicket.util.convert.ConversionException;
import com.pmease.commons.editable.PropertyDescriptor;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.branch.BranchChoiceProvider;
import com.pmease.gitplex.web.component.branch.BranchMultiChoice;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@SuppressWarnings("serial")
-public class LocalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
+public class LocalBranchMultiChoiceEditor extends PropertyEditor<List<RepoAndBranch>> {
private BranchMultiChoice input;
- public LocalBranchMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<Long>> propertyModel) {
+ public LocalBranchMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<RepoAndBranch>> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -46,14 +43,11 @@ public class LocalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
});
- List<Branch> branches = new ArrayList<>();
- if (getModelObject() != null) {
- Dao dao = GitPlex.getInstance(Dao.class);
- for (Long branchId: getModelObject())
- branches.add(dao.load(Branch.class, branchId));
- }
+ ArrayList<RepoAndBranch> repoAndBranches = new ArrayList<>();
+ if (getModelObject() != null)
+ repoAndBranches.addAll(getModelObject());
- input = new BranchMultiChoice("input", new Model((Serializable)branches), branchProvider);
+ input = new BranchMultiChoice("input", new Model(repoAndBranches), branchProvider);
add(input);
}
@@ -64,14 +58,12 @@ public class LocalBranchMultiChoiceEditor extends PropertyEditor<List<Long>> {
}
@Override
- protected List<Long> convertInputToValue() throws ConversionException {
- List<Long> branchIds = new ArrayList<>();
- Collection<Branch> branches = input.getConvertedInput();
- if (branches != null) {
- for (Branch branch: branches)
- branchIds.add(branch.getId());
- }
- return branchIds;
+ protected List<RepoAndBranch> convertInputToValue() throws ConversionException {
+ List<RepoAndBranch> repoAndBranches = new ArrayList<>();
+ Collection<RepoAndBranch> convertedInput = input.getConvertedInput();
+ if (convertedInput != null)
+ repoAndBranches.addAll(convertedInput);
+ return repoAndBranches;
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchSingleChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchSingleChoiceEditor.java
index 806befbd84..7a64a467a0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchSingleChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/LocalBranchSingleChoiceEditor.java
@@ -2,27 +2,24 @@ package com.pmease.gitplex.web.editable.branch;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.model.Model;
import org.apache.wicket.util.convert.ConversionException;
import com.pmease.commons.editable.PropertyDescriptor;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.branch.BranchChoiceProvider;
import com.pmease.gitplex.web.component.branch.BranchSingleChoice;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@SuppressWarnings("serial")
-public class LocalBranchSingleChoiceEditor extends PropertyEditor<Long> {
+public class LocalBranchSingleChoiceEditor extends PropertyEditor<RepoAndBranch> {
private BranchSingleChoice input;
- public LocalBranchSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<Long> propertyModel) {
+ public LocalBranchSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<RepoAndBranch> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -40,12 +37,7 @@ public class LocalBranchSingleChoiceEditor extends PropertyEditor<Long> {
});
- Branch branch;
- if (getModelObject() != null)
- branch = GitPlex.getInstance(Dao.class).load(Branch.class, getModelObject());
- else
- branch = null;
- input = new BranchSingleChoice("input", Model.of(branch), branchProvider);
+ input = new BranchSingleChoice("input", getModel(), branchProvider);
add(input);
}
@@ -56,12 +48,8 @@ public class LocalBranchSingleChoiceEditor extends PropertyEditor<Long> {
}
@Override
- protected Long convertInputToValue() throws ConversionException {
- Branch branch = input.getConvertedInput();
- if (branch != null)
- return branch.getId();
- else
- return null;
+ protected RepoAndBranch convertInputToValue() throws ConversionException {
+ return input.getConvertedInput();
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectoryMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectoryMultiChoiceEditor.java
index 3aa6d200b3..2b3394249d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectoryMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectoryMultiChoiceEditor.java
@@ -23,7 +23,7 @@ import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.web.component.directorychooser.DirectoryChooser;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@@ -54,10 +54,10 @@ public class DirectoryMultiChoiceEditor extends PropertyEditor<List<String>> {
@Override
protected Component newContent(String id) {
RepositoryPage page = (RepositoryPage) getPage();
- Branch defaultBranch = page.getRepository().getDefaultBranch();
+ String defaultBranch = page.getRepository().getDefaultBranch();
if (defaultBranch != null) {
- return new DirectoryChooser(id, Model.of(defaultBranch)) {
+ return new DirectoryChooser(id, Model.of(new RepoAndBranch(page.getRepository(), defaultBranch))) {
@Override
protected MarkupContainer newLinkComponent(String id, IModel<TreeNode> node) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectorySingleChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectorySingleChoiceEditor.java
index 9dff0d29fc..175a732731 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectorySingleChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/directory/DirectorySingleChoiceEditor.java
@@ -18,7 +18,7 @@ import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.web.component.directorychooser.DirectoryChooser;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@@ -43,10 +43,10 @@ public class DirectorySingleChoiceEditor extends PropertyEditor<String> {
@Override
protected Component newContent(String id) {
RepositoryPage page = (RepositoryPage) getPage();
- Branch defaultBranch = page.getRepository().getDefaultBranch();
+ String defaultBranch = page.getRepository().getDefaultBranch();
if (defaultBranch != null) {
- return new DirectoryChooser(id, Model.of(defaultBranch)) {
+ return new DirectoryChooser(id, Model.of(new RepoAndBranch(page.getRepository(), defaultBranch))) {
@Override
protected MarkupContainer newLinkComponent(String id, IModel<TreeNode> node) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/notifications/AccountNotificationsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/notifications/AccountNotificationsPage.java
index 162e0bd966..afb7a4cf00 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/notifications/AccountNotificationsPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/notifications/AccountNotificationsPage.java
@@ -23,7 +23,6 @@ import com.pmease.commons.wicket.component.datatable.DefaultDataTable;
import com.pmease.commons.wicket.component.datatable.EntityDataProvider;
import com.pmease.commons.wicket.component.datatable.SelectionColumn;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestNotification;
import com.pmease.gitplex.web.Constants;
@@ -91,7 +90,7 @@ public class AccountNotificationsPage extends AccountLayoutPage {
Item<ICellPopulator<PullRequestNotification>> cellItem,
String componentId, IModel<PullRequestNotification> rowModel) {
PullRequest request = rowModel.getObject().getRequest();
- cellItem.add(new BranchLink(componentId, new EntityModel<Branch>(request.getTarget())) {
+ cellItem.add(new BranchLink(componentId, Model.of(request.getTarget())) {
@Override
protected void onComponentTag(ComponentTag tag) {
@@ -111,7 +110,7 @@ public class AccountNotificationsPage extends AccountLayoutPage {
String componentId, IModel<PullRequestNotification> rowModel) {
PullRequest request = rowModel.getObject().getRequest();
if (request.getSource() != null) {
- cellItem.add(new BranchLink(componentId, new EntityModel<Branch>(request.getSource())) {
+ cellItem.add(new BranchLink(componentId, Model.of(request.getSource())) {
@Override
protected void onComponentTag(ComponentTag tag) {
@@ -121,7 +120,7 @@ public class AccountNotificationsPage extends AccountLayoutPage {
});
} else {
- cellItem.add(new Label(componentId, request.getSourceFQN()));
+ cellItem.add(new Label(componentId, request.getSource().getFQN()));
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/BranchComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/BranchComparePage.java
index f7d323a34e..2d82da79ea 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/BranchComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/BranchComparePage.java
@@ -18,7 +18,6 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.pmease.commons.git.Change;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
-import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.util.FileUtils;
import com.pmease.commons.wicket.component.backtotop.BackToTop;
import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;
@@ -27,8 +26,8 @@ import com.pmease.commons.wicket.component.tabbable.Tabbable;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.branch.AffinalBranchSingleChoice;
import com.pmease.gitplex.web.component.branch.BranchLink;
@@ -42,9 +41,9 @@ import com.pmease.gitplex.web.page.repository.pullrequest.RequestOverviewPage;
@SuppressWarnings("serial")
public class BranchComparePage extends RepositoryPage {
- private final IModel<Branch> targetModel;
+ private final IModel<RepoAndBranch> targetModel;
- private final IModel<Branch> sourceModel;
+ private final IModel<RepoAndBranch> sourceModel;
private IModel<List<Commit>> commitsModel;
@@ -52,11 +51,11 @@ public class BranchComparePage extends RepositoryPage {
private IModel<String> mergeBaseModel;
- private Long targetId;
+ private String targetId;
- private Long sourceId;
+ private String sourceId;
- public static PageParameters paramsOf(Repository repository, Branch source, Branch target) {
+ public static PageParameters paramsOf(Repository repository, RepoAndBranch source, RepoAndBranch target) {
PageParameters params = paramsOf(repository);
params.set("source", source.getId());
params.set("target", target.getId());
@@ -69,21 +68,20 @@ public class BranchComparePage extends RepositoryPage {
if (!getRepository().git().hasCommits())
throw new RestartResponseException(NoCommitsPage.class, paramsOf(getRepository()));
- targetModel = new IModel<Branch>() {
+ targetModel = new IModel<RepoAndBranch>() {
@Override
- public Branch getObject() {
- Dao dao = GitPlex.getInstance(Dao.class);
+ public RepoAndBranch getObject() {
if (targetId != null)
- return dao.load(Branch.class, targetId);
+ return new RepoAndBranch(targetId);
else if (params.get("target").toString() != null)
- return dao.load(Branch.class, params.get("target").toLongObject());
+ return new RepoAndBranch(params.get("target").toString());
else
- return getRepository().getDefaultBranch();
+ return new RepoAndBranch(getRepository(), getRepository().getDefaultBranch());
}
@Override
- public void setObject(Branch object) {
+ public void setObject(RepoAndBranch object) {
targetId = object.getId();
}
@@ -93,21 +91,20 @@ public class BranchComparePage extends RepositoryPage {
};
- sourceModel = new IModel<Branch>() {
+ sourceModel = new IModel<RepoAndBranch>() {
@Override
- public Branch getObject() {
- Dao dao = GitPlex.getInstance(Dao.class);
+ public RepoAndBranch getObject() {
if (sourceId != null)
- return dao.load(Branch.class, sourceId);
+ return new RepoAndBranch(sourceId);
else if (params.get("source").toString() != null)
- return dao.load(Branch.class, params.get("source").toLongObject());
+ return new RepoAndBranch(params.get("source").toString());
else
- return getRepository().getDefaultBranch();
+ return new RepoAndBranch(getRepository(), getRepository().getDefaultBranch());
}
@Override
- public void setObject(Branch object) {
+ public void setObject(RepoAndBranch object) {
sourceId = object.getId();
}
@@ -131,21 +128,21 @@ public class BranchComparePage extends RepositoryPage {
@Override
protected String load() {
- Branch target = targetModel.getObject();
- Branch source = sourceModel.getObject();
+ RepoAndBranch target = targetModel.getObject();
+ RepoAndBranch source = sourceModel.getObject();
if (!target.getRepository().equals(source.getRepository())) {
Git sandbox = new Git(FileUtils.createTempDir());
try {
- sandbox.clone(target.getRepository().git(), false, true, true, target.getName());
+ sandbox.clone(target.getRepository().git(), false, true, true, target.getBranch());
sandbox.reset(null, null);
- sandbox.fetch(source.getRepository().git(), source.getName());
- return sandbox.calcMergeBase(target.getHeadCommitHash(), source.getHeadCommitHash());
+ sandbox.fetch(source.getRepository().git(), source.getBranch());
+ return sandbox.calcMergeBase(target.getHead(), source.getHead());
} finally {
FileUtils.deleteDir(sandbox.repoDir());
}
} else {
return target.getRepository().git().calcMergeBase(
- target.getHeadCommitHash(), source.getHeadCommitHash());
+ target.getHead(), source.getHead());
}
}
@@ -155,8 +152,8 @@ public class BranchComparePage extends RepositoryPage {
@Override
protected List<Commit> load() {
- Branch source = sourceModel.getObject();
- return source.getRepository().git().log(mergeBaseModel.getObject(), source.getHeadCommitHash(), null, 0, 0);
+ RepoAndBranch source = sourceModel.getObject();
+ return source.getRepository().git().log(mergeBaseModel.getObject(), source.getHead(), null, 0, 0);
}
};
@@ -208,8 +205,8 @@ public class BranchComparePage extends RepositoryPage {
@Override
public void onClick() {
- Branch target = targetModel.getObject();
- Branch source = sourceModel.getObject();
+ RepoAndBranch target = targetModel.getObject();
+ RepoAndBranch source = sourceModel.getObject();
setResponsePage(NewRequestPage.class, NewRequestPage.paramsOf(target.getRepository(), source, target));
}
@@ -284,7 +281,7 @@ public class BranchComparePage extends RepositoryPage {
super.onConfigure();
setVisible(!targetModel.getObject().equals(sourceModel.getObject())
- && mergeBaseModel.getObject().equals(sourceModel.getObject().getHeadCommitHash()));
+ && mergeBaseModel.getObject().equals(sourceModel.getObject().getHead()));
}
@Override
@@ -340,7 +337,7 @@ public class BranchComparePage extends RepositoryPage {
private Component newChangedFilesPanel() {
return new CompareResultPanel("tabPanel", repoModel, mergeBaseModel.getObject(),
- sourceModel.getObject().getHeadCommitHash(), null) {
+ sourceModel.getObject().getHead(), null) {
@Override
protected void onSelection(AjaxRequestTarget target, Change change) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/RepoBranchesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/RepoBranchesPage.java
index ff671b5f46..28242f7178 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/RepoBranchesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/branches/RepoBranchesPage.java
@@ -48,12 +48,11 @@ import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.gatekeeper.GateKeeper;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
-import com.pmease.gitplex.core.manager.BranchManager;
import com.pmease.gitplex.core.manager.BranchWatchManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.BranchWatch;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.web.Constants;
@@ -73,9 +72,9 @@ import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig
@SuppressWarnings("serial")
public class RepoBranchesPage extends RepositoryPage {
- private Long baseBranchId;
+ private String baseBranch;
- private PageableListView<Branch> branchesView;
+ private PageableListView<String> branchesView;
private PagingNavigator pagingNavigator;
@@ -101,16 +100,16 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
protected Map<String, AheadBehind> load() {
List<String> compareHashes = new ArrayList<>();
- List<Branch> branchesInView = branchesView.getModelObject();
+ List<String> branchesInView = branchesView.getModelObject();
for (long i=branchesView.getFirstItemOffset(); i<branchesInView.size(); i++) {
if (i-branchesView.getFirstItemOffset() >= branchesView.getItemsPerPage())
break;
- Branch branch = branchesInView.get((int)i);
+ String branch = branchesInView.get((int)i);
if (!branch.equals(getBaseBranch()))
- compareHashes.add(lastCommitsModel.getObject().get(branch.getName()).getHash());
+ compareHashes.add(lastCommitsModel.getObject().get(branch).getHash());
}
- String baseHash = lastCommitsModel.getObject().get(getBaseBranch().getName()).getHash();
+ String baseHash = lastCommitsModel.getObject().get(getBaseBranch()).getHash();
Map<String, AheadBehind> aheadBehinds = getRepository().git().getAheadBehinds(
baseHash,
compareHashes.toArray(new String[compareHashes.size()]));
@@ -154,8 +153,10 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
protected Map<String, PullRequest> load() {
Map<String, PullRequest> requests = new HashMap<>();
- for (PullRequest request: GitPlex.getInstance(PullRequestManager.class).findOpenTo(getBaseBranch(), getRepository()))
- requests.put(request.getSource().getName(), request);
+ PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
+ RepoAndBranch repoAndBranch = new RepoAndBranch(getRepository(), getBaseBranch());
+ for (PullRequest request: pullRequestManager.queryOpenTo(repoAndBranch, getRepository()))
+ requests.put(request.getSource().getBranch(), request);
return requests;
}
@@ -167,8 +168,10 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
protected Map<String, PullRequest> load() {
Map<String, PullRequest> requests = new HashMap<>();
- for (PullRequest request: GitPlex.getInstance(PullRequestManager.class).findOpenFrom(getBaseBranch(), getRepository()))
- requests.put(request.getTarget().getName(), request);
+ PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
+ RepoAndBranch repoAndBranch = new RepoAndBranch(getRepository(), getBaseBranch());
+ for (PullRequest request: pullRequestManager.queryOpenFrom(repoAndBranch, getRepository()))
+ requests.put(request.getTarget().getBranch(), request);
return requests;
}
@@ -182,7 +185,7 @@ public class RepoBranchesPage extends RepositoryPage {
Map<String, BranchWatch> requestWatches = new HashMap<>();
for (BranchWatch watch: GitPlex.getInstance(BranchWatchManager.class).findBy(
Preconditions.checkNotNull(getCurrentUser()), getRepository()))
- requestWatches.put(watch.getBranch().getName(), watch);
+ requestWatches.put(watch.getBranch(), watch);
return requestWatches;
}
@@ -204,20 +207,20 @@ public class RepoBranchesPage extends RepositoryPage {
protected void onInitialize() {
super.onInitialize();
- add(new BranchSingleChoice("baseBranch", new IModel<Branch>() {
+ add(new BranchSingleChoice("baseBranch", new IModel<RepoAndBranch>() {
@Override
public void detach() {
}
@Override
- public Branch getObject() {
- return getBaseBranch();
+ public RepoAndBranch getObject() {
+ return new RepoAndBranch(getRepository(), getBaseBranch());
}
@Override
- public void setObject(Branch object) {
- baseBranchId = object.getId();
+ public void setObject(RepoAndBranch object) {
+ baseBranch = object.getBranch();
}
}, new BranchChoiceProvider(repoModel)).add(new AjaxFormComponentUpdatingBehavior("change") {
@@ -236,33 +239,33 @@ public class RepoBranchesPage extends RepositoryPage {
branchesContainer.setOutputMarkupId(true);
add(branchesContainer);
- branchesContainer.add(branchesView = new PageableListView<Branch>("branches", new AbstractReadOnlyModel<List<Branch>>() {
+ branchesContainer.add(branchesView = new PageableListView<String>("branches", new AbstractReadOnlyModel<List<String>>() {
@Override
- public List<Branch> getObject() {
- List<Branch> branches = new ArrayList<>(getRepository().getBranches());
+ public List<String> getObject() {
+ List<String> branches = new ArrayList<>(getRepository().getBranches());
searchFor = searchInput.getInput();
if (StringUtils.isNotBlank(searchFor)) {
searchFor = searchFor.trim().toLowerCase();
- for (Iterator<Branch> it = branches.iterator(); it.hasNext();) {
- Branch branch = it.next();
- if (!branch.getName().toLowerCase().contains(searchFor))
+ for (Iterator<String> it = branches.iterator(); it.hasNext();) {
+ String branch = it.next();
+ if (!branch.toLowerCase().contains(searchFor))
it.remove();
}
} else {
searchFor = null;
}
- Collections.sort(branches, new Comparator<Branch>() {
+ Collections.sort(branches, new Comparator<String>() {
@Override
- public int compare(Branch branch1, Branch branch2) {
- if (branch1.isDefault()) {
+ public int compare(String branch1, String branch2) {
+ if (getRepository().getDefaultBranch().equals(branch1)) {
return -1;
- } else if (branch2.isDefault()) {
+ } else if (getRepository().getDefaultBranch().equals(branch2)) {
return 1;
} else {
- BriefCommit commit1 = lastCommitsModel.getObject().get(branch1.getName());
- BriefCommit commit2 = lastCommitsModel.getObject().get(branch2.getName());
+ BriefCommit commit1 = lastCommitsModel.getObject().get(branch1);
+ BriefCommit commit2 = lastCommitsModel.getObject().get(branch2);
Preconditions.checkState(commit1 != null && commit2 != null);
return commit2.getAuthor().getWhen().compareTo(commit1.getAuthor().getWhen());
}
@@ -275,16 +278,16 @@ public class RepoBranchesPage extends RepositoryPage {
}, Constants.DEFAULT_PAGE_SIZE) {
@Override
- protected void populateItem(final ListItem<Branch> item) {
- final Branch branch = item.getModelObject();
+ protected void populateItem(final ListItem<String> item) {
+ final String branch = item.getModelObject();
AbstractLink link = new BookmarkablePageLink<Void>("branchLink",
RepoFilePage.class,
- RepoFilePage.paramsOf(getRepository(), branch.getName(), null));
- link.add(new Label("name", branch.getName()));
+ RepoFilePage.paramsOf(getRepository(), branch, null));
+ link.add(new Label("name", branch));
item.add(link);
- BriefCommit lastCommit = Preconditions.checkNotNull(lastCommitsModel.getObject().get(branch.getName()));
+ BriefCommit lastCommit = Preconditions.checkNotNull(lastCommitsModel.getObject().get(branch));
item.add(new AgeLabel("lastUpdateTime", Model.of(lastCommit.getAuthor().getWhen())));
item.add(new PersonLink("lastAuthor", Model.of(lastCommit.getAuthor()), AvatarMode.NAME));
@@ -294,12 +297,12 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(item.getModelObject().isDefault());
+ setVisible(getRepository().getDefaultBranch().equals(item.getModelObject()));
}
});
- String branchHash = lastCommitsModel.getObject().get(branch.getName()).getHash();
+ String branchHash = lastCommitsModel.getObject().get(branch).getHash();
final AheadBehind ab = Preconditions.checkNotNull(aheadBehindsModel.getObject().get(branchHash));
item.add(new Link<Void>("behindLink") {
@@ -320,7 +323,7 @@ public class RepoBranchesPage extends RepositoryPage {
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- if (behindOpenRequestsModel.getObject().get(item.getModelObject().getName()) != null) {
+ if (behindOpenRequestsModel.getObject().get(item.getModelObject()) != null) {
tag.put("title", "" + ab.getBehind() + " commits behind of base branch, and there is an "
+ "open pull request fetching those commits");
} else {
@@ -330,13 +333,16 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
public void onClick() {
- Branch branch = item.getModelObject();
- PullRequest request = behindOpenRequestsModel.getObject().get(branch.getName());
+ String branch = item.getModelObject();
+ PullRequest request = behindOpenRequestsModel.getObject().get(branch);
if (request != null) {
setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(request));
} else {
- setResponsePage(BranchComparePage.class,
- BranchComparePage.paramsOf(getRepository(), getBaseBranch(), branch));
+ PageParameters params = BranchComparePage.paramsOf(
+ getRepository(),
+ new RepoAndBranch(getRepository(), getBaseBranch()),
+ new RepoAndBranch(getRepository(), branch));
+ setResponsePage(BranchComparePage.class, params);
}
}
@@ -346,7 +352,7 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
protected void onInitialize() {
super.onInitialize();
- if (behindOpenRequestsModel.getObject().get(item.getModelObject().getName()) != null)
+ if (behindOpenRequestsModel.getObject().get(item.getModelObject()) != null)
add(AttributeAppender.append("class", " request"));
}
@@ -377,7 +383,7 @@ public class RepoBranchesPage extends RepositoryPage {
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- if (aheadOpenRequestsModel.getObject().get(item.getModelObject().getName()) != null) {
+ if (aheadOpenRequestsModel.getObject().get(item.getModelObject()) != null) {
tag.put("title", "" + ab.getAhead() + " commits ahead of base branch, and there is an "
+ "open pull request sending these commits to base branch");
} else {
@@ -387,13 +393,16 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
public void onClick() {
- Branch branch = item.getModelObject();
- PullRequest request = aheadOpenRequestsModel.getObject().get(branch.getName());
+ String branch = item.getModelObject();
+ PullRequest request = aheadOpenRequestsModel.getObject().get(branch);
if (request != null) {
setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(request));
} else {
- setResponsePage(BranchComparePage.class,
- BranchComparePage.paramsOf(getRepository(), branch, getBaseBranch()));
+ PageParameters params = BranchComparePage.paramsOf(
+ getRepository(),
+ new RepoAndBranch(getRepository(), branch),
+ new RepoAndBranch(getRepository(), getBaseBranch()));
+ setResponsePage(BranchComparePage.class, params);
}
}
@@ -403,7 +412,7 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
protected void onInitialize() {
super.onInitialize();
- if (aheadOpenRequestsModel.getObject().get(item.getModelObject().getName()) != null)
+ if (aheadOpenRequestsModel.getObject().get(item.getModelObject()) != null)
add(AttributeAppender.append("class", " request"));
}
@@ -423,11 +432,11 @@ public class RepoBranchesPage extends RepositoryPage {
@Override
public void onClick(AjaxRequestTarget target) {
- String branchName = item.getModelObject().getName();
- BranchWatch watch = branchWatchesModel.getObject().get(branchName);
+ String branch = item.getModelObject();
+ BranchWatch watch = branchWatchesModel.getObject().get(branch);
if (watch != null) {
GitPlex.getInstance(Dao.class).remove(watch);
- branchWatchesModel.getObject().remove(branchName);
+ branchWatchesModel.getObject().remove(branch);
}
target.add(actionsContainer);
}
@@ -436,7 +445,7 @@ public class RepoBranchesPage extends RepositoryPage {
protected void onConfigure() {
super.onConfigure();
setVisible(getCurrentUser() != null
- && branchWatchesModel.getObject().containsKey(item.getModelObject().getName()));
+ && branchWatchesModel.getObject().containsKey(item.getModelObject()));
}
});
@@ -455,35 +464,33 @@ public class RepoBranchesPage extends RepositoryPage {
protected void onConfigure() {
super.onConfigure();
setVisible(getCurrentUser() != null
- && !branchWatchesModel.getObject().containsKey(item.getModelObject().getName()));
+ && !branchWatchesModel.getObject().containsKey(item.getModelObject()));
}
});
Link<Void> deleteLink;
- final Long branchId = branch.getId();
actionsContainer.add(deleteLink = new Link<Void>("delete") {
@Override
public void onClick() {
- Dao dao = GitPlex.getInstance(Dao.class);
- GitPlex.getInstance(BranchManager.class).delete(dao.load(Branch.class, branchId));
+ getRepository().deleteBranch(branch);
}
@Override
protected void onConfigure() {
super.onConfigure();
- Branch branch = item.getModelObject();
- if (!branch.isDefault() && SecurityUtils.canModify(branch)) {
+ String branch = item.getModelObject();
+ if (!getRepository().getDefaultBranch().equals(branch) && SecurityUtils.canModify(getRepository(), branch)) {
User currentUser = getCurrentUser();
if (currentUser != null) {
GateKeeper gateKeeper = getRepository().getGateKeeper();
- CheckResult checkResult = gateKeeper.checkFile(currentUser, branch, null);
+ CheckResult checkResult = gateKeeper.checkFile(currentUser, getRepository(), branch, null);
if (checkResult instanceof Passed) {
setVisible(true);
- PullRequest aheadOpen = aheadOpenRequestsModel.getObject().get(branch.getName());
- PullRequest behindOpen = behindOpenRequestsModel.getObject().get(branch.getName());
+ PullRequest aheadOpen = aheadOpenRequestsModel.getObject().get(branch);
+ PullRequest behindOpen = behindOpenRequestsModel.getObject().get(branch);
setEnabled(aheadOpen == null && behindOpen == null);
} else {
setVisible(false);
@@ -498,8 +505,8 @@ public class RepoBranchesPage extends RepositoryPage {
});
deleteLink.add(new ConfirmBehavior("Do you really want to delete this branch?"));
- PullRequest aheadOpen = aheadOpenRequestsModel.getObject().get(branch.getName());
- PullRequest behindOpen = behindOpenRequestsModel.getObject().get(branch.getName());
+ PullRequest aheadOpen = aheadOpenRequestsModel.getObject().get(branch);
+ PullRequest behindOpen = behindOpenRequestsModel.getObject().get(branch);
if (aheadOpen != null || behindOpen != null) {
String hint = "This branch can not be deleted as there are <br>pull request opening against it.";
deleteLink.add(new TooltipBehavior(Model.of(hint), new TooltipConfig().withPlacement(Placement.left)));
@@ -521,9 +528,9 @@ public class RepoBranchesPage extends RepositoryPage {
pagingNavigator.setOutputMarkupPlaceholderTag(true);
}
- private Branch getBaseBranch() {
- if (baseBranchId != null)
- return GitPlex.getInstance(Dao.class).load(Branch.class, baseBranchId);
+ private String getBaseBranch() {
+ if (baseBranch != null)
+ return baseBranch;
else
return getRepository().getDefaultBranch();
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
index a1e3b56be9..ebb283b05b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
@@ -112,7 +112,7 @@ public class RepoFilePage extends RepositoryPage {
trait.repoId = getRepository().getId();
state.file.revision = GitUtils.normalizePath(params.get(PARAM_REVISION).toString());
if (state.file.revision == null)
- state.file.revision = getRepository().getDefaultBranch().getName();
+ state.file.revision = getRepository().getDefaultBranch();
trait.revision = state.file.revision;
state.file.path = GitUtils.normalizePath(params.get(PARAM_PATH).toString());
@@ -137,7 +137,7 @@ public class RepoFilePage extends RepositoryPage {
}
private ObjectId getCommitId() {
- return getRepository().getObjectId(state.file.revision, true);
+ return getRepository().getObjectId(state.file.revision);
}
@Override
@@ -321,7 +321,7 @@ public class RepoFilePage extends RepositoryPage {
}
private void onAddOrEditFile(AjaxRequestTarget target) {
- ObjectId commitId = getRepository().getObjectId(state.file.revision, true);
+ ObjectId commitId = getRepository().getObjectId(state.file.revision);
String refName = Git.REFS_HEADS + state.file.revision;
@@ -442,7 +442,7 @@ public class RepoFilePage extends RepositoryPage {
@Override
public void onDelete(AjaxRequestTarget target) {
- ObjectId commitId = getRepository().getObjectId(getState().file.revision, true);
+ ObjectId commitId = getRepository().getObjectId(getState().file.revision);
String refName = Git.REFS_HEADS + state.file.revision;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/NewRequestPage.java
index e5826ba408..21fd674dd6 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/NewRequestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/NewRequestPage.java
@@ -33,7 +33,6 @@ import com.pmease.commons.git.Change;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.loader.AppLoader;
import com.pmease.commons.util.FileUtils;
import com.pmease.commons.wicket.component.backtotop.BackToTop;
import com.pmease.commons.wicket.component.feedback.FeedbackPanel;
@@ -44,12 +43,12 @@ import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequest.CloseStatus;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
import com.pmease.gitplex.core.model.PullRequest.Status;
import com.pmease.gitplex.core.model.PullRequestUpdate;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.ReviewInvitation;
import com.pmease.gitplex.core.model.User;
@@ -75,7 +74,7 @@ public class NewRequestPage extends RepositoryPage {
private PullRequest pullRequest;
- public static PageParameters paramsOf(Repository repository, Branch source, Branch target) {
+ public static PageParameters paramsOf(Repository repository, RepoAndBranch source, RepoAndBranch target) {
PageParameters params = paramsOf(repository);
params.set("source", source.getId());
params.set("target", target.getId());
@@ -88,28 +87,26 @@ public class NewRequestPage extends RepositoryPage {
if (!getRepository().git().hasCommits())
throw new RestartResponseException(NoCommitsPage.class, paramsOf(getRepository()));
- Dao dao = AppLoader.getInstance(Dao.class);
-
- RepositoryPage page = (RepositoryPage) getPage();
-
- Branch target, source = null;
+ RepoAndBranch target, source = null;
if (params.get("target").toString() != null) {
- target = dao.load(Branch.class, params.get("target").toLongObject());
+ target = new RepoAndBranch(params.get("target").toString());
} else {
- if (page.getRepository().getForkedFrom() != null)
- target = page.getRepository().getForkedFrom().getDefaultBranch();
- else
- target = page.getRepository().getDefaultBranch();
+ if (getRepository().getForkedFrom() != null) {
+ target = new RepoAndBranch(getRepository().getForkedFrom(),
+ getRepository().getForkedFrom().getDefaultBranch());
+ } else {
+ target = new RepoAndBranch(getRepository(), getRepository().getDefaultBranch());
+ }
}
if (params.get("source").toString() != null) {
- source = dao.load(Branch.class, params.get("source").toLongObject());
+ source = new RepoAndBranch(params.get("source").toString());
} else {
- if (page.getRepository().getForkedFrom() != null) {
- source = page.getRepository().getDefaultBranch();
+ if (getRepository().getForkedFrom() != null) {
+ source = new RepoAndBranch(getRepository(), getRepository().getDefaultBranch());
} else {
- for (Branch each: page.getRepository().getBranches()) {
- if (!each.equals(target)) {
- source = each;
+ for (String each: getRepository().getBranches()) {
+ if (!each.equals(target.getBranch())) {
+ source = new RepoAndBranch(getRepository(), each);
break;
}
}
@@ -133,7 +130,7 @@ public class NewRequestPage extends RepositoryPage {
PullRequestUpdate update = new PullRequestUpdate();
pullRequest.addUpdate(update);
update.setRequest(pullRequest);
- update.setHeadCommitHash(source.getHeadCommitHash());
+ update.setHeadCommitHash(source.getHead());
pullRequest.setLastEventDate(new Date());
PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
@@ -149,20 +146,20 @@ public class NewRequestPage extends RepositoryPage {
if (target.getRepository().equals(source.getRepository())) {
pullRequest.setBaseCommitHash(pullRequest.git().calcMergeBase(
- target.getHeadCommitHash(), source.getHeadCommitHash()));
- if (target.getRepository().git().isAncestor(source.getHeadCommitHash(), target.getHeadCommitHash()))
+ target.getHead(), source.getHead()));
+ if (target.getRepository().git().isAncestor(source.getHead(), target.getHead()))
pullRequest.setCloseStatus(CloseStatus.INTEGRATED);
} else {
Git sandbox = new Git(FileUtils.createTempDir());
pullRequest.setSandbox(sandbox);
- sandbox.clone(target.getRepository().git(), false, true, true, pullRequest.getTarget().getName());
+ sandbox.clone(target.getRepository().git(), false, true, true, pullRequest.getTarget().getBranch());
sandbox.reset(null, null);
- sandbox.fetch(source.getRepository().git(), source.getName());
+ sandbox.fetch(source.getRepository().git(), source.getBranch());
- pullRequest.setBaseCommitHash(pullRequest.git().calcMergeBase(target.getHeadCommitHash(), source.getHeadCommitHash()));
+ pullRequest.setBaseCommitHash(pullRequest.git().calcMergeBase(target.getHead(), source.getHead()));
- if (sandbox.isAncestor(source.getHeadCommitHash(), target.getHeadCommitHash()))
+ if (sandbox.isAncestor(source.getHead(), target.getHead()))
pullRequest.setCloseStatus(CloseStatus.INTEGRATED);
}
}
@@ -398,10 +395,10 @@ public class NewRequestPage extends RepositoryPage {
super.onSubmit();
Dao dao = GitPlex.getInstance(Dao.class);
- Branch target = dao.load(Branch.class, pullRequest.getTarget().getId());
- Branch source = dao.load(Branch.class, pullRequest.getSource().getId());
- if (!target.getHeadCommitHash().equals(pullRequest.getTarget().getHeadCommitHash())
- || !source.getHeadCommitHash().equals(pullRequest.getSource().getHeadCommitHash())) {
+ RepoAndBranch target = pullRequest.getTarget();
+ RepoAndBranch source = pullRequest.getSource();
+ if (!target.getHead().equals(pullRequest.getTarget().getHead())
+ || !source.getHead().equals(pullRequest.getSource().getHead())) {
getSession().warn("Either target branch or source branch has new commits just now, please re-check.");
setResponsePage(NewRequestPage.class, paramsOf(getRepository(), source, target));
} else {
@@ -436,7 +433,7 @@ public class NewRequestPage extends RepositoryPage {
if (commits.size() == 1)
pullRequest.setTitle(commits.get(0).getSubject());
else
- pullRequest.setTitle(pullRequest.getSource().getName());
+ pullRequest.setTitle(pullRequest.getSource().getBranch());
}
return pullRequest.getTitle();
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
index d39d340d66..eba7eb9fd5 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
@@ -107,7 +107,7 @@ public class RequestComparePage extends RequestDetailPage {
choices.put(commit.getHash(), description);
}
- String targetHead = request.getTarget().getHeadCommitHash();
+ String targetHead = request.getTarget().getHead();
if (!choices.containsKey(targetHead)) {
description = new CommitDescription(TARGET_BRANCH_HEAD,
getRepository().getCommit(targetHead).getSubject());
@@ -296,7 +296,7 @@ public class RequestComparePage extends RequestDetailPage {
@Override
protected void onSelect() {
PageParameters params = paramsOf(getPullRequest(),
- getPullRequest().getTarget().getHeadCommitHash(), preview.getIntegrated(), file);
+ getPullRequest().getTarget().getHead(), preview.getIntegrated(), file);
setResponsePage(RequestComparePage.class, params);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
index 97359d1726..b889bbef3c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
@@ -68,8 +68,7 @@ import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;
import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.listeners.PullRequestListener;
-import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.model.Branch;
+import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
@@ -79,6 +78,7 @@ import com.pmease.gitplex.core.model.PullRequestCommentReply;
import com.pmease.gitplex.core.model.PullRequestOperation;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.PullRequestVerification;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.ReviewInvitation;
import com.pmease.gitplex.core.model.User;
@@ -394,7 +394,7 @@ public abstract class RequestDetailPage extends RepositoryPage {
IntegrationPreview preview = request.getIntegrationPreview();
PageParameters params = RequestComparePage.paramsOf(
- request, request.getTarget().getHeadCommitHash(),
+ request, request.getTarget().getHead(),
preview!=null?preview.getIntegrated():null, null);
Link<Void> link = new BookmarkablePageLink<Void>("preview", RequestComparePage.class, params) {
@@ -598,9 +598,9 @@ public abstract class RequestDetailPage extends RepositoryPage {
final FormComponent<String> noteInput;
final FormComponent<Boolean> deleteSourceCheck = new CheckBox("deleteSource", Model.of(false));
- Branch source = request.getSource();
+ RepoAndBranch source = request.getSource();
Preconditions.checkNotNull(source);
- if (operation != INTEGRATE || source.isDefault() || !SecurityUtils.canModify(source))
+ if (operation != INTEGRATE || source.isDefault() || !SecurityUtils.canModify(source.getRepository(), source.getBranch()))
deleteSourceCheck.setVisible(false);
form.add(deleteSourceCheck);
@@ -646,17 +646,11 @@ public abstract class RequestDetailPage extends RepositoryPage {
try {
operation.operate(request, noteInput.getModelObject());
if (deleteSourceCheck.getModelObject()) {
- boolean hasOpen = false;
- for (PullRequest each: request.getSource().getIncomingRequests()) {
- if (each.isOpen()) {
- hasOpen = true;
- break;
- }
- }
- if (hasOpen)
+ PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
+ if (!pullRequestManager.queryOpenTo(request.getSource(), null).isEmpty())
Session.get().warn("Source branch is not deleted as there are pull requests opening against it.");
- else
- GitPlex.getInstance(BranchManager.class).delete(request.getSource());
+ else
+ request.getSource().delete();
}
setResponsePage(getPage().getClass(), paramsOf(getPullRequest()));
} catch (Exception e) {
@@ -776,11 +770,18 @@ public abstract class RequestDetailPage extends RepositoryPage {
};
integratedNoteContainer.add(squashedContainer);
- squashedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
- squashedContainer.add(new BranchLink("source", new AbstractReadOnlyModel<Branch>() {
+ squashedContainer.add(new BranchLink("target", new LoadableDetachableModel<RepoAndBranch>() {
@Override
- public Branch getObject() {
+ protected RepoAndBranch load() {
+ return getPullRequest().getTarget();
+ }
+
+ }));
+ squashedContainer.add(new BranchLink("source", new LoadableDetachableModel<RepoAndBranch>() {
+
+ @Override
+ protected RepoAndBranch load() {
return getPullRequest().getSource();
}
@@ -809,11 +810,18 @@ public abstract class RequestDetailPage extends RepositoryPage {
};
integratedNoteContainer.add(sourceRebasedContainer);
- sourceRebasedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
- sourceRebasedContainer.add(new BranchLink("source", new AbstractReadOnlyModel<Branch>() {
+ sourceRebasedContainer.add(new BranchLink("target", new LoadableDetachableModel<RepoAndBranch>() {
+
+ @Override
+ protected RepoAndBranch load() {
+ return getPullRequest().getTarget();
+ }
+
+ }));
+ sourceRebasedContainer.add(new BranchLink("source", new LoadableDetachableModel<RepoAndBranch>() {
@Override
- public Branch getObject() {
+ protected RepoAndBranch load() {
return getPullRequest().getSource();
}
@@ -842,7 +850,14 @@ public abstract class RequestDetailPage extends RepositoryPage {
};
integratedNoteContainer.add(targetRebasedContainer);
- targetRebasedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
+ targetRebasedContainer.add(new BranchLink("target", new LoadableDetachableModel<RepoAndBranch>() {
+
+ @Override
+ protected RepoAndBranch load() {
+ return getPullRequest().getTarget();
+ }
+
+ }));
return integratedNoteContainer;
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestListPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestListPanel.java
index 0209bb1d97..15ff93c2ce 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestListPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestListPanel.java
@@ -34,14 +34,13 @@ import com.pmease.commons.wicket.behavior.menu.MenuBehavior;
import com.pmease.commons.wicket.behavior.menu.MenuItem;
import com.pmease.commons.wicket.behavior.menu.MenuPanel;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.web.Constants;
import com.pmease.gitplex.web.component.branch.BranchLink;
import com.pmease.gitplex.web.component.pullrequest.RequestLink;
import com.pmease.gitplex.web.component.userchoice.UserSingleChoice;
-import com.pmease.gitplex.web.model.EntityModel;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
@SuppressWarnings("serial")
@@ -268,8 +267,15 @@ public class RequestListPanel extends Panel {
@Override
public void populateItem(Item<ICellPopulator<PullRequest>> cellItem,
- String componentId, IModel<PullRequest> rowModel) {
- cellItem.add(new BranchLink(componentId, new EntityModel<Branch>(rowModel.getObject().getTarget())));
+ String componentId, final IModel<PullRequest> rowModel) {
+ cellItem.add(new BranchLink(componentId, new LoadableDetachableModel<RepoAndBranch>() {
+
+ @Override
+ protected RepoAndBranch load() {
+ return rowModel.getObject().getTarget();
+ }
+
+ }));
}
});
@@ -277,12 +283,20 @@ public class RequestListPanel extends Panel {
@Override
public void populateItem(Item<ICellPopulator<PullRequest>> cellItem,
- String componentId, IModel<PullRequest> rowModel) {
+ String componentId, final IModel<PullRequest> rowModel) {
PullRequest request = rowModel.getObject();
- if (request.getSource() != null)
- cellItem.add(new BranchLink(componentId, new EntityModel<Branch>(request.getSource())));
- else
- cellItem.add(new Label(componentId, request.getSourceFQN()));
+ if (request.getSourceRepo() != null) {
+ cellItem.add(new BranchLink(componentId, new LoadableDetachableModel<RepoAndBranch>(){
+
+ @Override
+ protected RepoAndBranch load() {
+ return rowModel.getObject().getSource();
+ }
+
+ }));
+ } else {
+ cellItem.add(new Label(componentId, "unknown repository"));
+ }
}
});
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestOverviewPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestOverviewPage.java
index 7227210ac9..52b7abd3e8 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestOverviewPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestOverviewPage.java
@@ -26,7 +26,6 @@ import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.repeater.RepeatingView;
-import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
@@ -41,12 +40,9 @@ import com.pmease.commons.wicket.behavior.TooltipBehavior;
import com.pmease.commons.wicket.component.feedback.FeedbackPanel;
import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.manager.BranchManager;
import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.manager.RepositoryManager;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
import com.pmease.gitplex.core.model.PullRequestActivity;
@@ -54,7 +50,7 @@ import com.pmease.gitplex.core.model.PullRequestComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.PullRequestVisit;
import com.pmease.gitplex.core.model.PullRequestWatch;
-import com.pmease.gitplex.core.model.Repository;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.ReviewInvitation;
import com.pmease.gitplex.core.model.User;
@@ -414,20 +410,29 @@ public class RequestOverviewPage extends RequestDetailPage {
WebMarkupContainer basicInfoContainer = new WebMarkupContainer("basicInfo");
basicInfoContainer.add(new AvatarByUser("submitter", new UserModel(request.getSubmitter()), true));
- basicInfoContainer.add(new BranchLink("target", new EntityModel<Branch>(request.getTarget())));
- basicInfoContainer.add(new BranchLink("sourceLink", new AbstractReadOnlyModel<Branch>() {
+ basicInfoContainer.add(new BranchLink("target", new LoadableDetachableModel<RepoAndBranch>() {
@Override
- public Branch getObject() {
- return getPullRequest().getSource();
+ protected RepoAndBranch load() {
+ return getPullRequest().getTarget();
}
+ }));
+ basicInfoContainer.add(new BranchLink("sourceLink", new LoadableDetachableModel<RepoAndBranch>() {
+
+ @Override
+ protected RepoAndBranch load() {
+ return getPullRequest().getSource();
+ }
+
}) {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getSource() != null);
+
+ PullRequest request = getPullRequest();
+ setVisible(request.getSourceRepo() != null && request.getSource().getHead(false) != null);
}
});
@@ -436,12 +441,14 @@ public class RequestOverviewPage extends RequestDetailPage {
@Override
protected String load() {
PullRequest request = getPullRequest();
- String branchName = Branch.getNameByFQN(request.getSourceFQN());
- String repoFQN = Branch.getRepositoryFQNByFQN(request.getSourceFQN());
- if (repoFQN.equals(request.getTarget().getRepository().getFQN()))
- return branchName + " (removed)";
- else
- return request.getSourceFQN() + " (removed)";
+ if (request.getSourceRepo() != null) {
+ if (request.getSourceRepo().equals(request.getTargetRepo()))
+ return request.getSourceBranch() + " (removed)";
+ else
+ return request.getSource().getFQN() + " (removed)";
+ } else {
+ return "unknown repository";
+ }
}
}) {
@@ -449,7 +456,9 @@ public class RequestOverviewPage extends RequestDetailPage {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getSource() == null);
+
+ PullRequest request = getPullRequest();
+ setVisible(request.getSourceRepo() == null || request.getSource().getHead(false) == null);
}
});
@@ -462,28 +471,13 @@ public class RequestOverviewPage extends RequestDetailPage {
PullRequest request = requestModel.getObject();
- if (request.getSource() != null || request.getSourceFQN() == null
- || !SecurityUtils.canModify(request)) {
- setVisible(false);
- } else {
- String repositoryFQN = Branch.getRepositoryFQNByFQN(request.getSourceFQN());
- Repository repository = GitPlex.getInstance(RepositoryManager.class).findBy(repositoryFQN);
- if (repository == null) {
- setVisible(false);
- } else {
- String branchName = Branch.getNameByFQN(request.getSourceFQN());
- Branch branch = GitPlex.getInstance(BranchManager.class).findBy(repository, branchName);
- if (branch == null)
- setVisible(SecurityUtils.canCreate(repository, branchName));
- else
- setVisible(true);
- }
- }
+ setVisible(request.getSourceRepo() != null && request.getSource().getHead(false) == null
+ && SecurityUtils.canModify(request) && SecurityUtils.canCreate(request.getSource()));
}
@Override
public void onClick() {
- GitPlex.getInstance(PullRequestManager.class).restoreSource(requestModel.getObject());
+ GitPlex.getInstance(PullRequestManager.class).restoreSourceBranch(requestModel.getObject());
}
});
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestSummaryPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestSummaryPanel.java
index 6736f47614..bb6e73ccb6 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestSummaryPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestSummaryPanel.java
@@ -8,11 +8,12 @@ import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
-import com.pmease.gitplex.core.model.Branch;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.web.component.avatar.AvatarMode;
import com.pmease.gitplex.web.component.branch.BranchLink;
import com.pmease.gitplex.web.component.label.AgeLabel;
@@ -68,19 +69,19 @@ public class RequestSummaryPanel extends Panel {
add(new UserLink("user", Model.of(getPullRequest().getSubmitter()), AvatarMode.NAME_AND_AVATAR));
- add(new BranchLink("target", new AbstractReadOnlyModel<Branch>() {
+ add(new BranchLink("target", new LoadableDetachableModel<RepoAndBranch>() {
@Override
- public Branch getObject() {
+ protected RepoAndBranch load() {
return getPullRequest().getTarget();
}
}));
- add(new BranchLink("source", new AbstractReadOnlyModel<Branch>() {
+ add(new BranchLink("source", new LoadableDetachableModel<RepoAndBranch>() {
@Override
- public Branch getObject() {
+ protected RepoAndBranch load() {
return getPullRequest().getSource();
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java
index 5803d07409..8f67b64cb8 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java
@@ -43,63 +43,63 @@ class ResolveConflictInstructionPanel extends Panel {
if (strategy == MERGE_WITH_SQUASH || strategy == REBASE_SOURCE_ONTO_TARGET) {
fragment = new Fragment("content", "rebaseInSourceFrag", this);
fragment.add(new Label("srcRepoName", request.getSource().getRepository()));
- fragment.add(new Label("srcBranchNameForCheckout", request.getSource().getName()));
- fragment.add(new Label("srcBranchNameForPush", request.getSource().getName()));
+ fragment.add(new Label("srcBranchNameForCheckout", request.getSourceBranch()));
+ fragment.add(new Label("srcBranchNameForPush", request.getSourceBranch()));
WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
- sameRepoContainer.add(new Label("destBranchName", request.getTarget().getName()));
+ sameRepoContainer.add(new Label("destBranchName", request.getTargetBranch()));
sameRepoContainer.setVisible(sameRepo);
fragment.add(sameRepoContainer);
WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
differentRepoContainer.add(new Label("destRepoUrl", request.getTarget().getRepository().getUrl()));
- differentRepoContainer.add(new Label("destBranchName", request.getTarget().getName()));
+ differentRepoContainer.add(new Label("destBranchName", request.getTargetBranch()));
differentRepoContainer.setVisible(!sameRepo);
fragment.add(differentRepoContainer);
} else if (strategy == REBASE_TARGET_ONTO_SOURCE) {
fragment = new Fragment("content", "rebaseInTargetFrag", this);
fragment.add(new Label("destRepoName", request.getTarget().getRepository()));
- fragment.add(new Label("destBranchNameForCheckout", request.getTarget().getName()));
- fragment.add(new Label("destBranchNameForPush", request.getTarget().getName()));
+ fragment.add(new Label("destBranchNameForCheckout", request.getTargetBranch()));
+ fragment.add(new Label("destBranchNameForPush", request.getTargetBranch()));
WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
- sameRepoContainer.add(new Label("srcBranchName", request.getSource().getName()));
+ sameRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
sameRepoContainer.setVisible(sameRepo);
fragment.add(sameRepoContainer);
WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
differentRepoContainer.add(new Label("srcRepoUrl", request.getSource().getRepository().getUrl()));
- differentRepoContainer.add(new Label("srcBranchName", request.getSource().getName()));
+ differentRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
differentRepoContainer.setVisible(!sameRepo);
fragment.add(differentRepoContainer);
} else if (user != null
&& SecurityUtils.getSubject().isPermitted(ObjectPermission.ofRepoPush(targetRepo))
- && targetRepo.getGateKeeper().checkCommit(user, request.getTarget(), sourceHead).allowIntegration()) {
+ && targetRepo.getGateKeeper().checkCommit(user, request.getTargetRepo(), request.getTargetBranch(), sourceHead).allowIntegration()) {
fragment = new Fragment("content", "mergeInTargetFrag", this);
fragment.add(new Label("destRepoName", request.getTarget().getRepository()));
- fragment.add(new Label("destBranchNameForCheckout", request.getTarget().getName()));
- fragment.add(new Label("destBranchNameForPush", request.getTarget().getName()));
+ fragment.add(new Label("destBranchNameForCheckout", request.getTargetBranch()));
+ fragment.add(new Label("destBranchNameForPush", request.getTargetBranch()));
WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
sameRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
- sameRepoContainer.add(new Label("srcBranchName", request.getSource().getName()));
+ sameRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
sameRepoContainer.setVisible(sameRepo);
fragment.add(sameRepoContainer);
WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
differentRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
differentRepoContainer.add(new Label("srcRepoUrl", request.getSource().getRepository().getUrl()));
- differentRepoContainer.add(new Label("srcBranchName", request.getSource().getName()));
+ differentRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
differentRepoContainer.setVisible(!sameRepo);
fragment.add(differentRepoContainer);
} else {
fragment = new Fragment("content", "mergeInSourceFrag", this);
fragment.add(new Label("srcRepoName", request.getSource().getRepository()));
- fragment.add(new Label("srcBranchNameForCheckout", request.getSource().getName()));
- fragment.add(new Label("srcBranchNameForPush", request.getSource().getName()));
+ fragment.add(new Label("srcBranchNameForCheckout", request.getSourceBranch()));
+ fragment.add(new Label("srcBranchNameForPush", request.getSourceBranch()));
WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
sameRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
- sameRepoContainer.add(new Label("destBranchName", request.getTarget().getName()));
+ sameRepoContainer.add(new Label("destBranchName", request.getTargetBranch()));
sameRepoContainer.setVisible(sameRepo);
fragment.add(sameRepoContainer);
WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
differentRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
differentRepoContainer.add(new Label("destRepoUrl", request.getTarget().getRepository().getUrl()));
- differentRepoContainer.add(new Label("destBranchName", request.getTarget().getName()));
+ differentRepoContainer.add(new Label("destBranchName", request.getTargetBranch()));
differentRepoContainer.setVisible(!sameRepo);
fragment.add(differentRepoContainer);
}