diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2015-08-27 14:06:38 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2015-08-27 14:06:38 +0900 |
commit | cc91e0c2987a4606e19b10e320b14f6a0c911c06 (patch) | |
tree | 8b3fdee6c954649cd8e05e0aa2ee9168f118baf6 /src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java | |
parent | 264b7a00361f8a880cbad389523bf329f1989480 (diff) |
Open Repository in try-with-resource
Change-Id: I40009fb8c6886c1338c14d49bca2ac5987bc369b
Diffstat (limited to 'src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java')
-rw-r--r-- | src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java index 49edc41..60810b8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java @@ -235,27 +235,23 @@ class Destination { e = pending.get(uri); } if (e == null) { - Repository git; - try { - git = gitManager.openRepository(project); - } catch (IOException err) { - stateLog.error(String.format( - "source project %s not available", project), err, state); - return; - } - try { - Ref head = git.getRef(Constants.HEAD); - if (head != null - && head.isSymbolic() - && RefNames.REFS_CONFIG.equals(head.getLeaf().getName())) { + try (Repository git = gitManager.openRepository(project)) { + try { + Ref head = git.getRef(Constants.HEAD); + if (head != null + && head.isSymbolic() + && RefNames.REFS_CONFIG.equals(head.getLeaf().getName())) { + return; + } + } catch (IOException err) { + stateLog.error(String.format( + "cannot check type of project %s", project), err, state); return; } } catch (IOException err) { stateLog.error(String.format( - "cannot check type of project %s", project), err, state); + "source project %s not available", project), err, state); return; - } finally { - git.close(); } } } |