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.model.TaskListener;
import hudson.plugins.git.*; import hudson.plugins.git.*;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteConfig;
import org.kohsuke.stapler.DataBoundConstructor; 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 // 5. sort them by the date of commit, old to new
// this ensures the fairness in scheduling. // 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; 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.plugins.git.Revision;
import hudson.slaves.NodeProperty; import hudson.slaves.NodeProperty;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter; import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.jenkinsci.plugins.gitclient.GitClient; import org.jenkinsci.plugins.gitclient.GitClient;
Expand Down Expand Up @@ -102,13 +103,15 @@ public List<Revision> filterTipBranches(Collection<Revision> revisions) {
ObjectId shaJ; ObjectId shaJ;
ObjectId commonAncestor; ObjectId commonAncestor;
RevWalk walk = null; RevWalk walk = null;
Repository repository = null;
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
long calls = 0; long calls = 0;
if (log) if (log)
LOGGER.fine(MessageFormat.format( LOGGER.fine(MessageFormat.format(
"Computing merge base of {0} branches", l.size())); "Computing merge base of {0} branches", l.size()));
try { try {
walk = new RevWalk(git.getRepository()); repository = git.getRepository();
walk = new RevWalk(repository);
walk.setRetainBody(false); walk.setRetainBody(false);
walk.setRevFilter(RevFilter.MERGE_BASE); walk.setRevFilter(RevFilter.MERGE_BASE);
for (int i = 0; i < l.size(); i++) 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) { } catch (IOException e) {
throw new GitException("Error computing merge base", e); throw new GitException("Error computing merge base", e);
} finally { } finally {
if (walk != null) if (walk != null) walk.release();
walk.release(); if (repository != null) repository.close();
} }
if (log) if (log)
LOGGER.fine(MessageFormat.format( LOGGER.fine(MessageFormat.format(
Expand Down
Expand Up @@ -3,6 +3,7 @@
import hudson.Extension; import hudson.Extension;
import hudson.model.TaskListener; import hudson.model.TaskListener;
import hudson.plugins.git.*; import hudson.plugins.git.*;
import org.eclipse.jgit.lib.Repository;
import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundConstructor;


import java.io.IOException; 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 // 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; return branchRevs;
} }


Expand Down

0 comments on commit e86d5eb

Please sign in to comment.