@@ -16,13 +16,13 @@ import gitbucket.core.view.helpers._
1616import gitbucket .gist .model .{GistUser , Gist }
1717import gitbucket .gist .service .GistService
1818import gitbucket .gist .util ._
19+ import gitbucket .gist .util .GistUtils ._
1920import gitbucket .gist .util .Configurations ._
2021import gitbucket .gist .html
2122
2223import org .apache .commons .io .FileUtils
2324import org .eclipse .jgit .api .Git
2425import org .eclipse .jgit .lib ._
25- import org .eclipse .jgit .dircache .DirCache
2626
2727class GistController extends GistControllerBase with GistService with AccountService
2828 with GistEditorAuthenticator with UsersAuthenticator
@@ -205,7 +205,7 @@ trait GistControllerBase extends ControllerBase {
205205 }
206206 }
207207 val gist = getGist(userName, repoName).get
208- html.revisions(" revision" , gist, repositoryUrl(gist), isEditable(userName), commits)
208+ html.revisions(" revision" , gist, repositoryUrl(gist, baseUrl ), isEditable(userName), commits)
209209 }
210210 case Left (_) => NotFound
211211 }
@@ -317,22 +317,14 @@ trait GistControllerBase extends ControllerBase {
317317 val files : Seq [(String , String )] = JGitUtil .getFileList(git, revision, " ." ).map { file =>
318318 file.name -> StringUtil .convertFromByteArray(JGitUtil .getContentFromId(git, file.id, true ).get)
319319 }
320- html.detail(" code" , gist, repositoryUrl(gist), revision, files, isEditable(userName))
320+ html.detail(" code" , gist, repositoryUrl(gist, baseUrl ), revision, files, isEditable(userName))
321321 } else Unauthorized
322322 }
323323 } else NotFound
324324 }
325325 }
326326 }
327327
328- private def repositoryUrl (gist : Gist ) = s " ${baseUrl}/git/gist/ ${gist.userName}/ ${gist.repositoryName}.git "
329-
330- private def isEditable (userName : String ): Boolean = {
331- context.loginAccount.map { loginAccount =>
332- loginAccount.isAdmin || loginAccount.userName == userName
333- }.getOrElse(false )
334- }
335-
336328 private def getFileParameters (flatten : Boolean ): Seq [(String , String )] = {
337329 val count = params(" count" ).toInt
338330 if (flatten){
@@ -351,28 +343,4 @@ trait GistControllerBase extends ControllerBase {
351343 }
352344 }
353345
354- private def commitFiles (git : Git , loginAccount : Account , message : String , files : Seq [(String , String )]): ObjectId = {
355- val builder = DirCache .newInCore.builder()
356- val inserter = git.getRepository.newObjectInserter()
357- val headId = git.getRepository.resolve(Constants .HEAD + " ^{commit}" )
358-
359- files.foreach { case (fileName, content) =>
360- builder.add(JGitUtil .createDirCacheEntry(fileName, FileMode .REGULAR_FILE ,
361- inserter.insert(Constants .OBJ_BLOB , content.getBytes(" UTF-8" ))))
362- }
363- builder.finish()
364-
365- val commitId = JGitUtil .createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),
366- Constants .HEAD , loginAccount.fullName, loginAccount.mailAddress, message)
367-
368- inserter.flush()
369- inserter.release()
370-
371- commitId
372- }
373-
374- private def isGistFile (fileName : String ): Boolean = fileName.matches(" gistfile[0-9]+\\ .txt" )
375-
376- private def getTitle (fileName : String , repoName : String ): String = if (isGistFile(fileName)) repoName else fileName
377-
378346}
0 commit comments