From 7afa2b0193a28efacfc6ceb89d8bd97cf03e0bdc Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 20 Sep 2012 11:37:38 +0200 Subject: [PATCH] use always the branch informations from the receivecommand --- .../scm/repository/GitChangesetConverter.java | 55 +++++++++++++------ .../repository/GitHookChangesetCollector.java | 26 +++------ 2 files changed, 47 insertions(+), 34 deletions(-) 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 fb14003e64..2599238bf9 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 @@ -35,6 +35,7 @@ package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import org.eclipse.jgit.diff.DiffEntry; @@ -134,7 +135,6 @@ public class GitChangesetConverter implements Closeable * Method description * * - * * @param commit * * @return @@ -142,6 +142,42 @@ public class GitChangesetConverter implements Closeable * @throws IOException */ public Changeset createChangeset(RevCommit commit) throws IOException + { + List branches = Lists.newArrayList(); + Set refs = repository.getAllRefsByPeeledObjectId().get(commit.getId()); + + if (Util.isNotEmpty(refs)) + { + + for (Ref ref : refs) + { + String branch = GitUtil.getBranch(ref); + + if (branch != null) + { + branches.add(branch); + } + } + + } + + return createChangeset(commit, branches); + } + + /** + * Method description + * + * + * + * @param commit + * @param branches + * + * @return + * + * @throws IOException + */ + public Changeset createChangeset(RevCommit commit, List branches) + throws IOException { String id = commit.getId().abbreviate(idLength).name(); List parentList = null; @@ -183,22 +219,7 @@ public class GitChangesetConverter implements Closeable changeset.getTags().addAll(tagCollection); } - Set refs = repository.getAllRefsByPeeledObjectId().get(commit.getId()); - - if (Util.isNotEmpty(refs)) - { - - for (Ref ref : refs) - { - String branch = GitUtil.getBranch(ref); - - if (branch != null) - { - changeset.getBranches().add(branch); - } - } - - } + changeset.setBranches(branches); return changeset; } 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 0d93ca5b1c..f23e2fd917 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 @@ -99,13 +99,14 @@ public class GitHookChangesetCollector org.eclipse.jgit.lib.Repository repository = rpack.getRepository(); RevWalk walk = null; - + GitChangesetConverter converter = null; try { walk = rpack.getRevWalk(); - converter = new GitChangesetConverter(repository, walk, GitUtil.ID_LENGTH); + converter = new GitChangesetConverter(repository, walk, + GitUtil.ID_LENGTH); for (ReceiveCommand rc : receiveCommands) { @@ -159,28 +160,19 @@ public class GitHookChangesetCollector RevCommit commit = walk.next(); + List branches = Lists.newArrayList(branch); + while (commit != null) { + // parse commit body to avoid npe walk.parseBody(commit); - Changeset changeset = converter.createChangeset(commit); - List branches = changeset.getBranches(); + Changeset changeset = converter.createChangeset(commit, branches); - if (branches.isEmpty()) + if (logger.isTraceEnabled()) { - if (logger.isTraceEnabled()) - { - //J- - logger.trace( - "missing branch informations for {}, set default branch {}", - changeset.getId(), - branch - ); - //J+ - } - - branches.add(branch); + logger.trace("retrive commit {} for hook", changeset.getId()); } changesets.add(changeset);