null
+ * @deprecated Use {@link Branch#Branch(String, String, boolean, Long, Person)} instead.
*/
+ @Deprecated
Branch(String name, String revision, boolean defaultBranch, Long lastCommitDate) {
+ this(name, revision, defaultBranch, lastCommitDate, null);
+ }
+
+ /**
+ * Constructs a new branch.
+ *
+ * @param name name of the branch
+ * @param revision latest revision of the branch
+ * @param defaultBranch Whether this branch is the default branch for the repository
+ * @param lastCommitDate The date of the commit this branch points to (if computed). May be null
+ * @param lastCommitter The user of the commit this branch points to (if computed). May be null
+ */
+ Branch(String name, String revision, boolean defaultBranch, Long lastCommitDate, Person lastCommitter) {
this.name = name;
this.revision = revision;
this.defaultBranch = defaultBranch;
this.lastCommitDate = lastCommitDate;
+ this.lastCommitter = lastCommitter;
}
/**
- * @deprecated Use {@link #normalBranch(String, String, Long)} instead to set the date of the last commit, too.
+ * @deprecated Use {@link #normalBranch(String, String, Long, Person)} instead to set the date of the last commit, too.
*/
@Deprecated
public static Branch normalBranch(String name, String revision) {
return normalBranch(name, revision, null);
}
+ /**
+ * @deprecated Use {@link #normalBranch(String, String, Long, Person)} instead to set the author of the last commit, too.
+ */
+ @Deprecated
public static Branch normalBranch(String name, String revision, Long lastCommitDate) {
- return new Branch(name, revision, false, lastCommitDate);
+ return normalBranch(name, revision, lastCommitDate, null);
+ }
+
+ public static Branch normalBranch(String name, String revision, Long lastCommitDate, Person lastCommitter) {
+ return new Branch(name, revision, false, lastCommitDate, lastCommitter);
}
/**
@@ -117,8 +142,16 @@ public final class Branch implements Serializable, Validateable {
return defaultBranch(name, revision, null);
}
+ /**
+ * @deprecated Use {@link #defaultBranch(String, String, Long, Person)} instead to set the author of the last commit, too.
+ */
+ @Deprecated
public static Branch defaultBranch(String name, String revision, Long lastCommitDate) {
- return new Branch(name, revision, true, lastCommitDate);
+ return defaultBranch(name, revision, lastCommitDate, null);
+ }
+
+ public static Branch defaultBranch(String name, String revision, Long lastCommitDate, Person lastCommitter) {
+ return new Branch(name, revision, true, lastCommitDate, lastCommitter);
}
public void setStale(boolean stale) {
@@ -145,7 +178,8 @@ public final class Branch implements Serializable, Validateable {
return Objects.equal(name, other.name)
&& Objects.equal(revision, other.revision)
&& Objects.equal(defaultBranch, other.defaultBranch)
- && Objects.equal(lastCommitDate, other.lastCommitDate);
+ && Objects.equal(lastCommitDate, other.lastCommitDate)
+ && Objects.equal(lastCommitter, other.lastCommitter);
}
@Override
@@ -156,11 +190,12 @@ public final class Branch implements Serializable, Validateable {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("name", name)
- .add("revision", revision)
- .add("defaultBranch", defaultBranch)
- .add("lastCommitDate", lastCommitDate)
- .toString();
+ .add("name", name)
+ .add("revision", revision)
+ .add("defaultBranch", defaultBranch)
+ .add("lastCommitDate", lastCommitDate)
+ .add("lastCommitter", lastCommitter)
+ .toString();
}
/**
@@ -197,6 +232,16 @@ public final class Branch implements Serializable, Validateable {
return Optional.ofNullable(lastCommitDate);
}
+
+ /**
+ * The author of the last commit this branch points to.
+ *
+ * @since 2.28.0
+ */
+ public Person getLastCommitter() {
+ return lastCommitter;
+ }
+
public boolean isStale() {
return stale;
}
diff --git a/scm-core/src/main/java/sonia/scm/repository/api/BranchDetailsCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/BranchDetailsCommandBuilder.java
new file mode 100644
index 0000000000..c7ef6aac1e
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/repository/api/BranchDetailsCommandBuilder.java
@@ -0,0 +1,98 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package sonia.scm.repository.api;
+
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import sonia.scm.cache.Cache;
+import sonia.scm.cache.CacheManager;
+import sonia.scm.repository.Repository;
+import sonia.scm.repository.RepositoryCacheKey;
+import sonia.scm.repository.RepositoryPermissions;
+import sonia.scm.repository.spi.BranchDetailsCommand;
+import sonia.scm.repository.spi.BranchDetailsCommandRequest;
+
+import java.io.Serializable;
+
+/**
+ * @since 2.28.0
+ */
+public final class BranchDetailsCommandBuilder {
+
+ static final String CACHE_NAME = "sonia.cache.cmd.branch-details";
+ private static final Logger LOG = LoggerFactory.getLogger(BranchDetailsCommandBuilder.class);
+
+ private final Repository repository;
+ private final BranchDetailsCommand command;
+ private final Cache