mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 06:55:54 +01:00
Move case classes in RepositoryViewerController to JGitUtil.
This commit is contained in:
@@ -3,72 +3,15 @@ package app
|
||||
import util.Directory._
|
||||
import util.Implicits._
|
||||
import util.{JGitUtil, FileTypeUtil, CompressUtil}
|
||||
import model._
|
||||
import service._
|
||||
import org.scalatra._
|
||||
import java.io.File
|
||||
import java.util.Date
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib._
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.eclipse.jgit.treewalk._
|
||||
import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
||||
|
||||
// TODO Should models move to other package?
|
||||
/**
|
||||
* The repository data.
|
||||
*
|
||||
* @param owner the user name of the repository owner
|
||||
* @param name the repository name
|
||||
* @param url the repository URL
|
||||
* @param branchList the list of branch names
|
||||
* @param tags the list of tags
|
||||
*/
|
||||
case class RepositoryInfo(owner: String, name: String, url: String, branchList: List[String], tags: List[TagInfo])
|
||||
|
||||
/**
|
||||
* The file data for the file list of the repository viewer.
|
||||
*
|
||||
* @param id the object id
|
||||
* @param isDirectory whether is it directory
|
||||
* @param name the file (or directory) name
|
||||
* @param time the last modified time
|
||||
* @param message the last commit message
|
||||
* @param committer the last committer name
|
||||
*/
|
||||
case class FileInfo(id: ObjectId, isDirectory: Boolean, name: String, time: Date, message: String, committer: String)
|
||||
|
||||
/**
|
||||
* The commit data.
|
||||
*
|
||||
* @param id the commit id
|
||||
* @param time the commit time
|
||||
* @param committer the commiter name
|
||||
* @param message the commit message
|
||||
*/
|
||||
case class CommitInfo(id: String, time: Date, committer: String, message: String){
|
||||
def this(rev: org.eclipse.jgit.revwalk.RevCommit) =
|
||||
this(rev.getName, rev.getCommitterIdent.getWhen, rev.getCommitterIdent.getName, rev.getFullMessage)
|
||||
}
|
||||
|
||||
case class DiffInfo(changeType: ChangeType, oldPath: String, newPath: String, oldContent: Option[String], newContent: Option[String])
|
||||
|
||||
/**
|
||||
* The file content data for the file content view of the repository viewer.
|
||||
*
|
||||
* @param viewType "image", "large" or "other"
|
||||
* @param content the string content
|
||||
*/
|
||||
case class ContentInfo(viewType: String, content: Option[String])
|
||||
|
||||
/**
|
||||
* The tag data.
|
||||
*
|
||||
* @param name the tag name
|
||||
* @param time the tagged date
|
||||
* @param id the commit id
|
||||
*/
|
||||
case class TagInfo(name: String, time: Date, id: String)
|
||||
|
||||
class RepositoryViewerController extends RepositoryViewerControllerBase with ProjectService with AccountService
|
||||
|
||||
@@ -191,10 +134,10 @@ trait RepositoryViewerControllerBase extends ControllerBase { self: ProjectServi
|
||||
// Viewer
|
||||
val large = FileTypeUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
|
||||
val viewer = if(FileTypeUtil.isImage(path)) "image" else if(large) "large" else "text"
|
||||
val content = ContentInfo(viewer,
|
||||
val content = JGitUtil.ContentInfo(viewer,
|
||||
if(viewer == "text") JGitUtil.getContent(git, objectId, false).map(new String(_, "UTF-8")) else None)
|
||||
|
||||
repo.html.blob(id, repositoryInfo, path.split("/").toList, content, new CommitInfo(revCommit))
|
||||
repo.html.blob(id, repositoryInfo, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,7 +152,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { self: ProjectServi
|
||||
|
||||
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||
repo.html.commit(id, new CommitInfo(revCommit),
|
||||
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
||||
JGitUtil.getRepositoryInfo(owner, repository, servletContext), JGitUtil.getDiffs(git, id))
|
||||
}
|
||||
}
|
||||
@@ -300,7 +243,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { self: ProjectServi
|
||||
// current path
|
||||
if(path == ".") Nil else path.split("/").toList,
|
||||
// latest commit
|
||||
new CommitInfo(revCommit),
|
||||
new JGitUtil.CommitInfo(revCommit),
|
||||
// file list
|
||||
files,
|
||||
// readme
|
||||
|
||||
@@ -56,5 +56,5 @@ trait ProjectService { self: AccountService =>
|
||||
}
|
||||
|
||||
object ProjectService {
|
||||
case class RepositoryInfo(owner: String, name: String, project: Project, branchList: List[String], tagInfo: List[app.TagInfo])
|
||||
case class RepositoryInfo(owner: String, name: String, project: Project, branchList: List[String], tagInfo: List[util.JGitUtil.TagInfo])
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.io.File
|
||||
import java.util.Date
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.apache.commons.io.FileUtils
|
||||
import app.DiffInfo
|
||||
import util.JGitUtil.DiffInfo
|
||||
import util.{Directory, JGitUtil}
|
||||
import org.eclipse.jgit.lib.RepositoryBuilder
|
||||
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package util
|
||||
|
||||
import org.eclipse.jgit.api.Git
|
||||
import app.{RepositoryInfo, FileInfo, CommitInfo, DiffInfo, TagInfo}
|
||||
import util.Directory._
|
||||
import scala.collection.JavaConverters._
|
||||
import javax.servlet.ServletContext
|
||||
@@ -14,12 +13,68 @@ import org.eclipse.jgit.diff._
|
||||
import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
||||
import org.eclipse.jgit.util.io.DisabledOutputStream
|
||||
import org.eclipse.jgit.errors.MissingObjectException
|
||||
import java.util.Date
|
||||
|
||||
/**
|
||||
* Provides complex JGit operations.
|
||||
*/
|
||||
object JGitUtil {
|
||||
|
||||
|
||||
/**
|
||||
* The repository data.
|
||||
*
|
||||
* @param owner the user name of the repository owner
|
||||
* @param name the repository name
|
||||
* @param url the repository URL
|
||||
* @param branchList the list of branch names
|
||||
* @param tags the list of tags
|
||||
*/
|
||||
case class RepositoryInfo(owner: String, name: String, url: String, branchList: List[String], tags: List[TagInfo])
|
||||
|
||||
/**
|
||||
* The file data for the file list of the repository viewer.
|
||||
*
|
||||
* @param id the object id
|
||||
* @param isDirectory whether is it directory
|
||||
* @param name the file (or directory) name
|
||||
* @param time the last modified time
|
||||
* @param message the last commit message
|
||||
* @param committer the last committer name
|
||||
*/
|
||||
case class FileInfo(id: ObjectId, isDirectory: Boolean, name: String, time: Date, message: String, committer: String)
|
||||
|
||||
/**
|
||||
* The commit data.
|
||||
*
|
||||
* @param id the commit id
|
||||
* @param time the commit time
|
||||
* @param committer the commiter name
|
||||
* @param message the commit message
|
||||
*/
|
||||
case class CommitInfo(id: String, time: Date, committer: String, message: String){
|
||||
def this(rev: org.eclipse.jgit.revwalk.RevCommit) =
|
||||
this(rev.getName, rev.getCommitterIdent.getWhen, rev.getCommitterIdent.getName, rev.getFullMessage)
|
||||
}
|
||||
|
||||
case class DiffInfo(changeType: ChangeType, oldPath: String, newPath: String, oldContent: Option[String], newContent: Option[String])
|
||||
|
||||
/**
|
||||
* The file content data for the file content view of the repository viewer.
|
||||
*
|
||||
* @param viewType "image", "large" or "other"
|
||||
* @param content the string content
|
||||
*/
|
||||
case class ContentInfo(viewType: String, content: Option[String])
|
||||
|
||||
/**
|
||||
* The tag data.
|
||||
*
|
||||
* @param name the tag name
|
||||
* @param time the tagged date
|
||||
* @param id the commit id
|
||||
*/
|
||||
case class TagInfo(name: String, time: Date, id: String)
|
||||
|
||||
/**
|
||||
* Use this method to use the Git object.
|
||||
* Repository resources are released certainly after processing.
|
||||
|
||||
@@ -25,7 +25,7 @@ object helpers {
|
||||
/**
|
||||
* Converts the issue number and the commit id to the link.
|
||||
*/
|
||||
private def markdownFilter(value: String, repository: app.RepositoryInfo)(implicit context: app.Context): String = {
|
||||
private def markdownFilter(value: String, repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context): String = {
|
||||
value
|
||||
.replaceAll("#([0-9]+)", "[$0](%s/%s/%s/issue/$1)".format(context.path, repository.owner, repository.name))
|
||||
.replaceAll("[0-9a-z]{10,40}", "[$0](%s/%s/%s/commit/$0)".format(context.path, repository.owner, repository.name))
|
||||
@@ -34,7 +34,7 @@ object helpers {
|
||||
/**
|
||||
* Converts Markdown of Wiki pages to HTML.
|
||||
*/
|
||||
def markdown(value: String, repository: app.RepositoryInfo, wikiLink: Boolean)(implicit context: app.Context): twirl.api.Html = {
|
||||
def markdown(value: String, repository: util.JGitUtil.RepositoryInfo, wikiLink: Boolean)(implicit context: app.Context): twirl.api.Html = {
|
||||
import org.pegdown._
|
||||
val html = new PegDownProcessor(Extensions.AUTOLINKS|Extensions.WIKILINKS|Extensions.FENCED_CODE_BLOCKS)
|
||||
.markdownToHtml(markdownFilter(value, repository), new LinkRenderer(){
|
||||
|
||||
Reference in New Issue
Block a user