diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index bae72a1..be5b36d 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -210,40 +210,38 @@ * @return HTML of the file list */ private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = { - getRepository(repository.owner, repository.name, baseUrl).map { repositoryInfo => - val revision = if(revstr.isEmpty){ - repositoryInfo.repository.defaultBranch - } else { - revstr + val revision = if(revstr.isEmpty){ + repository.repository.defaultBranch + } else { + revstr + } + + JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git => + // get latest commit + val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)) + + val files = JGitUtil.getFileList(git, revision, path) + + // process README.md + val readme = files.find(_.name == "README.md").map { file => + new String(JGitUtil.getContent(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get, "UTF-8") } - JGitUtil.withGit(getRepositoryDir(repositoryInfo.owner, repositoryInfo.name)){ git => - // get latest commit - val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)) - - val files = JGitUtil.getFileList(git, revision, path) - - // process README.md - val readme = files.find(_.name == "README.md").map { file => - new String(JGitUtil.getContent(Git.open(getRepositoryDir(repositoryInfo.owner, repositoryInfo.name)), file.id, true).get, "UTF-8") - } - - repo.html.files( - // current branch - revision, - // repository - repositoryInfo, - // current path - if(path == ".") Nil else path.split("/").toList, - // latest commit - new JGitUtil.CommitInfo(revCommit), - // file list - files, - // readme - readme - ) - } - } getOrElse NotFound + repo.html.files( + // current branch + revision, + // repository + repository, + // current path + if(path == ".") Nil else path.split("/").toList, + // latest commit + new JGitUtil.CommitInfo(revCommit), + // file list + files, + // readme + readme + ) + } } } \ No newline at end of file diff --git a/src/main/scala/service/RepositoryService.scala b/src/main/scala/service/RepositoryService.scala index af6a9a7..8a1d5a4 100644 --- a/src/main/scala/service/RepositoryService.scala +++ b/src/main/scala/service/RepositoryService.scala @@ -83,8 +83,7 @@ } q1.union(q2).filter(visibleFor(_, loginUserName)).sortBy(_.lastActivityDate desc).list map { repository => - val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) - RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) + new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository) } } @@ -98,8 +97,7 @@ */ def getRepository(userName: String, repositoryName: String, baseUrl: String): Option[RepositoryInfo] = { (Query(Repositories) filter { t => t.byRepository(userName, repositoryName) } firstOption) map { repository => - val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) - RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) + new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository) } } @@ -112,9 +110,9 @@ */ def getAccessibleRepositories(account: Option[Account], baseUrl: String): List[RepositoryInfo] = { - def createRepositoryInfo(repository: Repository): RepositoryInfo = { + def newRepositoryInfo(repository: Repository): RepositoryInfo = { val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) - RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) + new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository) } (account match { @@ -127,7 +125,7 @@ } // for Guests case None => Query(Repositories) filter(_.isPrivate is false.bind) - }).sortBy(_.lastActivityDate desc).list.map(createRepositoryInfo _) + }).sortBy(_.lastActivityDate desc).list.map(newRepositoryInfo _) } /** @@ -189,6 +187,12 @@ object RepositoryService { case class RepositoryInfo(owner: String, name: String, url: String, repository: Repository, - branchList: List[String], tags: List[util.JGitUtil.TagInfo]) + commitCount: Int, branchList: List[String], tags: List[util.JGitUtil.TagInfo]){ + + def this(repo: JGitUtil.RepositoryInfo, model: Repository) = { + this(repo.owner, repo.name, repo.url, model, repo.commitCount, repo.branchList, repo.tags) + } + + } } \ No newline at end of file diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index 198ff80..dc094bd 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -26,10 +26,11 @@ * @param owner the user name of the repository owner * @param name the repository name * @param url the repository URL + * @param commitCount the commit count. If the repository has over 1000 commits then this property is 1001. * @param branchList the list of branch names * @param tags the list of tags */ - case class RepositoryInfo(owner: String, name: String, url: String, branchList: List[String], tags: List[TagInfo]) + case class RepositoryInfo(owner: String, name: String, url: String, commitCount: Int, branchList: List[String], tags: List[TagInfo]) /** * The file data for the file list of the repository viewer. @@ -141,8 +142,18 @@ */ def getRepositoryInfo(owner: String, repository: String, baseUrl: String): RepositoryInfo = { withGit(getRepositoryDir(owner, repository)){ git => + // get commit count + val i = git.log.all.call.iterator + var commitCount = 0 + while(i.hasNext && commitCount <= 1000){ + i.next + commitCount = commitCount + 1 + } + RepositoryInfo( owner, repository, baseUrl + "/git/%s/%s.git".format(owner, repository), + // commit count + commitCount, // branches git.branchList.call.asScala.map { ref => ref.getName.replaceFirst("^refs/heads/", "") diff --git a/src/main/twirl/repo/files.scala.html b/src/main/twirl/repo/files.scala.html index bb20b20..613cffe 100644 --- a/src/main/twirl/repo/files.scala.html +++ b/src/main/twirl/repo/files.scala.html @@ -10,6 +10,11 @@ @html.header("code", repository) @tab(branch, repository, "files")
+
+ @defining(repository.commitCount){ commitCount => + @if(commitCount > 1000){ @commitCount+ } else { @commitCount } @plural(commitCount, "commit") + } +
@repository.name / @pathList.zipWithIndex.map { case (section, i) => @section /