mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-11 16:05:49 +01:00
Fix for repository downloading improvement in #2014
This commit is contained in:
@@ -31,7 +31,6 @@ import org.eclipse.jgit.archive.{TgzFormat, ZipFormat}
|
||||
import org.eclipse.jgit.dircache.{DirCache, DirCacheBuilder}
|
||||
import org.eclipse.jgit.errors.MissingObjectException
|
||||
import org.eclipse.jgit.lib._
|
||||
import org.eclipse.jgit.revwalk.RevWalk
|
||||
import org.eclipse.jgit.transport.{ReceiveCommand, ReceivePack}
|
||||
import org.eclipse.jgit.treewalk.TreeWalk
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter
|
||||
@@ -1151,28 +1150,25 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
val repositorySuffix = (if (sha1.startsWith(revision)) sha1 else revision).replace('/', '-')
|
||||
val pathSuffix = if (path.isEmpty) "" else '-' + path.replace('/', '-')
|
||||
val baseName = repository.name + "-" + repositorySuffix + pathSuffix
|
||||
val filename = baseName + archiveFormat
|
||||
|
||||
using(new RevWalk(git.getRepository)) { revWalk =>
|
||||
using(new TreeWalk(git.getRepository)) { treeWalk =>
|
||||
treeWalk.addTree(revCommit.getTree)
|
||||
treeWalk.setRecursive(true)
|
||||
if (!path.isEmpty) {
|
||||
treeWalk.setFilter(PathFilter.create(path))
|
||||
}
|
||||
if (treeWalk != null) {
|
||||
while (treeWalk.next()) {
|
||||
val entryPath =
|
||||
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
|
||||
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
||||
val size = JGitUtil.getFileSize(git, repository, treeWalk)
|
||||
val mode = treeWalk.getFileMode.getBits
|
||||
val entry: ArchiveEntry = entryCreator(entryPath, size, mode)
|
||||
JGitUtil.openFile(git, repository, revCommit.getTree, treeWalk.getPathString) { in =>
|
||||
archive.putArchiveEntry(entry)
|
||||
IOUtils.copy(in, archive)
|
||||
archive.closeArchiveEntry()
|
||||
}
|
||||
using(new TreeWalk(git.getRepository)) { treeWalk =>
|
||||
treeWalk.addTree(revCommit.getTree)
|
||||
treeWalk.setRecursive(true)
|
||||
if (!path.isEmpty) {
|
||||
treeWalk.setFilter(PathFilter.create(path))
|
||||
}
|
||||
if (treeWalk != null) {
|
||||
while (treeWalk.next()) {
|
||||
val entryPath =
|
||||
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
|
||||
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
||||
val size = JGitUtil.getFileSize(git, repository, treeWalk)
|
||||
val mode = treeWalk.getFileMode.getBits
|
||||
val entry: ArchiveEntry = entryCreator(entryPath, size, mode)
|
||||
JGitUtil.openFile(git, repository, revCommit.getTree, treeWalk.getPathString) { in =>
|
||||
archive.putArchiveEntry(entry)
|
||||
IOUtils.copy(in, archive)
|
||||
archive.closeArchiveEntry()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1253,7 +1253,7 @@ object JGitUtil {
|
||||
f(in)
|
||||
}
|
||||
} else {
|
||||
throw new EmptyLfsAttributesException
|
||||
throw new NoSuchElementException("LFS attribute is empty.")
|
||||
}
|
||||
} else {
|
||||
using(loader.openStream()) { in =>
|
||||
@@ -1277,6 +1277,4 @@ object JGitUtil {
|
||||
JGitUtil.getLfsObjects(text)
|
||||
}
|
||||
|
||||
case class EmptyLfsAttributesException() extends Exception
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user