diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 5236123..5efcb6a 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -477,6 +477,34 @@ repository) }) + /** + * Displays the file find of branch. + */ + get("/:owner/:repository/find/:ref")(referrersOnly { repository => + using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git => + JGitUtil.getTreeId(git, params("ref")).map{ treeId => + html.find(params("ref"), + treeId, + repository, + context.loginAccount match { + case None => List() + case account: Option[Account] => getGroupsByUserName(account.get.userName) + }) + } getOrElse NotFound + } + }) + + /** + * Get all file list of branch. + */ + ajaxGet("/:owner/:repository/tree-list/:tree")(referrersOnly { repository => + using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git => + val treeId = params("tree") + contentType = formats("json") + Map("paths" -> JGitUtil.getAllFileListByTreeId(git, treeId)) + } + }) + private def splitPath(repository: RepositoryService.RepositoryInfo, path: String): (String, String) = { val id = repository.branchList.collectFirst { case branch if(path == branch || path.startsWith(branch + "/")) => branch diff --git a/src/main/scala/gitbucket/core/util/JGitUtil.scala b/src/main/scala/gitbucket/core/util/JGitUtil.scala index c373340..c2491e8 100644 --- a/src/main/scala/gitbucket/core/util/JGitUtil.scala +++ b/src/main/scala/gitbucket/core/util/JGitUtil.scala @@ -325,6 +325,39 @@ } /** + * get all file list by revision. only file. + */ + def getTreeId(git: Git, revision: String): Option[String] = { + using(new RevWalk(git.getRepository)){ revWalk => + val objectId = git.getRepository.resolve(revision) + if(objectId==null) return None + val revCommit = revWalk.parseCommit(objectId) + Some(revCommit.getTree.name) + } + } + + /** + * get all file list by tree object id. + */ + def getAllFileListByTreeId(git: Git, treeId: String): List[String] = { + using(new RevWalk(git.getRepository)){ revWalk => + val objectId = git.getRepository.resolve(treeId+"^{tree}") + if(objectId==null) return Nil + using(new TreeWalk(git.getRepository)){ treeWalk => + treeWalk.addTree(objectId) + treeWalk.setRecursive(true) + var ret: List[String] = Nil + if(treeWalk != null){ + while (treeWalk.next()) { + ret +:= treeWalk.getPathString + } + } + ret.reverse + } + } + } + + /** * Returns the commit list of the specified branch. * * @param git the Git object diff --git a/src/main/twirl/gitbucket/core/main.scala.html b/src/main/twirl/gitbucket/core/main.scala.html index 591d948..d8267f6 100644 --- a/src/main/twirl/gitbucket/core/main.scala.html +++ b/src/main/twirl/gitbucket/core/main.scala.html @@ -28,6 +28,7 @@ +