mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
Added limit parameter to JGit.getCommitLogs() and page parameter became
optional.
This commit is contained in:
@@ -114,7 +114,7 @@ class RepositoryViewerController extends ControllerBase {
|
|||||||
val branchName = params("branch")
|
val branchName = params("branch")
|
||||||
val page = params.getOrElse("page", "1").toInt
|
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),
|
html.commits(branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext),
|
||||||
logs.splitWith{ (commit1, commit2) =>
|
logs.splitWith{ (commit1, commit2) =>
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class WikiController extends ControllerBase {
|
|||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
// TODO retrieve all commit logs.
|
// 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))
|
JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,13 +94,17 @@ object JGitUtil {
|
|||||||
* @param git the Git object
|
* @param git the Git object
|
||||||
* @param revision the branch name or commit id
|
* @param revision the branch name or commit id
|
||||||
* @param page the page number (1-)
|
* @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
|
* @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
|
@scala.annotation.tailrec
|
||||||
def getCommitLog(i: java.util.Iterator[RevCommit], count: Int, logs: List[CommitInfo]): (List[CommitInfo], Boolean) =
|
def getCommitLog(i: java.util.Iterator[RevCommit], count: Int, logs: List[CommitInfo]): (List[CommitInfo], Boolean) =
|
||||||
i.hasNext match {
|
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)
|
case _ => (logs, i.hasNext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<input type="button" value="Compare Revisions" class="btn"/>
|
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered">
|
||||||
@commits.map { commit =>
|
@commits.map { commit =>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user