mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 03:26:06 +01:00
Add file history page to the repository viewer.
This commit is contained in:
@@ -116,12 +116,31 @@ class RepositoryViewerController extends ControllerBase {
|
|||||||
|
|
||||||
val (logs, hasNext) = JGitUtil.getCommitLog(Git.open(getRepositoryDir(owner, repository)), branchName, page, 30)
|
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) =>
|
logs.splitWith{ (commit1, commit2) =>
|
||||||
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
|
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
|
||||||
}, page, hasNext)
|
}, 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.
|
* Displays the file content of the specified branch or commit.
|
||||||
*/
|
*/
|
||||||
@@ -130,7 +149,7 @@ class RepositoryViewerController extends ControllerBase {
|
|||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val id = params("id") // branch name or commit id
|
val id = params("id") // branch name or commit id
|
||||||
val raw = params.get("raw").getOrElse("false").toBoolean
|
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 repositoryInfo = JGitUtil.getRepositoryInfo(owner, repository, servletContext)
|
||||||
|
|
||||||
val git = Git.open(getRepositoryDir(owner, repository))
|
val git = Git.open(getRepositoryDir(owner, repository))
|
||||||
|
|||||||
@@ -41,9 +41,7 @@ class WikiController extends ControllerBase {
|
|||||||
val git = Git.open(WikiUtil.getWikiRepositoryDir(owner, repository))
|
val git = Git.open(WikiUtil.getWikiRepositoryDir(owner, repository))
|
||||||
|
|
||||||
html.wikihistory(Some(page),
|
html.wikihistory(Some(page),
|
||||||
JGitUtil.getCommitLog(git, "master")._1.filter { commit =>
|
JGitUtil.getCommitLog(git, "master", path = page + ".md")._1,
|
||||||
JGitUtil.getDiffs(git, commit.id).find(_.newPath == page + ".md").isDefined
|
|
||||||
},
|
|
||||||
JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
|||||||
import org.eclipse.jgit.lib.FileMode
|
import org.eclipse.jgit.lib.FileMode
|
||||||
import org.eclipse.jgit.treewalk.filter.PathFilter
|
import org.eclipse.jgit.treewalk.filter.PathFilter
|
||||||
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
||||||
|
import org.eclipse.jgit.revwalk.filter.RevFilter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides complex JGit operations.
|
* Provides complex JGit operations.
|
||||||
@@ -94,10 +95,11 @@ object JGitUtil {
|
|||||||
* @param git the Git object
|
* @param git the Git object
|
||||||
* @param revision the branch name or commit id
|
* @param revision the branch name or commit id
|
||||||
* @param page the page number (1-)
|
* @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
|
* @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
|
val fixedPage = if(page <= 0) 1 else page
|
||||||
|
|
||||||
@scala.annotation.tailrec
|
@scala.annotation.tailrec
|
||||||
@@ -110,6 +112,14 @@ object JGitUtil {
|
|||||||
|
|
||||||
val revWalk = new RevWalk(git.getRepository)
|
val revWalk = new RevWalk(git.getRepository)
|
||||||
revWalk.markStart(revWalk.parseCommit(git.getRepository.resolve(revision)))
|
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)
|
val commits = getCommitLog(revWalk.iterator, 0, Nil)
|
||||||
revWalk.release
|
revWalk.release
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="btn-group pull-right">
|
<div class="btn-group pull-right">
|
||||||
<a class="btn btn-mini" href="?raw=true">Raw</a>
|
<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>
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -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 context._
|
||||||
@import view.helpers
|
@import view.helpers
|
||||||
@main(repository.owner+"/"+repository.name) {
|
@main(repository.owner+"/"+repository.name) {
|
||||||
@header("code", repository)
|
@header("code", repository)
|
||||||
@navtab(branch, repository, "commits")
|
@navtab(branch, repository, if(pathList.isEmpty) "commits" else "files")
|
||||||
<div class="head">
|
<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>
|
</div>
|
||||||
|
|
||||||
@commits.map { date =>
|
@commits.map { date =>
|
||||||
|
|||||||
Reference in New Issue
Block a user