mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Refactoring
This commit is contained in:
@@ -37,15 +37,4 @@ object ControlUtil {
|
||||
def using[T](treeWalk: TreeWalk)(f: TreeWalk => T): T =
|
||||
try f(treeWalk) finally treeWalk.release()
|
||||
|
||||
|
||||
// def withTmpRefSpec[T](ref: RefSpec, git: Git)(f: RefSpec => T): T = {
|
||||
// try {
|
||||
// f(ref)
|
||||
// } finally {
|
||||
// val refUpdate = git.getRepository.updateRef(ref.getDestination)
|
||||
// refUpdate.setForceUpdate(true)
|
||||
// refUpdate.delete()
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -31,24 +31,6 @@ object FileUtil {
|
||||
|
||||
def isText(content: Array[Byte]): Boolean = !content.contains(0)
|
||||
|
||||
// def createZipFile(dest: File, dir: File): Unit = {
|
||||
// def addDirectoryToZip(out: ZipArchiveOutputStream, dir: File, path: String): Unit = {
|
||||
// dir.listFiles.map { file =>
|
||||
// if(file.isFile){
|
||||
// out.putArchiveEntry(new ZipArchiveEntry(path + "/" + file.getName))
|
||||
// out.write(FileUtils.readFileToByteArray(file))
|
||||
// out.closeArchiveEntry
|
||||
// } else if(file.isDirectory){
|
||||
// addDirectoryToZip(out, file, path + "/" + file.getName)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// using(new ZipArchiveOutputStream(dest)){ out =>
|
||||
// addDirectoryToZip(out, dir, dir.getName)
|
||||
// }
|
||||
// }
|
||||
|
||||
def getFileName(path: String): String = defining(path.lastIndexOf('/')){ i =>
|
||||
if(i >= 0) path.substring(i + 1) else path
|
||||
}
|
||||
|
||||
@@ -585,4 +585,17 @@ object JGitUtil {
|
||||
existIds.toSeq
|
||||
}
|
||||
|
||||
def processTree(git: Git, id: ObjectId)(f: (String, CanonicalTreeParser) => Unit) = {
|
||||
using(new RevWalk(git.getRepository)){ revWalk =>
|
||||
using(new TreeWalk(git.getRepository)){ treeWalk =>
|
||||
val index = treeWalk.addTree(revWalk.parseTree(id))
|
||||
treeWalk.setRecursive(true)
|
||||
while(treeWalk.next){
|
||||
f(treeWalk.getPathString, treeWalk.getTree(index, classOf[CanonicalTreeParser]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user