diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index 94093b9..55e2043 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -158,27 +158,10 @@ JGitUtil.withGit(getRepositoryDir(owner, repository)){ git => val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id)) - import scala.collection.JavaConverters._ - import org.eclipse.jgit.lib.Constants - val walk = new org.eclipse.jgit.revwalk.RevWalk(git.getRepository) - val commit = walk.parseCommit(git.getRepository.resolve(revCommit.getName + "^0")) - - // TODO move to JGitUtil - val branchs = git.getRepository.getAllRefs.entrySet.asScala.filter { e => - (e.getKey.startsWith(Constants.R_HEADS) && walk.isMergedInto(commit, walk.parseCommit(e.getValue.getObjectId))) - }.map { e => - e.getValue.getName.substring(org.eclipse.jgit.lib.Constants.R_HEADS.length) - }.toList.sorted - - // TODO move to JGitUtil - val tags = git.getRepository.getAllRefs.entrySet.asScala.filter { e => - (e.getKey.startsWith(Constants.R_TAGS) && walk.isMergedInto(commit, walk.parseCommit(e.getValue.getObjectId))) - }.map { e => - e.getValue.getName.substring(org.eclipse.jgit.lib.Constants.R_TAGS.length) - }.toList.sorted.reverse - - repo.html.commit(id, new JGitUtil.CommitInfo(revCommit), branchs, tags, - getRepository(owner, repository, baseUrl).get, JGitUtil.getDiffs(git, id)) + repo.html.commit(id, new JGitUtil.CommitInfo(revCommit), + JGitUtil.getBranchesOfCommit(git, revCommit.getName), + JGitUtil.getTagsOfCommit(git, revCommit.getName), + getRepository(owner, repository, baseUrl).get, JGitUtil.getDiffs(git, id)) } }) diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index ff982c6..ee8043d 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -431,4 +431,42 @@ } } + /** + * Returns the list of branch names of the specified commit. + */ + def getBranchesOfCommit(git: Git, commitId: String): List[String] = { + val walk = new org.eclipse.jgit.revwalk.RevWalk(git.getRepository) + try { + val commit = walk.parseCommit(git.getRepository.resolve(commitId + "^0")) + + git.getRepository.getAllRefs.entrySet.asScala.filter { e => + (e.getKey.startsWith(Constants.R_HEADS) && walk.isMergedInto(commit, walk.parseCommit(e.getValue.getObjectId))) + }.map { e => + e.getValue.getName.substring(org.eclipse.jgit.lib.Constants.R_HEADS.length) + }.toList.sorted + + } finally { + walk.release + } + } + + /** + * Returns the list of tags of the specified commit. + */ + def getTagsOfCommit(git: Git, commitId: String): List[String] = { + val walk = new org.eclipse.jgit.revwalk.RevWalk(git.getRepository) + try { + val commit = walk.parseCommit(git.getRepository.resolve(commitId + "^0")) + + git.getRepository.getAllRefs.entrySet.asScala.filter { e => + (e.getKey.startsWith(Constants.R_TAGS) && walk.isMergedInto(commit, walk.parseCommit(e.getValue.getObjectId))) + }.map { e => + e.getValue.getName.substring(org.eclipse.jgit.lib.Constants.R_TAGS.length) + }.toList.sorted.reverse + + } finally { + walk.release + } + } + } \ No newline at end of file