mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 23:15:49 +01:00
Use ControlUtil.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package util
|
||||
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.revwalk.DepthWalk.RevWalk
|
||||
import org.eclipse.jgit.revwalk.RevWalk
|
||||
import org.eclipse.jgit.treewalk.TreeWalk
|
||||
|
||||
/**
|
||||
* Provides control facilities.
|
||||
@@ -11,9 +12,7 @@ object ControlUtil {
|
||||
def defining[A, B](value: A)(f: A => B): B = f(value)
|
||||
|
||||
def using[A <% { def close(): Unit }, B](resource: A)(f: A => B): B =
|
||||
try {
|
||||
f(resource)
|
||||
} finally {
|
||||
try f(resource) finally {
|
||||
if(resource != null){
|
||||
try {
|
||||
resource.close()
|
||||
@@ -24,31 +23,26 @@ object ControlUtil {
|
||||
}
|
||||
|
||||
def using[T](git: Git)(f: Git => T): T =
|
||||
try {
|
||||
f(git)
|
||||
} finally {
|
||||
git.getRepository.close
|
||||
try f(git) finally git.getRepository.close
|
||||
|
||||
def using[T](git1: Git, git2: Git)(f: (Git, Git) => T): T =
|
||||
try f(git1, git2) finally {
|
||||
git1.getRepository.close
|
||||
git2.getRepository.close
|
||||
}
|
||||
|
||||
def using[T](revWalk: RevWalk)(f: RevWalk => T): T =
|
||||
try {
|
||||
f(revWalk)
|
||||
} finally {
|
||||
revWalk.release()
|
||||
}
|
||||
try f(revWalk) finally revWalk.release()
|
||||
|
||||
def using[T](treeWalk: TreeWalk)(f: TreeWalk => T): T =
|
||||
try f(treeWalk) finally treeWalk.release()
|
||||
|
||||
def executeIf(condition: => Boolean)(action: => Unit): Boolean =
|
||||
if(condition){
|
||||
action
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else false
|
||||
|
||||
def optionIf[T](condition: => Boolean)(action: => Option[T]): Option[T] =
|
||||
if(condition){
|
||||
action
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if(condition) action else None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user