mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
Like GitHub, show a shortcut path of the directory whoes ancestors have only one child directory.
This commit is contained in:
@@ -4,6 +4,7 @@ import org.eclipse.jgit.api.Git
|
|||||||
import util.Directory._
|
import util.Directory._
|
||||||
import util.StringUtil._
|
import util.StringUtil._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
|
import scala.annotation.tailrec
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import org.eclipse.jgit.lib._
|
import org.eclipse.jgit.lib._
|
||||||
import org.eclipse.jgit.revwalk._
|
import org.eclipse.jgit.revwalk._
|
||||||
@@ -190,38 +191,23 @@ object JGitUtil {
|
|||||||
* @return HTML of the file list
|
* @return HTML of the file list
|
||||||
*/
|
*/
|
||||||
def getFileList(git: Git, revision: String, path: String = "."): List[FileInfo] = {
|
def getFileList(git: Git, revision: String, path: String = "."): List[FileInfo] = {
|
||||||
val list = new scala.collection.mutable.ListBuffer[(ObjectId, FileMode, String, String, Option[String])]
|
var list = new scala.collection.mutable.ListBuffer[(ObjectId, FileMode, String, String, Option[String])]
|
||||||
|
|
||||||
using(new RevWalk(git.getRepository)){ revWalk =>
|
using(new RevWalk(git.getRepository)){ revWalk =>
|
||||||
val objectId = git.getRepository.resolve(revision)
|
val objectId = git.getRepository.resolve(revision)
|
||||||
val revCommit = revWalk.parseCommit(objectId)
|
val revCommit = revWalk.parseCommit(objectId)
|
||||||
|
|
||||||
using(new TreeWalk(git.getRepository)){ treeWalk =>
|
val treeWalk = if (path == ".") {
|
||||||
|
val treeWalk = new TreeWalk(git.getRepository)
|
||||||
treeWalk.addTree(revCommit.getTree)
|
treeWalk.addTree(revCommit.getTree)
|
||||||
if(path != "."){
|
treeWalk
|
||||||
treeWalk.setRecursive(true)
|
|
||||||
treeWalk.setFilter(new TreeFilter(){
|
|
||||||
|
|
||||||
var stopRecursive = false
|
|
||||||
|
|
||||||
def include(walker: TreeWalk): Boolean = {
|
|
||||||
val targetPath = walker.getPathString
|
|
||||||
if((path + "/").startsWith(targetPath)){
|
|
||||||
true
|
|
||||||
} else if(targetPath.startsWith(path + "/") && targetPath.substring(path.length + 1).indexOf('/') < 0){
|
|
||||||
stopRecursive = true
|
|
||||||
treeWalk.setRecursive(false)
|
|
||||||
true
|
|
||||||
} else {
|
} else {
|
||||||
false
|
val treeWalk = TreeWalk.forPath(git.getRepository, path, revCommit.getTree)
|
||||||
}
|
treeWalk.enterSubtree()
|
||||||
|
treeWalk
|
||||||
}
|
}
|
||||||
|
|
||||||
def shouldBeRecursive(): Boolean = !stopRecursive
|
using(treeWalk) { treeWalk =>
|
||||||
|
|
||||||
override def clone: TreeFilter = return this
|
|
||||||
})
|
|
||||||
}
|
|
||||||
while (treeWalk.next()) {
|
while (treeWalk.next()) {
|
||||||
// submodule
|
// submodule
|
||||||
val linkUrl = if(treeWalk.getFileMode(0) == FileMode.GITLINK){
|
val linkUrl = if(treeWalk.getFileMode(0) == FileMode.GITLINK){
|
||||||
@@ -230,6 +216,32 @@ object JGitUtil {
|
|||||||
|
|
||||||
list.append((treeWalk.getObjectId(0), treeWalk.getFileMode(0), treeWalk.getPathString, treeWalk.getNameString, linkUrl))
|
list.append((treeWalk.getObjectId(0), treeWalk.getFileMode(0), treeWalk.getPathString, treeWalk.getNameString, linkUrl))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list = list.map(tuple =>
|
||||||
|
if (tuple._2 != FileMode.TREE)
|
||||||
|
tuple
|
||||||
|
else
|
||||||
|
simplifyPath(tuple)
|
||||||
|
)
|
||||||
|
|
||||||
|
@tailrec
|
||||||
|
def simplifyPath(tuple: (ObjectId, FileMode, String, String, Option[String])): (ObjectId, FileMode, String, String, Option[String]) = {
|
||||||
|
val walk = new TreeWalk(git.getRepository)
|
||||||
|
walk.addTree(tuple._1)
|
||||||
|
val list = new scala.collection.mutable.ListBuffer[(ObjectId, FileMode, String, String, Option[String])]
|
||||||
|
while (walk.next()) {
|
||||||
|
if (list.size > 0)
|
||||||
|
return tuple
|
||||||
|
val linkUrl = if (walk.getFileMode(0) == FileMode.GITLINK) {
|
||||||
|
getSubmodules(git, revCommit.getTree).find(_.path == walk.getPathString).map(_.url)
|
||||||
|
} else None
|
||||||
|
list.append((walk.getObjectId(0), walk.getFileMode(0), tuple._3 + "/" + walk.getPathString, tuple._4 + "/" + walk.getNameString, linkUrl))
|
||||||
|
}
|
||||||
|
if (list.size == 0 || list.exists(_._2 != FileMode.TREE))
|
||||||
|
tuple
|
||||||
|
else
|
||||||
|
simplifyPath(list(0))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,19 @@
|
|||||||
<td>
|
<td>
|
||||||
@if(file.isDirectory){
|
@if(file.isDirectory){
|
||||||
@if(file.linkUrl.isDefined){
|
@if(file.linkUrl.isDefined){
|
||||||
<a href="@file.linkUrl">@file.name</a>
|
<a href="@file.linkUrl">
|
||||||
|
<span class="simplified-path">@file.name.split("/").toList.init match {
|
||||||
|
case Nil => {}
|
||||||
|
case list => {@list.mkString("", "/", "/")}
|
||||||
|
}</span>@file.name.split("/").toList.last
|
||||||
|
</a>
|
||||||
} else {
|
} else {
|
||||||
<a href="@url(repository)/tree@{(encodeRefName(branch) :: pathList).mkString("/", "/", "/")}@file.name">@file.name</a>
|
<a href="@url(repository)/tree@{(encodeRefName(branch) :: pathList).mkString("/", "/", "/")}@file.name">
|
||||||
|
<span class="simplified-path">@file.name.split("/").toList.init match {
|
||||||
|
case Nil => {}
|
||||||
|
case list => {@list.mkString("", "/", "/")}
|
||||||
|
}</span>@file.name.split("/").toList.last
|
||||||
|
</a>
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
<a href="@url(repository)/blob@{(encodeRefName(branch) :: pathList).mkString("/", "/", "/")}@file.name">@file.name</a>
|
<a href="@url(repository)/blob@{(encodeRefName(branch) :: pathList).mkString("/", "/", "/")}@file.name">@file.name</a>
|
||||||
|
|||||||
@@ -608,6 +608,10 @@ li.highlight {
|
|||||||
background-color: #ffb;
|
background-color: #ffb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.simplified-path {
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* Issues */
|
/* Issues */
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user