mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
Move getBranchesOfCommit and getTagsOfCommit to JGitUtil.
This commit is contained in:
@@ -158,26 +158,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
||||||
import org.eclipse.jgit.lib.Constants
|
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
||||||
val walk = new org.eclipse.jgit.revwalk.RevWalk(git.getRepository)
|
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
||||||
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))
|
getRepository(owner, repository, baseUrl).get, JGitUtil.getDiffs(git, id))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -431,4 +431,42 @@ object JGitUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user