mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-14 17:35:50 +01:00
Dispose ObjectLoader certainty
This commit is contained in:
@@ -290,7 +290,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
val lastModifiedCommit = JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
if(raw){
|
if(raw){
|
||||||
// Download
|
// Download
|
||||||
@@ -298,8 +297,11 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
RawData(FileUtil.getContentType(path, bytes), bytes)
|
RawData(FileUtil.getContentType(path, bytes), bytes)
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
} else {
|
} else {
|
||||||
html.blob(id, repository, path.split("/").toList, JGitUtil.getContentInfo(git, path, objectId),
|
html.blob(id, repository, path.split("/").toList,
|
||||||
new JGitUtil.CommitInfo(lastModifiedCommit), hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
JGitUtil.getContentInfo(git, path, objectId),
|
||||||
|
new JGitUtil.CommitInfo(JGitUtil.getLastModifiedCommit(git, revCommit, path)),
|
||||||
|
hasWritePermission(repository.owner, repository.name, context.loginAccount)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -639,7 +639,9 @@ object JGitUtil {
|
|||||||
|
|
||||||
def getContentInfo(git: Git, path: String, objectId: ObjectId): ContentInfo = {
|
def getContentInfo(git: Git, path: String, objectId: ObjectId): ContentInfo = {
|
||||||
// Viewer
|
// Viewer
|
||||||
val large = FileUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
|
using(git.getRepository.getObjectDatabase){ db =>
|
||||||
|
val loader = db.open(objectId)
|
||||||
|
val large = FileUtil.isLarge(loader.getSize)
|
||||||
val viewer = if(FileUtil.isImage(path)) "image" else if(large) "large" else "other"
|
val viewer = if(FileUtil.isImage(path)) "image" else if(large) "large" else "other"
|
||||||
val bytes = if(viewer == "other") JGitUtil.getContentFromId(git, objectId, false) else None
|
val bytes = if(viewer == "other") JGitUtil.getContentFromId(git, objectId, false) else None
|
||||||
|
|
||||||
@@ -656,6 +658,7 @@ object JGitUtil {
|
|||||||
ContentInfo(viewer, None, None)
|
ContentInfo(viewer, None, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object content of the given object id as byte array from the Git repository.
|
* Get object content of the given object id as byte array from the Git repository.
|
||||||
@@ -666,12 +669,12 @@ object JGitUtil {
|
|||||||
* @return the byte array of content or None if object does not exist
|
* @return the byte array of content or None if object does not exist
|
||||||
*/
|
*/
|
||||||
def getContentFromId(git: Git, id: ObjectId, fetchLargeFile: Boolean): Option[Array[Byte]] = try {
|
def getContentFromId(git: Git, id: ObjectId, fetchLargeFile: Boolean): Option[Array[Byte]] = try {
|
||||||
val loader = git.getRepository.getObjectDatabase.open(id)
|
using(git.getRepository.getObjectDatabase){ db =>
|
||||||
|
val loader = db.open(id)
|
||||||
if(fetchLargeFile == false && FileUtil.isLarge(loader.getSize)){
|
if(fetchLargeFile == false && FileUtil.isLarge(loader.getSize)){
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
using(git.getRepository.getObjectDatabase){ db =>
|
Some(loader.getBytes)
|
||||||
Some(db.open(id).getBytes)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user