All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.koshinuke.jgit.GGitUtil.groovy Maven / Gradle / Ivy

There is a newer version: 0.1.0
Show newest version
package org.koshinuke.jgit

import javax.annotation.Nonnull

import org.eclipse.jgit.api.Git
import org.eclipse.jgit.dircache.DirCache
import org.eclipse.jgit.lib.Repository

/**
 * @author taichi
 */
class GGitUtil {

	def static handle(@Nonnull Git git, Closure closure) {
		Objects.requireNonNull(git)
		handle(git.getRepository(), closure)
	}

	def static handle(@Nonnull Repository repo, Closure closure) {
		Objects.requireNonNull(repo)
		try {
			closure(repo)
		} finally {
			repo.close()
		}
	}

	def static lockDirCache(@Nonnull Repository repo, Closure closure) {
		Objects.requireNonNull(repo)
		DirCache dc = null
		try {
			dc = repo.lockDirCache()
			closure(dc)
		} finally {
			if(dc != null) {
				dc.unlock()
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy