Skip to content

Commit

Permalink
[FIXED JENKINS-12188] close JGit repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof committed Feb 28, 2013
1 parent cda843e commit e86d5eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Expand Up @@ -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;

Expand Down Expand Up @@ -218,7 +219,12 @@ private List<Revision> getAdvancedCandidateRevisions(boolean isPollCall, TaskLis

// 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;
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/hudson/plugins/git/util/GitUtils.java
Expand Up @@ -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;
Expand Down Expand Up @@ -102,13 +103,15 @@ public List<Revision> filterTipBranches(Collection<Revision> revisions) {
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++)
Expand Down Expand Up @@ -145,8 +148,8 @@ public List<Revision> filterTipBranches(Collection<Revision> revisions) {
} 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(
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +89,12 @@ public Collection<Revision> getCandidateRevisions(boolean isPollCall,
}

// 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;
}

Expand Down

0 comments on commit e86d5eb

Please sign in to comment.