(refs #13)File editing (add, edit and delete) in repository viewer is available.

This commit is contained in:
takezoe
2014-04-27 02:02:36 +09:00
parent 0e5591017a
commit a97edb7ef5
6 changed files with 311 additions and 153 deletions

View File

@@ -550,6 +550,26 @@ object JGitUtil {
}
}
def getContentInfo(git: Git, path: String, objectId: ObjectId): ContentInfo = {
// Viewer
val large = FileUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
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
if(viewer == "other"){
if(bytes.isDefined && FileUtil.isText(bytes.get)){
// text
ContentInfo("text", Some(StringUtil.convertFromByteArray(bytes.get)), Some(StringUtil.detectEncoding(bytes.get)))
} else {
// binary
ContentInfo("binary", None, None)
}
} else {
// image or large
ContentInfo(viewer, None, None)
}
}
/**
* Get object content of the given object id as byte array from the Git repository.
*