mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-05 04:55:50 +01:00
fix missing git tags in commit detail view
This commit is contained in:
@@ -35,6 +35,9 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import org.eclipse.jgit.diff.DiffEntry;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
@@ -56,7 +59,7 @@ import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -83,7 +86,7 @@ public class GitChangesetConverter implements Closeable
|
||||
* @param idLength
|
||||
*/
|
||||
public GitChangesetConverter(org.eclipse.jgit.lib.Repository repository,
|
||||
int idLength)
|
||||
int idLength)
|
||||
{
|
||||
this(repository, null, idLength);
|
||||
}
|
||||
@@ -97,7 +100,7 @@ public class GitChangesetConverter implements Closeable
|
||||
* @param idLength
|
||||
*/
|
||||
public GitChangesetConverter(org.eclipse.jgit.lib.Repository repository,
|
||||
RevWalk revWalk, int idLength)
|
||||
RevWalk revWalk, int idLength)
|
||||
{
|
||||
this.idLength = idLength;
|
||||
this.revWalk = revWalk;
|
||||
@@ -147,7 +150,7 @@ public class GitChangesetConverter implements Closeable
|
||||
long date = GitUtil.getCommitTime(commit);
|
||||
PersonIdent authorIndent = commit.getAuthorIdent();
|
||||
Person author = new Person(authorIndent.getName(),
|
||||
authorIndent.getEmailAddress());
|
||||
authorIndent.getEmailAddress());
|
||||
String message = commit.getShortMessage();
|
||||
Changeset changeset = new Changeset(id, date, author, message);
|
||||
|
||||
@@ -163,11 +166,11 @@ public class GitChangesetConverter implements Closeable
|
||||
changeset.setModifications(modifications);
|
||||
}
|
||||
|
||||
String tag = tags.get(commit.getId());
|
||||
Collection<String> tagCollection = tags.get(commit.getId());
|
||||
|
||||
if (tag != null)
|
||||
if (tagCollection != null)
|
||||
{
|
||||
changeset.getTags().add(tag);
|
||||
changeset.getTags().addAll(tagCollection);
|
||||
}
|
||||
|
||||
return changeset;
|
||||
@@ -213,7 +216,7 @@ public class GitChangesetConverter implements Closeable
|
||||
* @throws IOException
|
||||
*/
|
||||
private Modifications createModifications(TreeWalk treeWalk, RevCommit commit)
|
||||
throws IOException
|
||||
throws IOException
|
||||
{
|
||||
Modifications modifications = null;
|
||||
|
||||
@@ -276,7 +279,7 @@ public class GitChangesetConverter implements Closeable
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* TODO cache
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
@@ -284,7 +287,7 @@ public class GitChangesetConverter implements Closeable
|
||||
*/
|
||||
private void createTagMap(org.eclipse.jgit.lib.Repository repository)
|
||||
{
|
||||
tags = new HashMap<ObjectId, String>();
|
||||
tags = ArrayListMultimap.create();
|
||||
|
||||
Map<String, Ref> tagMap = repository.getTags();
|
||||
|
||||
@@ -292,11 +295,68 @@ public class GitChangesetConverter implements Closeable
|
||||
{
|
||||
for (Map.Entry<String, Ref> e : tagMap.entrySet())
|
||||
{
|
||||
tags.put(e.getValue().getObjectId(), e.getKey());
|
||||
try
|
||||
{
|
||||
|
||||
RevCommit c = getCommit(repository, e.getValue());
|
||||
|
||||
if (c != null)
|
||||
{
|
||||
tags.put(c.getId(), e.getKey());
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not find commit for tag {}", e.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not read commit for ref", ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param ref
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private RevCommit getCommit(org.eclipse.jgit.lib.Repository repository,
|
||||
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;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@@ -306,7 +366,7 @@ public class GitChangesetConverter implements Closeable
|
||||
private RevWalk revWalk;
|
||||
|
||||
/** Field description */
|
||||
private Map<ObjectId, String> tags;
|
||||
private Multimap<ObjectId, String> tags;
|
||||
|
||||
/** Field description */
|
||||
private TreeWalk treeWalk;
|
||||
|
||||
@@ -75,6 +75,9 @@ public class GitUtil
|
||||
/** Field description */
|
||||
public static final String REF_MASTER = "master";
|
||||
|
||||
/** Field description */
|
||||
private static final String PREFIX_TAG = "refs/tags/";
|
||||
|
||||
/** the logger for GitUtil */
|
||||
private static final Logger logger = LoggerFactory.getLogger(GitUtil.class);
|
||||
|
||||
@@ -105,10 +108,10 @@ public class GitUtil
|
||||
* @throws IOException
|
||||
*/
|
||||
public static org.eclipse.jgit.lib.Repository open(File directory)
|
||||
throws IOException
|
||||
throws IOException
|
||||
{
|
||||
return RepositoryCache.open(RepositoryCache.FileKey.lenient(directory,
|
||||
FS.DETECTED), true);
|
||||
FS.DETECTED), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,8 +170,8 @@ public class GitUtil
|
||||
* @throws IOException
|
||||
*/
|
||||
public static ObjectId getBranchId(org.eclipse.jgit.lib.Repository repo,
|
||||
String branchName)
|
||||
throws IOException
|
||||
String branchName)
|
||||
throws IOException
|
||||
{
|
||||
ObjectId branchId = null;
|
||||
Ref ref = repo.getRef(branchName);
|
||||
@@ -259,8 +262,8 @@ public class GitUtil
|
||||
* @throws IOException
|
||||
*/
|
||||
public static ObjectId getRevisionId(org.eclipse.jgit.lib.Repository repo,
|
||||
String revision)
|
||||
throws IOException
|
||||
String revision)
|
||||
throws IOException
|
||||
{
|
||||
ObjectId revId = null;
|
||||
|
||||
@@ -275,4 +278,25 @@ public class GitUtil
|
||||
|
||||
return revId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param ref
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getTagName(Ref ref)
|
||||
{
|
||||
String name = ref.getName();
|
||||
|
||||
if (name.startsWith(PREFIX_TAG))
|
||||
{
|
||||
name = name.substring(PREFIX_TAG.length());
|
||||
}
|
||||
|
||||
return name;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@ import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.Tag;
|
||||
@@ -60,17 +58,6 @@ import java.util.List;
|
||||
public class GitTagsCommand extends AbstractGitCommand implements TagsCommand
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String PREFIX_TAG = "refs/tags/";
|
||||
|
||||
/**
|
||||
* the logger for GitTagsCommand
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(GitTagsCommand.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -110,12 +97,7 @@ public class GitTagsCommand extends AbstractGitCommand implements TagsCommand
|
||||
@Override
|
||||
public Tag apply(Ref input)
|
||||
{
|
||||
String name = input.getName();
|
||||
|
||||
if (name.startsWith(PREFIX_TAG))
|
||||
{
|
||||
name = name.substring(PREFIX_TAG.length());
|
||||
}
|
||||
String name = GitUtil.getTagName(input);
|
||||
|
||||
return new Tag(name, input.getObjectId().name());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user