mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
(refs #36)Handle unresolved revision string.
This commit is contained in:
@@ -58,13 +58,14 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/commits/:branch")(referrersOnly { repository =>
|
get("/:owner/:repository/commits/:branch")(referrersOnly { repository =>
|
||||||
val branchName = params("branch")
|
val branchName = params("branch")
|
||||||
val page = params.getOrElse("page", "1").toInt
|
val page = params.getOrElse("page", "1").toInt
|
||||||
|
|
||||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||||
val (logs, hasNext) = JGitUtil.getCommitLog(git, branchName, page, 30)
|
JGitUtil.getCommitLog(git, branchName, page, 30) match {
|
||||||
|
case Right((logs, hasNext)) =>
|
||||||
repo.html.commits(Nil, branchName, repository, logs.splitWith{ (commit1, commit2) =>
|
repo.html.commits(Nil, branchName, repository, 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)
|
||||||
|
case Left(_) => NotFound
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -77,12 +78,14 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val page = params.getOrElse("page", "1").toInt
|
val page = params.getOrElse("page", "1").toInt
|
||||||
|
|
||||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||||
val (logs, hasNext) = JGitUtil.getCommitLog(git, branchName, page, 30, path)
|
JGitUtil.getCommitLog(git, branchName, page, 30, path) match {
|
||||||
|
case Right((logs, hasNext)) =>
|
||||||
repo.html.commits(path.split("/").toList, branchName, repository,
|
repo.html.commits(path.split("/").toList, branchName, repository,
|
||||||
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)
|
||||||
|
case Left(_) => NotFound
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -214,16 +217,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
repo.html.guide(repository)
|
repo.html.guide(repository)
|
||||||
} else {
|
} else {
|
||||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||||
|
val revisions = Seq(if(revstr.isEmpty) repository.repository.defaultBranch else revstr, repository.branchList.head)
|
||||||
|
//val objectId = git.getRepository.resolve(revstr2)
|
||||||
|
|
||||||
// get specified commit
|
// get specified commit
|
||||||
val (revCommit, revision) = try {
|
revisions.map { rev => (git.getRepository.resolve(rev), rev)}.find(_._1 != null).map { case (objectId, revision) =>
|
||||||
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
|
val revCommit = JGitUtil.getRevCommitFromId(git, objectId)
|
||||||
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
|
|
||||||
} catch {
|
|
||||||
case e: NullPointerException => {
|
|
||||||
val revision = repository.branchList.head
|
|
||||||
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// get files
|
// get files
|
||||||
val files = JGitUtil.getFileList(git, revision, path)
|
val files = JGitUtil.getFileList(git, revision, path)
|
||||||
// process README.md
|
// process README.md
|
||||||
@@ -235,6 +235,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
if(path == ".") Nil else path.split("/").toList, // current path
|
if(path == ".") Nil else path.split("/").toList, // current path
|
||||||
new JGitUtil.CommitInfo(revCommit), // latest commit
|
new JGitUtil.CommitInfo(revCommit), // latest commit
|
||||||
files, readme)
|
files, readme)
|
||||||
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val pageName = params("page")
|
val pageName = params("page")
|
||||||
|
|
||||||
JGitUtil.withGit(getWikiRepositoryDir(repository.owner, repository.name)){ git =>
|
JGitUtil.withGit(getWikiRepositoryDir(repository.owner, repository.name)){ git =>
|
||||||
wiki.html.history(Some(pageName), JGitUtil.getCommitLog(git, "master", path = pageName + ".md")._1, repository)
|
JGitUtil.getCommitLog(git, "master", path = pageName + ".md") match {
|
||||||
|
case Right((logs, hasNext)) => wiki.html.history(Some(pageName), logs, repository)
|
||||||
|
case Left(_) => NotFound
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -117,7 +120,10 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
||||||
JGitUtil.withGit(getWikiRepositoryDir(repository.owner, repository.name)){ git =>
|
JGitUtil.withGit(getWikiRepositoryDir(repository.owner, repository.name)){ git =>
|
||||||
wiki.html.history(None, JGitUtil.getCommitLog(git, "master")._1, repository)
|
JGitUtil.getCommitLog(git, "master") match {
|
||||||
|
case Right((logs, hasNext)) => wiki.html.history(None, logs, repository)
|
||||||
|
case Left(_) => NotFound
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ object JGitUtil {
|
|||||||
* @param path filters by this path. default is no filter.
|
* @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, path: String = ""): (List[CommitInfo], Boolean) = {
|
def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0, path: String = ""): Either[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
|
||||||
@@ -267,7 +267,11 @@ object JGitUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val revWalk = new RevWalk(git.getRepository)
|
val revWalk = new RevWalk(git.getRepository)
|
||||||
revWalk.markStart(revWalk.parseCommit(git.getRepository.resolve(revision)))
|
val objectId = git.getRepository.resolve(revision)
|
||||||
|
if(objectId == null){
|
||||||
|
Left(s"${revision} can't be resolved.")
|
||||||
|
} else {
|
||||||
|
revWalk.markStart(revWalk.parseCommit(objectId))
|
||||||
if(path.nonEmpty){
|
if(path.nonEmpty){
|
||||||
revWalk.setRevFilter(new RevFilter(){
|
revWalk.setRevFilter(new RevFilter(){
|
||||||
def include(walk: RevWalk, commit: RevCommit): Boolean = {
|
def include(walk: RevWalk, commit: RevCommit): Boolean = {
|
||||||
@@ -280,7 +284,8 @@ object JGitUtil {
|
|||||||
val commits = getCommitLog(revWalk.iterator, 0, Nil)
|
val commits = getCommitLog(revWalk.iterator, 0, Nil)
|
||||||
revWalk.release
|
revWalk.release
|
||||||
|
|
||||||
commits
|
Right(commits)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user