mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 23:15:49 +01:00
use FileUtil.withTmpDir and FileUtil.using
This commit is contained in:
@@ -9,7 +9,6 @@ import org.eclipse.jgit.api.Git
|
|||||||
import org.apache.commons.io._
|
import org.apache.commons.io._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.eclipse.jgit.lib.PersonIdent
|
import org.eclipse.jgit.lib.PersonIdent
|
||||||
import scala.Some
|
|
||||||
|
|
||||||
class CreateRepositoryController extends CreateRepositoryControllerBase
|
class CreateRepositoryController extends CreateRepositoryControllerBase
|
||||||
with RepositoryService with AccountService with WikiService with LabelsService with ActivityService
|
with RepositoryService with AccountService with WikiService with LabelsService with ActivityService
|
||||||
@@ -74,8 +73,7 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
|||||||
JGitUtil.initRepository(gitdir)
|
JGitUtil.initRepository(gitdir)
|
||||||
|
|
||||||
if(form.createReadme){
|
if(form.createReadme){
|
||||||
val tmpdir = getInitRepositoryDir(form.owner, form.name)
|
FileUtil.withTmpDir(getInitRepositoryDir(form.owner, form.name)){ tmpdir =>
|
||||||
try {
|
|
||||||
// Clone the repository
|
// Clone the repository
|
||||||
Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call
|
Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call
|
||||||
|
|
||||||
@@ -97,9 +95,6 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
|||||||
.setCommitter(new PersonIdent(loginUserName, loginAccount.mailAddress))
|
.setCommitter(new PersonIdent(loginUserName, loginAccount.mailAddress))
|
||||||
.setMessage("Initial commit").call
|
.setMessage("Initial commit").call
|
||||||
git.push.call
|
git.push.call
|
||||||
|
|
||||||
} finally {
|
|
||||||
FileUtils.deleteDirectory(tmpdir)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import util.{LockUtil, CollaboratorsAuthenticator, JGitUtil, ReferrerAuthenticat
|
|||||||
import util.Directory._
|
import util.Directory._
|
||||||
import util.Implicits._
|
import util.Implicits._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
|
import util.FileUtil._
|
||||||
import service._
|
import service._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
@@ -15,7 +16,6 @@ import org.eclipse.jgit.api.MergeCommand.FastForwardMode
|
|||||||
import service.IssuesService._
|
import service.IssuesService._
|
||||||
import service.PullRequestService._
|
import service.PullRequestService._
|
||||||
import util.JGitUtil.DiffInfo
|
import util.JGitUtil.DiffInfo
|
||||||
import scala.Some
|
|
||||||
import service.RepositoryService.RepositoryTreeNode
|
import service.RepositoryService.RepositoryTreeNode
|
||||||
import util.JGitUtil.CommitInfo
|
import util.JGitUtil.CommitInfo
|
||||||
|
|
||||||
@@ -99,10 +99,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
LockUtil.lock(s"${owner}/${name}/merge"){
|
LockUtil.lock(s"${owner}/${name}/merge"){
|
||||||
getPullRequest(owner, name, issueId).map { case (issue, pullreq) =>
|
getPullRequest(owner, name, issueId).map { case (issue, pullreq) =>
|
||||||
val remote = getRepositoryDir(owner, name)
|
val remote = getRepositoryDir(owner, name)
|
||||||
val tmpdir = new java.io.File(getTemporaryDir(owner, name), s"merge-${issueId}")
|
withTmpDir(new java.io.File(getTemporaryDir(owner, name), s"merge-${issueId}")){ tmpdir =>
|
||||||
val git = Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(pullreq.branch).call
|
using(Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(pullreq.branch).call){ git =>
|
||||||
|
|
||||||
try {
|
|
||||||
// mark issue as merged and close.
|
// mark issue as merged and close.
|
||||||
val loginAccount = context.loginAccount.get
|
val loginAccount = context.loginAccount.get
|
||||||
createComment(owner, name, loginAccount.userName, issueId, form.message, "merge")
|
createComment(owner, name, loginAccount.userName, issueId, form.message, "merge")
|
||||||
@@ -159,10 +158,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
redirect(s"/${owner}/${name}/pull/${issueId}")
|
redirect(s"/${owner}/${name}/pull/${issueId}")
|
||||||
|
}
|
||||||
} finally {
|
|
||||||
git.getRepository.close
|
|
||||||
FileUtils.deleteDirectory(tmpdir)
|
|
||||||
}
|
}
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
@@ -316,13 +312,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
// TODO Are there more quick way?
|
// TODO Are there more quick way?
|
||||||
LockUtil.lock(s"${userName}/${repositoryName}/merge-check"){
|
LockUtil.lock(s"${userName}/${repositoryName}/merge-check"){
|
||||||
val remote = getRepositoryDir(userName, repositoryName)
|
val remote = getRepositoryDir(userName, repositoryName)
|
||||||
val tmpdir = new java.io.File(getTemporaryDir(userName, repositoryName), "merge-check")
|
withTmpDir(new java.io.File(getTemporaryDir(userName, repositoryName), "merge-check")){ tmpdir =>
|
||||||
if(tmpdir.exists()){
|
using(Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(branch).call){ git =>
|
||||||
FileUtils.deleteDirectory(tmpdir)
|
|
||||||
}
|
|
||||||
|
|
||||||
val git = Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(branch).call
|
|
||||||
try {
|
|
||||||
git.checkout.setName(branch).call
|
git.checkout.setName(branch).call
|
||||||
|
|
||||||
git.fetch
|
git.fetch
|
||||||
@@ -334,10 +326,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
.setCommit(false).call
|
.setCommit(false).call
|
||||||
|
|
||||||
result.getConflicts != null
|
result.getConflicts != null
|
||||||
|
}
|
||||||
} finally {
|
|
||||||
git.getRepository.close
|
|
||||||
FileUtils.deleteDirectory(tmpdir)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user