mirror of
				https://github.com/gitbucket/gitbucket.git
				synced 2025-10-31 10:36:05 +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(){ | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(diffs: Seq[app.DiffInfo], repository: app.RepositoryInfo, commitId: Option[String])(implicit context: app.Context) | ||||
| @(diffs: Seq[util.JGitUtil.DiffInfo], repository: util.JGitUtil.RepositoryInfo, commitId: Option[String])(implicit context: app.Context) | ||||
| @import context._ | ||||
| @import org.eclipse.jgit.diff.DiffEntry.ChangeType | ||||
| @diffs.zipWithIndex.map { case (diff, i) => | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(active: String, repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(active: String, repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import context._ | ||||
| <div class="head"> | ||||
|   <a href="@path/@repository.owner">@repository.owner</a> / <a href="@path/@repository.owner/@repository.name">@repository.name</a> | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(branch: String, repository: app.RepositoryInfo, pathList: List[String], content: app.ContentInfo, latestCommit: app.CommitInfo)(implicit context: app.Context) | ||||
| @(branch: String, repository: util.JGitUtil.RepositoryInfo, pathList: List[String], content: util.JGitUtil.ContentInfo, latestCommit: util.JGitUtil.CommitInfo)(implicit context: app.Context) | ||||
| @import context._ | ||||
| @import view.helpers | ||||
| @html.main(repository.owner+"/"+repository.name) { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(branch: String, commit: app.CommitInfo, repository: app.RepositoryInfo, diffs: Seq[app.DiffInfo])(implicit context: app.Context) | ||||
| @(branch: String, commit: util.JGitUtil.CommitInfo, repository: util.JGitUtil.RepositoryInfo, diffs: Seq[util.JGitUtil.DiffInfo])(implicit context: app.Context) | ||||
| @import context._ | ||||
| @import view.helpers | ||||
| @import org.eclipse.jgit.diff.DiffEntry.ChangeType | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(pathList: List[String], branch: String, repository: app.RepositoryInfo, commits: Seq[Seq[app.CommitInfo]], page: Int, hasNext: Boolean)(implicit context: app.Context) | ||||
| @(pathList: List[String], branch: String, repository: util.JGitUtil.RepositoryInfo, commits: Seq[Seq[util.JGitUtil.CommitInfo]], page: Int, hasNext: Boolean)(implicit context: app.Context) | ||||
| @import context._ | ||||
| @import view.helpers | ||||
| @html.main(repository.owner+"/"+repository.name) { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(branch: String, repository: app.RepositoryInfo, pathList: List[String], latestCommit: app.CommitInfo, files: List[app.FileInfo], readme: Option[String])(implicit context: app.Context) | ||||
| @(branch: String, repository: util.JGitUtil.RepositoryInfo, pathList: List[String], latestCommit: util.JGitUtil.CommitInfo, files: List[util.JGitUtil.FileInfo], readme: Option[String])(implicit context: app.Context) | ||||
| @import context._ | ||||
| @import view.helpers | ||||
| @html.main(repository.owner + "/" + repository.name) { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(id: String, repository: app.RepositoryInfo, active: String)(implicit context: app.Context) | ||||
| @(id: String, repository: util.JGitUtil.RepositoryInfo, active: String)(implicit context: app.Context) | ||||
| @import context._ | ||||
| <ul class="nav nav-tabs"> | ||||
|   <li> | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import context._ | ||||
| @import view.helpers | ||||
| @html.main(repository.owner + "/" + repository.name) { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import context._ | ||||
| @html.main("Settings"){ | ||||
|   @html.header("settings", repository) | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(active: String, repository: app.RepositoryInfo)(body: Html)(implicit context: app.Context) | ||||
| @(active: String, repository: util.JGitUtil.RepositoryInfo)(body: Html)(implicit context: app.Context) | ||||
| @import context._ | ||||
| <div class="row-fluid"> | ||||
|   <div class="span3"> | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import context._ | ||||
| @html.main("Settings"){ | ||||
|   @html.header("settings", repository) | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(pageName: String, page: service.WikiService.WikiPageInfo, repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(pageName: String, page: service.WikiService.WikiPageInfo, repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import view.helpers | ||||
| @import context._ | ||||
| @html.main(pageName + " - " + repository.owner + "/" + repository.name){ | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(pageName: Option[String], diffs: Seq[app.DiffInfo], repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(pageName: Option[String], diffs: Seq[util.JGitUtil.DiffInfo], repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import view.helpers | ||||
| @import context._ | ||||
| @import org.eclipse.jgit.diff.DiffEntry.ChangeType | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(pageName: String, page: Option[service.WikiService.WikiPageInfo], repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(pageName: String, page: Option[service.WikiService.WikiPageInfo], repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import view.helpers | ||||
| @import context._ | ||||
| @html.main((if(pageName == "") "New Page" else pageName) + " - " + repository.owner + "/" + repository.name){ | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(pageName: Option[String], commits: List[app.CommitInfo], repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(pageName: Option[String], commits: List[util.JGitUtil.CommitInfo], repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import view.helpers | ||||
| @import context._ | ||||
| @html.main("History - " + repository.owner + "/" + repository.name){ | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(pages: List[String], repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(pages: List[String], repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import view.helpers | ||||
| @import context._ | ||||
| @html.main("Pages - " + repository.owner + "/" + repository.name){ | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| @(active: String, repository: app.RepositoryInfo)(implicit context: app.Context) | ||||
| @(active: String, repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) | ||||
| @import context._ | ||||
| <ul class="nav nav-tabs"> | ||||
|   <li@if(active == "home"){ class="active"}><a href="@path/@repository.owner/@repository.name/wiki">Home</a></li> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user