getCommitLog is moved to JGitUtil and it get commit logs from only bared

repository.
This commit is contained in:
takezoe
2013-04-29 04:28:46 +09:00
parent 902b4ec699
commit 891c932358
2 changed files with 34 additions and 11 deletions

View File

@@ -78,16 +78,9 @@ class RepositoryViewerServlet extends ServletBase {
val repository = params("repository")
val branchName = params("branch")
val page = params.getOrElse("page", "1").toInt
val dir = getBranchDir(owner, repository, branchName)
@scala.annotation.tailrec
def getCommitLog(i: java.util.Iterator[RevCommit], count: Int, logs: List[CommitInfo]): (List[CommitInfo], Boolean) =
i.hasNext match {
case true if(logs.size < 30) => getCommitLog(i, count + 1, if((page - 1) * 30 < count) logs :+ new CommitInfo(i.next) else logs)
case _ => (logs, i.hasNext)
}
val (logs, hasNext) = getCommitLog(Git.open(dir).log.call.iterator, 0, Nil)
val (logs, hasNext) = JGitUtil.getCommitLog(
Git.open(getRepositoryDir(owner, repository)).getRepository, branchName, page)
html.commits(branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext),
logs.splitWith{ (commit1, commit2) =>

View File

@@ -1,7 +1,7 @@
package util
import org.eclipse.jgit.api.Git
import app.{RepositoryInfo, FileInfo}
import app.{RepositoryInfo, FileInfo, CommitInfo}
import util.Directory._
import scala.collection.JavaConverters._
import javax.servlet.ServletContext
@@ -100,8 +100,38 @@ object JGitUtil {
}}
}
/**
* Returns the commit list of the specified branch.
*
* @param repository the repository
* @param revision the branch name or commit id
* @param page the page number (1-)
* @return a tuple of the commit list and whether has next
*/
def getCommitLog(repository: Repository, revision: String, page: Int): (List[CommitInfo], Boolean) = {
@scala.annotation.tailrec
def getCommitLog(i: java.util.Iterator[RevCommit], count: Int, logs: List[CommitInfo]): (List[CommitInfo], Boolean) =
i.hasNext match {
case true if(logs.size < 30) => getCommitLog(i, count + 1, if((page - 1) * 30 < count) logs :+ new CommitInfo(i.next) else logs)
case _ => (logs, i.hasNext)
}
val revWalk = new RevWalk(repository)
revWalk.markStart(revWalk.parseCommit(repository.resolve(revision)))
val commits = getCommitLog(revWalk.iterator, 0, Nil)
revWalk.release
commits
}
/**
* Returns the latest RevCommit of the specified path.
*
* @param repository the repository
* @param the path
* @param the branch name or commit id
* @return the latest commit
*/
def getLatestCommitFromPath(repository: Repository, path: String, revision: String): RevCommit = {
val revWalk = new RevWalk(repository)