mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Remove some functions from ControlUtil.
This commit is contained in:
@@ -338,12 +338,12 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
using(Git.open(getRepositoryDir(requestUserName, requestRepositoryName))) { git =>
|
using(Git.open(getRepositoryDir(requestUserName, requestRepositoryName))) { git =>
|
||||||
val remoteRefName = s"refs/heads/${branch}"
|
val remoteRefName = s"refs/heads/${branch}"
|
||||||
val tmpRefName = s"refs/merge-check/${userName}/${branch}"
|
val tmpRefName = s"refs/merge-check/${userName}/${branch}"
|
||||||
|
val refSpec = new RefSpec(s"${remoteRefName}:${tmpRefName}").setForceUpdate(true)
|
||||||
withTmpRefSpec(new RefSpec(s"${remoteRefName}:${tmpRefName}").setForceUpdate(true), git) { ref =>
|
try {
|
||||||
// fetch objects from origin repository branch
|
// fetch objects from origin repository branch
|
||||||
git.fetch
|
git.fetch
|
||||||
.setRemote(getRepositoryDir(userName, repositoryName).toURI.toString)
|
.setRemote(getRepositoryDir(userName, repositoryName).toURI.toString)
|
||||||
.setRefSpecs(ref)
|
.setRefSpecs(refSpec)
|
||||||
.call
|
.call
|
||||||
|
|
||||||
// merge conflict check
|
// merge conflict check
|
||||||
@@ -355,6 +355,10 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
} catch {
|
} catch {
|
||||||
case e: NoMergeBaseException => true
|
case e: NoMergeBaseException => true
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
val refUpdate = git.getRepository.updateRef(refSpec.getDestination)
|
||||||
|
refUpdate.setForceUpdate(true)
|
||||||
|
refUpdate.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,16 +188,16 @@ trait WikiControllerBase extends ControllerBase with FlashMapSupport {
|
|||||||
|
|
||||||
private def conflictForNew: Constraint = new Constraint(){
|
private def conflictForNew: Constraint = new Constraint(){
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
optionIf(targetWikiPage.nonEmpty){
|
targetWikiPage.map { _ =>
|
||||||
Some("Someone has created the wiki since you started. Please reload this page and re-apply your changes.")
|
"Someone has created the wiki since you started. Please reload this page and re-apply your changes."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def conflictForEdit: Constraint = new Constraint(){
|
private def conflictForEdit: Constraint = new Constraint(){
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
optionIf(targetWikiPage.map(_.id != params("id")).getOrElse(false)){
|
targetWikiPage.filter(_.id != params("id")).map{ _ =>
|
||||||
Some("Someone has edited the wiki since you started. Please reload this page and re-apply your changes.")
|
"Someone has edited the wiki since you started. Please reload this page and re-apply your changes."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ trait WikiService {
|
|||||||
*/
|
*/
|
||||||
def getWikiPage(owner: String, repository: String, pageName: String): Option[WikiPageInfo] = {
|
def getWikiPage(owner: String, repository: String, pageName: String): Option[WikiPageInfo] = {
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
optionIf(!JGitUtil.isEmpty(git)){
|
if(!JGitUtil.isEmpty(git)){
|
||||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
||||||
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"), file.committer, file.time, file.commitId)
|
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"), file.committer, file.time, file.commitId)
|
||||||
}
|
}
|
||||||
}
|
} else None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ trait WikiService {
|
|||||||
*/
|
*/
|
||||||
def getFileContent(owner: String, repository: String, path: String): Option[Array[Byte]] =
|
def getFileContent(owner: String, repository: String, path: String): Option[Array[Byte]] =
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
optionIf(!JGitUtil.isEmpty(git)){
|
if(!JGitUtil.isEmpty(git)){
|
||||||
val index = path.lastIndexOf('/')
|
val index = path.lastIndexOf('/')
|
||||||
val parentPath = if(index < 0) "." else path.substring(0, index)
|
val parentPath = if(index < 0) "." else path.substring(0, index)
|
||||||
val fileName = if(index < 0) path else path.substring(index + 1)
|
val fileName = if(index < 0) path else path.substring(index + 1)
|
||||||
@@ -80,7 +80,7 @@ trait WikiService {
|
|||||||
JGitUtil.getFileList(git, "master", parentPath).find(_.name == fileName).map { file =>
|
JGitUtil.getFileList(git, "master", parentPath).find(_.name == fileName).map { file =>
|
||||||
git.getRepository.open(file.id).getBytes
|
git.getRepository.open(file.id).getBytes
|
||||||
}
|
}
|
||||||
}
|
} else None
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,7 +239,7 @@ trait WikiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
optionIf(created || updated || removed){
|
if(created || updated || removed){
|
||||||
builder.add(JGitUtil.createDirCacheEntry(newPageName + ".md", FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
|
builder.add(JGitUtil.createDirCacheEntry(newPageName + ".md", FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
|
||||||
builder.finish()
|
builder.finish()
|
||||||
val newHeadId = JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
val newHeadId = JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
||||||
@@ -256,7 +256,7 @@ trait WikiService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Some(newHeadId)
|
Some(newHeadId)
|
||||||
}
|
} else None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,17 +97,17 @@ class CommitLogHook(owner: String, repository: String, userName: String, baseURL
|
|||||||
val newCommits = if(commits.size > 1000){
|
val newCommits = if(commits.size > 1000){
|
||||||
val existIds = getAllCommitIds(owner, repository)
|
val existIds = getAllCommitIds(owner, repository)
|
||||||
commits.flatMap { commit =>
|
commits.flatMap { commit =>
|
||||||
optionIf(!existIds.contains(commit.id)){
|
if(!existIds.contains(commit.id)){
|
||||||
createIssueComment(commit)
|
createIssueComment(commit)
|
||||||
Some(commit)
|
Some(commit)
|
||||||
}
|
} else None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
commits.flatMap { commit =>
|
commits.flatMap { commit =>
|
||||||
optionIf(!existsCommitId(owner, repository, commit.id)){
|
if(!existsCommitId(owner, repository, commit.id)){
|
||||||
createIssueComment(commit)
|
createIssueComment(commit)
|
||||||
Some(commit)
|
Some(commit)
|
||||||
}
|
} else None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,22 +40,14 @@ object ControlUtil {
|
|||||||
try f(treeWalk) finally treeWalk.release()
|
try f(treeWalk) finally treeWalk.release()
|
||||||
|
|
||||||
|
|
||||||
def withTmpRefSpec[T](ref: RefSpec, git: Git)(f: RefSpec => T): T = {
|
// def withTmpRefSpec[T](ref: RefSpec, git: Git)(f: RefSpec => T): T = {
|
||||||
try {
|
// try {
|
||||||
f(ref)
|
// f(ref)
|
||||||
} finally {
|
// } finally {
|
||||||
val refUpdate = git.getRepository.updateRef(ref.getDestination)
|
// val refUpdate = git.getRepository.updateRef(ref.getDestination)
|
||||||
refUpdate.setForceUpdate(true)
|
// refUpdate.setForceUpdate(true)
|
||||||
refUpdate.delete()
|
// refUpdate.delete()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
def executeIf(condition: => Boolean)(action: => Unit): Boolean =
|
|
||||||
if(condition){
|
|
||||||
action
|
|
||||||
true
|
|
||||||
} else false
|
|
||||||
|
|
||||||
def optionIf[T](condition: => Boolean)(action: => Option[T]): Option[T] =
|
|
||||||
if(condition) action else None
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ object JGitUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val description = defining(fullMessage.trim.indexOf("\n")){ i =>
|
val description = defining(fullMessage.trim.indexOf("\n")){ i =>
|
||||||
optionIf(i >= 0){
|
if(i >= 0){
|
||||||
Some(fullMessage.trim.substring(i).trim)
|
Some(fullMessage.trim.substring(i).trim)
|
||||||
}
|
} else None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ object LDAPUtil {
|
|||||||
|
|
||||||
private def findMailAddress(conn: LDAPConnection, userDN: String, mailAttribute: String): Option[String] =
|
private def findMailAddress(conn: LDAPConnection, userDN: String, mailAttribute: String): Option[String] =
|
||||||
defining(conn.search(userDN, LDAPConnection.SCOPE_BASE, null, Array[String](mailAttribute), false)){ results =>
|
defining(conn.search(userDN, LDAPConnection.SCOPE_BASE, null, Array[String](mailAttribute), false)){ results =>
|
||||||
optionIf (results.hasMore) {
|
if(results.hasMore) {
|
||||||
Option(results.next.getAttribute(mailAttribute)).map(_.getStringValue)
|
Option(results.next.getAttribute(mailAttribute)).map(_.getStringValue)
|
||||||
}
|
} else None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user