diff --git a/scm-core/src/main/java/sonia/scm/repository/Changeset.java b/scm-core/src/main/java/sonia/scm/repository/Changeset.java index dc12dc382f..fecfd74cc9 100644 --- a/scm-core/src/main/java/sonia/scm/repository/Changeset.java +++ b/scm-core/src/main/java/sonia/scm/repository/Changeset.java @@ -132,7 +132,9 @@ public class Changeset extends BasicPropertiesAware final Changeset other = (Changeset) obj; - return Objects.equal(id, other.id) && Objects.equal(date, other.date) + //J- + return Objects.equal(id, other.id) + && Objects.equal(date, other.date) && Objects.equal(author, other.author) && Objects.equal(description, other.description) && Objects.equal(parents, other.parents) @@ -140,6 +142,7 @@ public class Changeset extends BasicPropertiesAware && Objects.equal(branches, other.branches) && Objects.equal(modifications, other.modifications) && Objects.equal(properties, other.properties); + //J+ } /** @@ -206,7 +209,9 @@ public class Changeset extends BasicPropertiesAware } /** - * Returns the branches of the changeset. + * Returns the branches of the changeset. In the most cases a changeset is + * only related to one branch, but in the case of receive hooks it is possible + * that a changeset is related to more than a branch. * * * @return branches of the changeset diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java index ab588816ce..a59e3b5754 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java @@ -160,6 +160,23 @@ public class GitChangesetConverter implements Closeable return createChangeset(commit, branches); } + /** + * Method description + * + * + * @param commit + * @param branch + * + * @return + * + * @throws IOException + */ + public Changeset createChangeset(RevCommit commit, String branch) + throws IOException + { + return createChangeset(commit, Lists.newArrayList(branch)); + } + /** * Method description * diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java index 471f2450c9..a13a08997c 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java @@ -36,6 +36,7 @@ package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.lib.ObjectId; @@ -56,7 +57,7 @@ import sonia.scm.web.CollectingPackParserListener; import java.io.IOException; import java.util.List; - +import java.util.Map; /** * @@ -98,7 +99,7 @@ public class GitHookChangesetCollector */ public List collectChangesets() { - List changesets = Lists.newArrayList(); + Map changesets = Maps.newLinkedHashMap(); org.eclipse.jgit.lib.Repository repository = rpack.getRepository(); @@ -157,7 +158,7 @@ public class GitHookChangesetCollector GitUtil.release(walk); } - return changesets; + return Lists.newArrayList(changesets.values()); } /** @@ -172,7 +173,7 @@ public class GitHookChangesetCollector * @throws IOException * @throws IncorrectObjectTypeException */ - private void collectChangesets(List changesets, + private void collectChangesets(Map changesets, GitChangesetConverter converter, RevWalk walk, ReceiveCommand rc) throws IncorrectObjectTypeException, IOException { @@ -190,7 +191,7 @@ public class GitHookChangesetCollector ObjectId oldId = rc.getOldId(); - if ((oldId != null) &&!oldId.equals(ObjectId.zeroId())) + if ((oldId != null) && !oldId.equals(ObjectId.zeroId())) { logger.trace("mark {} as uninteresting for rev walk", oldId.getName()); @@ -199,27 +200,38 @@ public class GitHookChangesetCollector RevCommit commit = walk.next(); - List branches = Lists.newArrayList(branch); - while (commit != null) { + String id = commit.getId().name(); + Changeset changeset = changesets.get(id); - // only append new commits - if (listener.isNew(commit)) + if (changeset != null) { - - // parse commit body to avoid npe - walk.parseBody(commit); - - Changeset changeset = converter.createChangeset(commit, branches); - - logger.trace("retrieve commit {} for hook", changeset.getId()); - - changesets.add(changeset); + logger.trace( + "commit {} already received durring this push, add branch {} to the commit", + commit, branch); + changeset.getBranches().add(branch); } else { - logger.trace("commit {} was already received", commit.getId()); + + // only append new commits + if (listener.isNew(commit)) + { + + // parse commit body to avoid npe + walk.parseBody(commit); + + changeset = converter.createChangeset(commit, branch); + + logger.trace("retrieve commit {} for hook", changeset.getId()); + + changesets.put(id, changeset); + } + else + { + logger.trace("commit {} was already received", commit.getId()); + } } commit = walk.next();