use always the branch informations from the receivecommand

This commit is contained in:
Sebastian Sdorra
2012-09-20 11:37:38 +02:00
parent 7404791b8d
commit 7afa2b0193
2 changed files with 47 additions and 34 deletions

View File

@@ -35,6 +35,7 @@ package sonia.scm.repository;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.diff.DiffEntry;
@@ -134,7 +135,6 @@ public class GitChangesetConverter implements Closeable
* Method description * Method description
* *
* *
*
* @param commit * @param commit
* *
* @return * @return
@@ -142,6 +142,42 @@ public class GitChangesetConverter implements Closeable
* @throws IOException * @throws IOException
*/ */
public Changeset createChangeset(RevCommit commit) throws IOException public Changeset createChangeset(RevCommit commit) throws IOException
{
List<String> branches = Lists.newArrayList();
Set<Ref> 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<String> branches)
throws IOException
{ {
String id = commit.getId().abbreviate(idLength).name(); String id = commit.getId().abbreviate(idLength).name();
List<String> parentList = null; List<String> parentList = null;
@@ -183,22 +219,7 @@ public class GitChangesetConverter implements Closeable
changeset.getTags().addAll(tagCollection); changeset.getTags().addAll(tagCollection);
} }
Set<Ref> refs = repository.getAllRefsByPeeledObjectId().get(commit.getId()); changeset.setBranches(branches);
if (Util.isNotEmpty(refs))
{
for (Ref ref : refs)
{
String branch = GitUtil.getBranch(ref);
if (branch != null)
{
changeset.getBranches().add(branch);
}
}
}
return changeset; return changeset;
} }

View File

@@ -105,7 +105,8 @@ public class GitHookChangesetCollector
try try
{ {
walk = rpack.getRevWalk(); walk = rpack.getRevWalk();
converter = new GitChangesetConverter(repository, walk, GitUtil.ID_LENGTH); converter = new GitChangesetConverter(repository, walk,
GitUtil.ID_LENGTH);
for (ReceiveCommand rc : receiveCommands) for (ReceiveCommand rc : receiveCommands)
{ {
@@ -159,28 +160,19 @@ public class GitHookChangesetCollector
RevCommit commit = walk.next(); RevCommit commit = walk.next();
List<String> branches = Lists.newArrayList(branch);
while (commit != null) while (commit != null)
{ {
// parse commit body to avoid npe // parse commit body to avoid npe
walk.parseBody(commit); walk.parseBody(commit);
Changeset changeset = converter.createChangeset(commit);
List<String> branches = changeset.getBranches(); Changeset changeset = converter.createChangeset(commit, branches);
if (branches.isEmpty())
{
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
//J- logger.trace("retrive commit {} for hook", changeset.getId());
logger.trace(
"missing branch informations for {}, set default branch {}",
changeset.getId(),
branch
);
//J+
}
branches.add(branch);
} }
changesets.add(changeset); changesets.add(changeset);