mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 21:45:43 +01:00
improve git branch informations
This commit is contained in:
@@ -40,6 +40,7 @@ import com.google.common.collect.Multimap;
|
||||
import org.eclipse.jgit.diff.DiffEntry;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevTree;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
@@ -59,6 +60,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -99,6 +101,7 @@ public class GitChangesetConverter implements Closeable
|
||||
public GitChangesetConverter(org.eclipse.jgit.lib.Repository repository,
|
||||
RevWalk revWalk, int idLength)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.idLength = idLength;
|
||||
|
||||
if (revWalk == null)
|
||||
@@ -175,6 +178,23 @@ public class GitChangesetConverter implements Closeable
|
||||
changeset.getTags().addAll(tagCollection);
|
||||
}
|
||||
|
||||
Set<Ref> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return changeset;
|
||||
}
|
||||
|
||||
@@ -285,6 +305,9 @@ public class GitChangesetConverter implements Closeable
|
||||
/** Field description */
|
||||
private int idLength;
|
||||
|
||||
/** Field description */
|
||||
private org.eclipse.jgit.lib.Repository repository;
|
||||
|
||||
/** Field description */
|
||||
private RevWalk revWalk;
|
||||
|
||||
|
||||
@@ -78,6 +78,9 @@ public class GitUtil
|
||||
/** Field description */
|
||||
public static final String REF_MASTER = "master";
|
||||
|
||||
/** Field description */
|
||||
private static final String PREFIX_HEADS = "refs/heads/";
|
||||
|
||||
/** Field description */
|
||||
private static final String PREFIX_TAG = "refs/tags/";
|
||||
|
||||
@@ -209,6 +212,28 @@ public class GitUtil
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param ref
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getBranch(Ref ref)
|
||||
{
|
||||
String branch = null;
|
||||
|
||||
String name = ref.getName();
|
||||
|
||||
if (name.startsWith(PREFIX_HEADS))
|
||||
{
|
||||
branch = name.substring(PREFIX_HEADS.length());
|
||||
}
|
||||
|
||||
return branch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -239,6 +264,43 @@ public class GitUtil
|
||||
return branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param revWalk
|
||||
* @param ref
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static RevCommit getCommit(org.eclipse.jgit.lib.Repository repository,
|
||||
RevWalk revWalk, Ref ref)
|
||||
throws IOException
|
||||
{
|
||||
RevCommit commit = null;
|
||||
ObjectId id = ref.getPeeledObjectId();
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
id = ref.getObjectId();
|
||||
}
|
||||
|
||||
if (id != null)
|
||||
{
|
||||
if (revWalk == null)
|
||||
{
|
||||
revWalk = new RevWalk(repository);
|
||||
}
|
||||
|
||||
commit = revWalk.parseCommit(id);
|
||||
}
|
||||
|
||||
return commit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -350,41 +412,4 @@ public class GitUtil
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param revWalk
|
||||
* @param ref
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static RevCommit getCommit(
|
||||
org.eclipse.jgit.lib.Repository repository, RevWalk revWalk, Ref ref)
|
||||
throws IOException
|
||||
{
|
||||
RevCommit commit = null;
|
||||
ObjectId id = ref.getPeeledObjectId();
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
id = ref.getObjectId();
|
||||
}
|
||||
|
||||
if (id != null)
|
||||
{
|
||||
if (revWalk == null)
|
||||
{
|
||||
revWalk = new RevWalk(repository);
|
||||
}
|
||||
|
||||
commit = revWalk.parseCommit(id);
|
||||
}
|
||||
|
||||
return commit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user