mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
(refs #434)Refactor to get last modified commit
This commit is contained in:
@@ -191,7 +191,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
val lastModifiedCommit = git.log.add(revCommit).addPath(path).setMaxCount(1).call.iterator.next()
|
val lastModifiedCommit = JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
if(raw){
|
if(raw){
|
||||||
// Download
|
// Download
|
||||||
@@ -315,7 +315,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
// get specified commit
|
// get specified commit
|
||||||
JGitUtil.getDefaultBranch(git, repository, revstr).map { case (objectId, revision) =>
|
JGitUtil.getDefaultBranch(git, repository, revstr).map { case (objectId, revision) =>
|
||||||
defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit =>
|
defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit =>
|
||||||
val lastModifiedCommit = if(path != ".") git.log.add(revCommit).addPath(path).setMaxCount(1).call.iterator.next else revCommit
|
val lastModifiedCommit = if(path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
||||||
// get files
|
// get files
|
||||||
val files = JGitUtil.getFileList(git, revision, path)
|
val files = JGitUtil.getFileList(git, revision, path)
|
||||||
val parentPath = if (path == ".") Nil else path.split("/").toList
|
val parentPath = if (path == ".") Nil else path.split("/").toList
|
||||||
|
|||||||
@@ -652,4 +652,15 @@ object JGitUtil {
|
|||||||
}.head.id
|
}.head.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last modified commit of specified path
|
||||||
|
* @param git the Git object
|
||||||
|
* @param startCommit the search base commit id
|
||||||
|
* @param path the path of target file or directory
|
||||||
|
* @return the last modified commit of specified path
|
||||||
|
*/
|
||||||
|
def getLastModifiedCommit(git: Git, startCommit: RevCommit, path: String): RevCommit = {
|
||||||
|
return git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user