From 5697dbd92c0415790eb473c2d88f22c76b3eb8e6 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 17 Apr 2011 17:56:05 +0200 Subject: [PATCH] added tag support --- .../scm/repository/GitChangesetViewer.java | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java b/plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java index bc003fe037..9f5d4b5662 100644 --- a/plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java +++ b/plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java @@ -38,7 +38,9 @@ package sonia.scm.repository; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.NoHeadException; 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.lib.RepositoryCache; import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.revwalk.RevCommit; @@ -55,7 +57,9 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @@ -111,12 +115,13 @@ public class GitChangesetViewer implements ChangesetViewer List changesetList = new ArrayList(); int counter = 0; TreeWalk treeWalk = new TreeWalk(gr); + Map tags = createTagMap(gr); for (RevCommit commit : git.log().call()) { if ((counter >= start) && (counter < start + max)) { - changesetList.add(createChangeset(treeWalk, commit)); + changesetList.add(createChangeset(treeWalk, tags, commit)); } counter++; @@ -196,13 +201,16 @@ public class GitChangesetViewer implements ChangesetViewer * * * @param treeWalk + * @param tags * @param commit * * @return * * @throws IOException */ - private Changeset createChangeset(TreeWalk treeWalk, RevCommit commit) + private Changeset createChangeset(TreeWalk treeWalk, + Map tags, + RevCommit commit) throws IOException { String id = commit.getName(); @@ -227,6 +235,21 @@ public class GitChangesetViewer implements ChangesetViewer changeset.setModifications(modifications); } + String tag = tags.get(commit.getId()); + + if (tag != null) + { + List tagList = changeset.getTags(); + + if (tagList == null) + { + tagList = new ArrayList(); + changeset.setTags(tagList); + } + + changeset.getTags().add(tag); + } + return changeset; } @@ -278,6 +301,31 @@ public class GitChangesetViewer implements ChangesetViewer return modifications; } + /** + * Method description + * + * + * @param repository + * + * @return + */ + private Map createTagMap(org.eclipse.jgit.lib.Repository repository) + { + Map tagMap = new HashMap(); + Map tags = repository.getTags(); + + if (tags != null) + { + for (Map.Entry e : tags.entrySet()) + { + tagMap.put(e.getValue().getObjectId(), e.getKey()); + } + } + + return tagMap; + } + //~--- fields --------------------------------------------------------------- /** Field description */