Skip to content
Permalink
Browse files

[FIXED JENKINS-12188] close JGit repository

  • Loading branch information...
ndeloof committed Feb 28, 2013
1 parent cda843e commit e86d5eb48c9ddd6235e86bc52010207a8eed203f
@@ -4,6 +4,7 @@
import hudson.model.TaskListener;
import hudson.plugins.git.*;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteConfig;
import org.kohsuke.stapler.DataBoundConstructor;

@@ -218,7 +219,12 @@ private Revision objectId2Revision(String singleBranch, ObjectId sha1) {

// 5. sort them by the date of commit, old to new
// this ensures the fairness in scheduling.
Collections.sort(revs,new CommitTimeComparator(utils.git.getRepository()));
Repository repository = utils.git.getRepository();
try {
Collections.sort(revs,new CommitTimeComparator(repository));
} finally {
repository.close();
}

return revs;
}
@@ -10,6 +10,7 @@
import hudson.plugins.git.Revision;
import hudson.slaves.NodeProperty;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.jenkinsci.plugins.gitclient.GitClient;
@@ -102,13 +103,15 @@ public Revision getRevisionForSHA1(ObjectId sha1) throws GitException, IOExcepti
ObjectId shaJ;
ObjectId commonAncestor;
RevWalk walk = null;
Repository repository = null;
final long start = System.currentTimeMillis();
long calls = 0;
if (log)
LOGGER.fine(MessageFormat.format(
"Computing merge base of {0} branches", l.size()));
try {
walk = new RevWalk(git.getRepository());
repository = git.getRepository();
walk = new RevWalk(repository);
walk.setRetainBody(false);
walk.setRevFilter(RevFilter.MERGE_BASE);
for (int i = 0; i < l.size(); i++)
@@ -145,8 +148,8 @@ public Revision getRevisionForSHA1(ObjectId sha1) throws GitException, IOExcepti
} catch (IOException e) {
throw new GitException("Error computing merge base", e);
} finally {
if (walk != null)
walk.release();
if (walk != null) walk.release();
if (repository != null) repository.close();
}
if (log)
LOGGER.fine(MessageFormat.format(
@@ -3,6 +3,7 @@
import hudson.Extension;
import hudson.model.TaskListener;
import hudson.plugins.git.*;
import org.eclipse.jgit.lib.Repository;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
@@ -88,7 +89,12 @@ public InverseBuildChooser() {
}

// Sort revisions by the date of commit, old to new, to ensure fairness in scheduling
Collections.sort(branchRevs, new CommitTimeComparator(utils.git.getRepository()));
Repository repository = utils.git.getRepository();
try {
Collections.sort(branchRevs, new CommitTimeComparator(repository));
} finally {
repository.close();
}
return branchRevs;
}

0 comments on commit e86d5eb

Please sign in to comment.
You can’t perform that action at this time.