Display the commit count at the repository viewer.

This commit is contained in:
takezoe
2013-07-06 16:49:06 +09:00
parent e6451c7ede
commit 67d6cf37a5
4 changed files with 59 additions and 41 deletions

View File

@@ -210,14 +210,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
* @return HTML of the file list * @return HTML of the file list
*/ */
private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = { private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = {
getRepository(repository.owner, repository.name, baseUrl).map { repositoryInfo =>
val revision = if(revstr.isEmpty){ val revision = if(revstr.isEmpty){
repositoryInfo.repository.defaultBranch repository.repository.defaultBranch
} else { } else {
revstr revstr
} }
JGitUtil.withGit(getRepositoryDir(repositoryInfo.owner, repositoryInfo.name)){ git => JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
// get latest commit // get latest commit
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)) val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
@@ -225,14 +224,14 @@ trait RepositoryViewerControllerBase extends ControllerBase {
// process README.md // process README.md
val readme = files.find(_.name == "README.md").map { file => 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") new String(JGitUtil.getContent(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get, "UTF-8")
} }
repo.html.files( repo.html.files(
// current branch // current branch
revision, revision,
// repository // repository
repositoryInfo, repository,
// current path // current path
if(path == ".") Nil else path.split("/").toList, if(path == ".") Nil else path.split("/").toList,
// latest commit // latest commit
@@ -243,7 +242,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
readme readme
) )
} }
} getOrElse NotFound
} }
} }

View File

@@ -83,8 +83,7 @@ trait RepositoryService { self: AccountService =>
} }
q1.union(q2).filter(visibleFor(_, loginUserName)).sortBy(_.lastActivityDate desc).list map { repository => q1.union(q2).filter(visibleFor(_, loginUserName)).sortBy(_.lastActivityDate desc).list map { repository =>
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository)
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
} }
} }
@@ -98,8 +97,7 @@ trait RepositoryService { self: AccountService =>
*/ */
def getRepository(userName: String, repositoryName: String, baseUrl: String): Option[RepositoryInfo] = { def getRepository(userName: String, repositoryName: String, baseUrl: String): Option[RepositoryInfo] = {
(Query(Repositories) filter { t => t.byRepository(userName, repositoryName) } firstOption) map { repository => (Query(Repositories) filter { t => t.byRepository(userName, repositoryName) } firstOption) map { repository =>
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository)
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
} }
} }
@@ -112,9 +110,9 @@ trait RepositoryService { self: AccountService =>
*/ */
def getAccessibleRepositories(account: Option[Account], baseUrl: String): List[RepositoryInfo] = { 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) 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 { (account match {
@@ -127,7 +125,7 @@ trait RepositoryService { self: AccountService =>
} }
// for Guests // for Guests
case None => Query(Repositories) filter(_.isPrivate is false.bind) 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 @@ trait RepositoryService { self: AccountService =>
object RepositoryService { object RepositoryService {
case class RepositoryInfo(owner: String, name: String, url: String, repository: Repository, 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)
}
}
} }

View File

@@ -26,10 +26,11 @@ object JGitUtil {
* @param owner the user name of the repository owner * @param owner the user name of the repository owner
* @param name the repository name * @param name the repository name
* @param url the repository URL * @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 branchList the list of branch names
* @param tags the list of tags * @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. * The file data for the file list of the repository viewer.
@@ -141,8 +142,18 @@ object JGitUtil {
*/ */
def getRepositoryInfo(owner: String, repository: String, baseUrl: String): RepositoryInfo = { def getRepositoryInfo(owner: String, repository: String, baseUrl: String): RepositoryInfo = {
withGit(getRepositoryDir(owner, repository)){ git => 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( RepositoryInfo(
owner, repository, baseUrl + "/git/%s/%s.git".format(owner, repository), owner, repository, baseUrl + "/git/%s/%s.git".format(owner, repository),
// commit count
commitCount,
// branches // branches
git.branchList.call.asScala.map { ref => git.branchList.call.asScala.map { ref =>
ref.getName.replaceFirst("^refs/heads/", "") ref.getName.replaceFirst("^refs/heads/", "")

View File

@@ -10,6 +10,11 @@
@html.header("code", repository) @html.header("code", repository)
@tab(branch, repository, "files") @tab(branch, repository, "files")
<div class="head"> <div class="head">
<div class="pull-right">
@defining(repository.commitCount){ commitCount =>
<a href="@url(repository)/commits/@branch">@if(commitCount > 1000){ @commitCount+ } else { @commitCount } @plural(commitCount, "commit")</a>
}
</div>
<a href="@url(repository)/tree/@branch">@repository.name</a> / <a href="@url(repository)/tree/@branch">@repository.name</a> /
@pathList.zipWithIndex.map { case (section, i) => @pathList.zipWithIndex.map { case (section, i) =>
<a href="@url(repository)/tree/@branch/@pathList.take(i + 1).mkString("/")">@section</a> / <a href="@url(repository)/tree/@branch/@pathList.take(i + 1).mkString("/")">@section</a> /