Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2015-05-26 11:21:08 +0000
committerMatthias Sohn2015-05-26 11:21:08 +0000
commita08c9bd885d553a459ec896de14b8552d7e16f9a (patch)
treed4d773936424928222a5394a0a57801b3230278c /org.eclipse.mylyn.github.ui/src/org/eclipse
parente0c90f002d5756406ee8f0311899f7b87b4144ed (diff)
downloadegit-github-a08c9bd885d553a459ec896de14b8552d7e16f9a.tar.gz
egit-github-a08c9bd885d553a459ec896de14b8552d7e16f9a.tar.xz
egit-github-a08c9bd885d553a459ec896de14b8552d7e16f9a.zip
Use try-with-resource to close JGit walks
JGit now supports AutoClosable on walks and no longer supports the old release() method. Change-Id: I82e1a788ad212ac067dd45d1bdf959feaf991174 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.mylyn.github.ui/src/org/eclipse')
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CheckoutPullRequestHandler.java5
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CommitAttributePart.java5
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/PullRequestContextSynchronizer.java43
3 files changed, 22 insertions, 31 deletions
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CheckoutPullRequestHandler.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CheckoutPullRequestHandler.java
index b063ef5c..10e6f78a 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CheckoutPullRequestHandler.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CheckoutPullRequestHandler.java
@@ -61,11 +61,8 @@ public class CheckoutPullRequestHandler extends TaskDataHandler {
private RevCommit getBase(Repository repo, PullRequest request)
throws IOException {
- RevWalk walk = new RevWalk(repo);
- try {
+ try (RevWalk walk = new RevWalk(repo)) {
return walk.parseCommit(repo.resolve(request.getBase().getSha()));
- } finally {
- walk.release();
}
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CommitAttributePart.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CommitAttributePart.java
index 47f79bb0..4e0b08e4 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CommitAttributePart.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/CommitAttributePart.java
@@ -165,8 +165,7 @@ public class CommitAttributePart extends AbstractTaskEditorSection {
return;
if (repository == null)
return;
- RevWalk walk = new RevWalk(repository);
- try {
+ try (RevWalk walk = new RevWalk(repository)) {
for (Object element : elements) {
String id = ((PullRequestCommitAdapter) element).getCommit()
.getSha();
@@ -198,8 +197,6 @@ public class CommitAttributePart extends AbstractTaskEditorSection {
}
} catch (IOException e) {
GitHubUi.logError(e);
- } finally {
- walk.release();
}
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/PullRequestContextSynchronizer.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/PullRequestContextSynchronizer.java
index bf4eba6a..33c58b1d 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/PullRequestContextSynchronizer.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/pr/PullRequestContextSynchronizer.java
@@ -56,7 +56,6 @@ public class PullRequestContextSynchronizer extends TaskActivationAdapter {
if (context == null)
return;
- RevWalk walk = null;
try {
TaskData data = TasksUi.getTaskDataManager().getTaskData(task);
PullRequestComposite prComp = PullRequestConnector
@@ -67,35 +66,33 @@ public class PullRequestContextSynchronizer extends TaskActivationAdapter {
Repository repository = PullRequestUtils.getRepository(request);
if (repository == null)
return;
- walk = new RevWalk(repository);
- TreeWalk diffs = new TreeWalk(walk.getObjectReader());
- diffs.setFilter(TreeFilter.ANY_DIFF);
- diffs.setRecursive(true);
- diffs.addTree(walk.parseCommit(
- ObjectId.fromString(request.getHead().getSha())).getTree());
- diffs.addTree(walk.parseCommit(
- ObjectId.fromString(request.getBase().getSha())).getTree());
- Set<IResource> resources = new HashSet<IResource>();
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- String base = repository.getWorkTree().getAbsolutePath() + "/"; //$NON-NLS-1$
- while (diffs.next()) {
- IFile file = root.getFileForLocation(Path.fromOSString(base
- + diffs.getPathString()));
- if (file != null)
- resources.add(file);
+ try (RevWalk walk = new RevWalk(repository);
+ TreeWalk diffs = new TreeWalk(walk.getObjectReader())) {
+ diffs.setFilter(TreeFilter.ANY_DIFF);
+ diffs.setRecursive(true);
+ diffs.addTree(walk.parseCommit(
+ ObjectId.fromString(request.getHead().getSha())).getTree());
+ diffs.addTree(walk.parseCommit(
+ ObjectId.fromString(request.getBase().getSha())).getTree());
+ Set<IResource> resources = new HashSet<IResource>();
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ String base = repository.getWorkTree().getAbsolutePath() + "/"; //$NON-NLS-1$
+ while (diffs.next()) {
+ IFile file = root.getFileForLocation(Path.fromOSString(base
+ + diffs.getPathString()));
+ if (file != null)
+ resources.add(file);
+ }
+ if (!resources.isEmpty())
+ ResourcesUi.addResourceToContext(resources,
+ InteractionEvent.Kind.SELECTION);
}
- if (!resources.isEmpty())
- ResourcesUi.addResourceToContext(resources,
- InteractionEvent.Kind.SELECTION);
} catch (MissingObjectException ignored) {
// Ignored
} catch (IOException e) {
GitHubUi.logError(e);
} catch (CoreException e) {
GitHubUi.logError(e);
- } finally {
- if (walk != null)
- walk.release();
}
}
}

Back to the top