Use ControlUtil#using() to handle RevWalk.

This commit is contained in:
takezoe
2013-09-21 22:21:59 +09:00
parent e89b2020a3
commit c00b704843
2 changed files with 69 additions and 82 deletions

View File

@@ -1,6 +1,7 @@
package util
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.revwalk.DepthWalk.RevWalk
/**
* Provides control facilities.
@@ -22,10 +23,6 @@ object ControlUtil {
}
}
/**
* Use this method to use the Git object.
* Repository resources are released certainly after processing.
*/
def using[T](git: Git)(f: Git => T): T =
try {
f(git)
@@ -33,6 +30,13 @@ object ControlUtil {
git.getRepository.close
}
def using[T](revWalk: RevWalk)(f: RevWalk => T): T =
try {
f(revWalk)
} finally {
revWalk.release()
}
def executeIf(condition: => Boolean)(action: => Unit): Boolean =
if(condition){
action