diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index f6b45f0..757d706 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -114,7 +114,7 @@ val branchName = params("branch") val page = params.getOrElse("page", "1").toInt - val (logs, hasNext) = JGitUtil.getCommitLog(Git.open(getRepositoryDir(owner, repository)), branchName, page) + val (logs, hasNext) = JGitUtil.getCommitLog(Git.open(getRepositoryDir(owner, repository)), branchName, page, 30) html.commits(branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext), logs.splitWith{ (commit1, commit2) => diff --git a/src/main/scala/app/WikiController.scala b/src/main/scala/app/WikiController.scala index 29de8c5..5cbd452 100644 --- a/src/main/scala/app/WikiController.scala +++ b/src/main/scala/app/WikiController.scala @@ -75,7 +75,7 @@ val repository = params("repository") // TODO retrieve all commit logs. - html.wikihistory(JGitUtil.getCommitLog(Git.open(WikiUtil.getWikiRepositoryDir(owner, repository)), "master", 100)._1, + html.wikihistory(JGitUtil.getCommitLog(Git.open(WikiUtil.getWikiRepositoryDir(owner, repository)), "master")._1, JGitUtil.getRepositoryInfo(owner, repository, servletContext)) } } \ No newline at end of file diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index 6cdca44..76e5f85 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -94,13 +94,17 @@ * @param git the Git object * @param revision the branch name or commit id * @param page the page number (1-) + * @param limit the number of commit info per page. 0 means unlimited. * @return a tuple of the commit list and whether has next */ - def getCommitLog(git: Git, revision: String, page: Int): (List[CommitInfo], Boolean) = { + def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0): (List[CommitInfo], Boolean) = { + val fixedPage = if(page <= 0) 1 else page + @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 true if(limit <= 0 || logs.size < limit) => + getCommitLog(i, count + 1, if(limit <= 0 || (fixedPage - 1) * limit < count) logs :+ new CommitInfo(i.next) else logs) case _ => (logs, i.hasNext) } diff --git a/src/main/twirl/wikihistory.scala.html b/src/main/twirl/wikihistory.scala.html index 92c75a4..b9aa52b 100644 --- a/src/main/twirl/wikihistory.scala.html +++ b/src/main/twirl/wikihistory.scala.html @@ -14,7 +14,6 @@ - @commits.map { commit =>