Add file history page to the repository viewer.

This commit is contained in:
takezoe
2013-05-03 15:13:26 +09:00
parent 0c3a301f24
commit b29f2fb64a
5 changed files with 51 additions and 11 deletions

View File

@@ -116,12 +116,31 @@ class RepositoryViewerController extends ControllerBase {
val (logs, hasNext) = JGitUtil.getCommitLog(Git.open(getRepositoryDir(owner, repository)), branchName, page, 30)
html.commits(branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext),
html.commits(Nil, branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext),
logs.splitWith{ (commit1, commit2) =>
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
}, page, hasNext)
}
/**
* Displays the commit list of the specified resource.
*/
get("/:owner/:repository/commits/:branch/*"){
val owner = params("owner")
val repository = params("repository")
val branchName = params("branch")
val path = multiParams("splat").head //.replaceFirst("^tree/.+?/", "")
val page = params.getOrElse("page", "1").toInt
val (logs, hasNext) = JGitUtil.getCommitLog(Git.open(getRepositoryDir(owner, repository)), branchName, page, 30, path)
html.commits(path.split("/").toList, branchName, JGitUtil.getRepositoryInfo(owner, repository, servletContext),
logs.splitWith{ (commit1, commit2) =>
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
}, page, hasNext)
}
/**
* Displays the file content of the specified branch or commit.
*/
@@ -130,7 +149,7 @@ class RepositoryViewerController extends ControllerBase {
val repository = params("repository")
val id = params("id") // branch name or commit id
val raw = params.get("raw").getOrElse("false").toBoolean
val path = multiParams("splat").head.replaceFirst("^tree/.+?/", "")
val path = multiParams("splat").head //.replaceFirst("^tree/.+?/", "")
val repositoryInfo = JGitUtil.getRepositoryInfo(owner, repository, servletContext)
val git = Git.open(getRepositoryDir(owner, repository))

View File

@@ -41,9 +41,7 @@ class WikiController extends ControllerBase {
val git = Git.open(WikiUtil.getWikiRepositoryDir(owner, repository))
html.wikihistory(Some(page),
JGitUtil.getCommitLog(git, "master")._1.filter { commit =>
JGitUtil.getDiffs(git, commit.id).find(_.newPath == page + ".md").isDefined
},
JGitUtil.getCommitLog(git, "master", path = page + ".md")._1,
JGitUtil.getRepositoryInfo(owner, repository, servletContext))
}

View File

@@ -20,6 +20,7 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType
import org.eclipse.jgit.lib.FileMode
import org.eclipse.jgit.treewalk.filter.PathFilter
import org.eclipse.jgit.treewalk.CanonicalTreeParser
import org.eclipse.jgit.revwalk.filter.RevFilter
/**
* Provides complex JGit operations.
@@ -94,10 +95,11 @@ object JGitUtil {
* @param git the Git object
* @param revision the branch name or commit id
* @param page the page number (1-)
* @param limit the number of commit info per page. 0 means unlimited.
* @param limit the number of commit info per page. 0 (default) means unlimited.
* @param path filters by this path. default is no filter.
* @return a tuple of the commit list and whether has next
*/
def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0): (List[CommitInfo], Boolean) = {
def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0, path: String = ""): (List[CommitInfo], Boolean) = {
val fixedPage = if(page <= 0) 1 else page
@scala.annotation.tailrec
@@ -110,6 +112,14 @@ object JGitUtil {
val revWalk = new RevWalk(git.getRepository)
revWalk.markStart(revWalk.parseCommit(git.getRepository.resolve(revision)))
if(path.nonEmpty){
revWalk.setRevFilter(new RevFilter(){
def include(walk: RevWalk, commit: RevCommit): Boolean = {
getDiffs(git, commit.getName).find(_.newPath == path).nonEmpty
}
override def clone(): RevFilter = this
})
}
val commits = getCommitLog(revWalk.iterator, 0, Nil)
revWalk.release

View File

@@ -25,7 +25,7 @@
</div>
<div class="btn-group pull-right">
<a class="btn btn-mini" href="?raw=true">Raw</a>
<a class="btn btn-mini">History</a>
<a class="btn btn-mini" href="@path/@repository.owner/@repository.name/commits/@branch/@pathList.mkString("/")">History</a>
</div>
</th>
</tr>

View File

@@ -1,11 +1,24 @@
@(branch: String, repository: app.RepositoryInfo, commits: Seq[Seq[app.CommitInfo]], page: Int, hasNext: Boolean)(implicit context: app.Context)
@(pathList: List[String], branch: String, repository: app.RepositoryInfo, commits: Seq[Seq[app.CommitInfo]], page: Int, hasNext: Boolean)(implicit context: app.Context)
@import context._
@import view.helpers
@main(repository.owner+"/"+repository.name) {
@header("code", repository)
@navtab(branch, repository, "commits")
@navtab(branch, repository, if(pathList.isEmpty) "commits" else "files")
<div class="head">
<a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> / Commit History
@if(pathList.isEmpty){
<a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> / Commit History
}
@if(pathList.nonEmpty){
<span class="description">History for</span>
<a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> /
@pathList.zipWithIndex.map { case (section, i) =>
@if(i == pathList.length - 1){
@section
} else {
<a href="@path/@repository.owner/@repository.name/tree/@branch/@pathList.take(i + 1).mkString("/")">@section</a> /
}
}
}
</div>
@commits.map { date =>