Convert to auto-closeable Repository and RevWalk
Change-Id: Ia2964f4e7fbf76948059b37ab47c07baeb6db78f
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/util/CommitMessageFetcher.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/util/CommitMessageFetcher.java
index a04b175..02ea502 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/util/CommitMessageFetcher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/util/CommitMessageFetcher.java
@@ -25,15 +25,11 @@
}
public String fetch(String projectName, String commitId) throws IOException {
- final Repository repo =
- repoManager.openRepository(new NameKey(projectName));
- try {
- RevWalk revWalk = new RevWalk(repo);
- RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
-
- return commit.getFullMessage();
- } finally {
- repo.close();
+ try (Repository repo = repoManager.openRepository(new NameKey(projectName))) {
+ try (RevWalk revWalk = new RevWalk(repo)) {
+ RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
+ return commit.getFullMessage();
+ }
}
}