From a77ffdf0802a623a739c388d648eb66e50df6c8e Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 15 Mar 2018 15:43:13 +0900 Subject: [PATCH] SubmoduleSyncCommand: Refactor to open Repository in try-with-resource Change-Id: I502904ff7dbe074f7bbcb2a56a17bf4729f4f4d3 Signed-off-by: David Pursehouse --- .../jgit/api/SubmoduleSyncCommand.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java index d22d820c32..462543d3bb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java @@ -132,30 +132,31 @@ public class SubmoduleSyncCommand extends GitCommand> { path, ConfigConstants.CONFIG_KEY_URL, remoteUrl); synced.put(path, remoteUrl); - Repository subRepo = generator.getRepository(); - if (subRepo == null) - continue; + try (Repository subRepo = generator.getRepository()) { + if (subRepo == null) { + continue; + } + + StoredConfig subConfig; + String branch; - StoredConfig subConfig; - String branch; - try { subConfig = subRepo.getConfig(); // Get name of remote associated with current branch and // fall back to default remote name as last resort branch = getHeadBranch(subRepo); String remote = null; - if (branch != null) + if (branch != null) { remote = subConfig.getString( ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); - if (remote == null) + } + if (remote == null) { remote = Constants.DEFAULT_REMOTE_NAME; + } subConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants.CONFIG_KEY_URL, remoteUrl); subConfig.save(); - } finally { - subRepo.close(); } } if (!synced.isEmpty()) -- 2.39.5