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

@@ -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 @@ object JGitUtil {
}
/**
* 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)