mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-03 03:55:58 +01:00
Merge pull request #2192 from gitbucket/set-archive-entry-date
Set the commit datetime to archive entries
This commit is contained in:
@@ -945,18 +945,19 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
path: String
|
path: String
|
||||||
) = {
|
) = {
|
||||||
def archive(revision: String, archiveFormat: String, archive: ArchiveOutputStream)(
|
def archive(revision: String, archiveFormat: String, archive: ArchiveOutputStream)(
|
||||||
entryCreator: (String, Long, Int) => ArchiveEntry
|
entryCreator: (String, Long, java.util.Date, Int) => ArchiveEntry
|
||||||
): Unit = {
|
): Unit = {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val oid = git.getRepository.resolve(revision)
|
val oid = git.getRepository.resolve(revision)
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, oid)
|
val commit = JGitUtil.getRevCommitFromId(git, oid)
|
||||||
|
val date = commit.getCommitterIdent.getWhen
|
||||||
val sha1 = oid.getName()
|
val sha1 = oid.getName()
|
||||||
val repositorySuffix = (if (sha1.startsWith(revision)) sha1 else revision).replace('/', '-')
|
val repositorySuffix = (if (sha1.startsWith(revision)) sha1 else revision).replace('/', '-')
|
||||||
val pathSuffix = if (path.isEmpty) "" else '-' + path.replace('/', '-')
|
val pathSuffix = if (path.isEmpty) "" else '-' + path.replace('/', '-')
|
||||||
val baseName = repository.name + "-" + repositorySuffix + pathSuffix
|
val baseName = repository.name + "-" + repositorySuffix + pathSuffix
|
||||||
|
|
||||||
using(new TreeWalk(git.getRepository)) { treeWalk =>
|
using(new TreeWalk(git.getRepository)) { treeWalk =>
|
||||||
treeWalk.addTree(revCommit.getTree)
|
treeWalk.addTree(commit.getTree)
|
||||||
treeWalk.setRecursive(true)
|
treeWalk.setRecursive(true)
|
||||||
if (!path.isEmpty) {
|
if (!path.isEmpty) {
|
||||||
treeWalk.setFilter(PathFilter.create(path))
|
treeWalk.setFilter(PathFilter.create(path))
|
||||||
@@ -968,8 +969,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
||||||
val size = JGitUtil.getFileSize(git, repository, treeWalk)
|
val size = JGitUtil.getFileSize(git, repository, treeWalk)
|
||||||
val mode = treeWalk.getFileMode.getBits
|
val mode = treeWalk.getFileMode.getBits
|
||||||
val entry: ArchiveEntry = entryCreator(entryPath, size, mode)
|
val entry: ArchiveEntry = entryCreator(entryPath, size, date, mode)
|
||||||
JGitUtil.openFile(git, repository, revCommit.getTree, treeWalk.getPathString) { in =>
|
JGitUtil.openFile(git, repository, commit.getTree, treeWalk.getPathString) { in =>
|
||||||
archive.putArchiveEntry(entry)
|
archive.putArchiveEntry(entry)
|
||||||
IOUtils.copy(in, archive)
|
IOUtils.copy(in, archive)
|
||||||
archive.closeArchiveEntry()
|
archive.closeArchiveEntry()
|
||||||
@@ -994,10 +995,11 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
response.setBufferSize(1024 * 1024)
|
response.setBufferSize(1024 * 1024)
|
||||||
using(new ZipArchiveOutputStream(response.getOutputStream)) { zip =>
|
using(new ZipArchiveOutputStream(response.getOutputStream)) { zip =>
|
||||||
archive(revision, ".zip", zip) { (path, size, mode) =>
|
archive(revision, ".zip", zip) { (path, size, date, mode) =>
|
||||||
val entry = new ZipArchiveEntry(path)
|
val entry = new ZipArchiveEntry(path)
|
||||||
entry.setSize(size)
|
entry.setSize(size)
|
||||||
entry.setUnixMode(mode)
|
entry.setUnixMode(mode)
|
||||||
|
entry.setTime(date.getTime)
|
||||||
entry
|
entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1018,9 +1020,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
tar.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR)
|
tar.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR)
|
||||||
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU)
|
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU)
|
||||||
tar.setAddPaxHeadersForNonAsciiNames(true)
|
tar.setAddPaxHeadersForNonAsciiNames(true)
|
||||||
archive(revision, ".tar.gz", tar) { (path, size, mode) =>
|
archive(revision, ".tar.gz", tar) { (path, size, date, mode) =>
|
||||||
val entry = new TarArchiveEntry(path)
|
val entry = new TarArchiveEntry(path)
|
||||||
entry.setSize(size)
|
entry.setSize(size)
|
||||||
|
entry.setModTime(date)
|
||||||
entry.setMode(mode)
|
entry.setMode(mode)
|
||||||
entry
|
entry
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user