(refs #810)Display Compare (or Pull Request) button for the default branch of the forked repository

This commit is contained in:
Naoki Takezoe
2015-07-28 01:57:54 +09:00
parent 41fff399b5
commit 8f10c8051e
2 changed files with 15 additions and 9 deletions

View File

@@ -436,10 +436,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
* Displays branches. * Displays branches.
*/ */
get("/:owner/:repository/branches")(referrersOnly { repository => get("/:owner/:repository/branches")(referrersOnly { repository =>
val branches = JGitUtil.getBranches(repository.owner, repository.name, repository.repository.defaultBranch) val branches = JGitUtil.getBranches(
owner = repository.owner,
name = repository.name,
defaultBranch = repository.repository.defaultBranch,
origin = repository.repository.originUserName.isEmpty
)
.sortBy(br => (br.mergeInfo.isEmpty, br.commitTime)) .sortBy(br => (br.mergeInfo.isEmpty, br.commitTime))
.map(br => br -> getPullRequestByRequestCommit(repository.owner, repository.name, repository.repository.defaultBranch, br.name, br.commitId)) .map(br => br -> getPullRequestByRequestCommit(repository.owner, repository.name, repository.repository.defaultBranch, br.name, br.commitId))
.reverse .reverse
html.branches(branches, hasWritePermission(repository.owner, repository.name, context.loginAccount), repository) html.branches(branches, hasWritePermission(repository.owner, repository.name, context.loginAccount), repository)
}) })

View File

@@ -791,7 +791,7 @@ object JGitUtil {
return git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next return git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next
} }
def getBranches(owner: String, name: String, defaultBranch: String): Seq[BranchInfo] = { def getBranches(owner: String, name: String, defaultBranch: String, origin: Boolean): Seq[BranchInfo] = {
using(Git.open(getRepositoryDir(owner, name))){ git => using(Git.open(getRepositoryDir(owner, name))){ git =>
val repo = git.getRepository val repo = git.getRepository
val defaultObject = if (repo.getAllRefs.keySet().contains(defaultBranch)) { val defaultObject = if (repo.getAllRefs.keySet().contains(defaultBranch)) {
@@ -802,20 +802,20 @@ object JGitUtil {
git.branchList.call.asScala.map { ref => git.branchList.call.asScala.map { ref =>
val walk = new RevWalk(repo) val walk = new RevWalk(repo)
try{ try {
val defaultCommit = walk.parseCommit(defaultObject) val defaultCommit = walk.parseCommit(defaultObject)
val branchName = ref.getName.stripPrefix("refs/heads/") val branchName = ref.getName.stripPrefix("refs/heads/")
val branchCommit = if(branchName == defaultBranch){ val branchCommit = if(branchName == defaultBranch){
defaultCommit defaultCommit
}else{ } else {
walk.parseCommit(ref.getObjectId) walk.parseCommit(ref.getObjectId)
} }
val when = branchCommit.getCommitterIdent.getWhen val when = branchCommit.getCommitterIdent.getWhen
val committer = branchCommit.getCommitterIdent.getName val committer = branchCommit.getCommitterIdent.getName
val committerEmail = branchCommit.getCommitterIdent.getEmailAddress val committerEmail = branchCommit.getCommitterIdent.getEmailAddress
val mergeInfo = if(branchName==defaultBranch){ val mergeInfo = if(origin && branchName == defaultBranch){
None None
}else{ } else {
walk.reset() walk.reset()
walk.setRevFilter( RevFilter.MERGE_BASE ) walk.setRevFilter( RevFilter.MERGE_BASE )
walk.markStart(branchCommit) walk.markStart(branchCommit)