mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
getCommitLog is moved to JGitUtil and it get commit logs from only bared
repository.
This commit is contained in:
@@ -78,16 +78,9 @@ class RepositoryViewerServlet extends ServletBase {
|
|||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val branchName = params("branch")
|
val branchName = params("branch")
|
||||||
val page = params.getOrElse("page", "1").toInt
|
val page = params.getOrElse("page", "1").toInt
|
||||||
val dir = getBranchDir(owner, repository, branchName)
|
|
||||||
|
|
||||||
@scala.annotation.tailrec
|
val (logs, hasNext) = JGitUtil.getCommitLog(
|
||||||
def getCommitLog(i: java.util.Iterator[RevCommit], count: Int, logs: List[CommitInfo]): (List[CommitInfo], Boolean) =
|
Git.open(getRepositoryDir(owner, repository)).getRepository, branchName, page)
|
||||||
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)
|
|
||||||
|
|
||||||
html.commits(branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext),
|
html.commits(branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext),
|
||||||
logs.splitWith{ (commit1, commit2) =>
|
logs.splitWith{ (commit1, commit2) =>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import app.{RepositoryInfo, FileInfo}
|
import app.{RepositoryInfo, FileInfo, CommitInfo}
|
||||||
import util.Directory._
|
import util.Directory._
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import javax.servlet.ServletContext
|
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.
|
* 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 = {
|
def getLatestCommitFromPath(repository: Repository, path: String, revision: String): RevCommit = {
|
||||||
val revWalk = new RevWalk(repository)
|
val revWalk = new RevWalk(repository)
|
||||||
|
|||||||
Reference in New Issue
Block a user