diff --git a/src/main/scala/app/RepositoryViewerServlet.scala b/src/main/scala/app/RepositoryViewerServlet.scala index 4e9955b..8644592 100644 --- a/src/main/scala/app/RepositoryViewerServlet.scala +++ b/src/main/scala/app/RepositoryViewerServlet.scala @@ -78,16 +78,9 @@ 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) => diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index e849d0c..876c412 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -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 @@ -101,7 +101,37 @@ } /** - * Returns the latest RevCommit of the specified path. + * 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)