Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2018-01-04 11:45:00 +0000
committerGerrit Code Review @ Eclipse.org2018-01-04 11:45:00 +0000
commit992980d8560613c60a966de64bf7217321e681b1 (patch)
tree0aed7084a3bca07baa152e0a66f23317b0322cb5
parent21d22e6f63a1adcfaeaee155f1be32f8123fd789 (diff)
parent67a8858b945944cc94baf9a2f6e4516bc283656b (diff)
downloadjgit-992980d8560613c60a966de64bf7217321e681b1.tar.gz
jgit-992980d8560613c60a966de64bf7217321e681b1.tar.xz
jgit-992980d8560613c60a966de64bf7217321e681b1.zip
Merge "Fix file handle leak in FetchCommand#fetchSubmodules"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java64
1 files changed, 34 insertions, 30 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java
index b2c28dab0c..5d178bc13c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java
@@ -171,38 +171,42 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> {
}
walk.setTree(revWalk.parseTree(fetchHead));
while (walk.next()) {
- Repository submoduleRepo = walk.getRepository();
-
- // Skip submodules that don't exist locally (have not been
- // cloned), are not registered in the .gitmodules file, or
- // not registered in the parent repository's config.
- if (submoduleRepo == null || walk.getModulesPath() == null
- || walk.getConfigUrl() == null) {
- continue;
- }
+ try (Repository submoduleRepo = walk.getRepository()) {
+
+ // Skip submodules that don't exist locally (have not been
+ // cloned), are not registered in the .gitmodules file, or
+ // not registered in the parent repository's config.
+ if (submoduleRepo == null || walk.getModulesPath() == null
+ || walk.getConfigUrl() == null) {
+ continue;
+ }
- FetchRecurseSubmodulesMode recurseMode = getRecurseMode(
- walk.getPath());
-
- // When the fetch mode is "yes" we always fetch. When the mode
- // is "on demand", we only fetch if the submodule's revision was
- // updated to an object that is not currently present in the
- // submodule.
- if ((recurseMode == FetchRecurseSubmodulesMode.ON_DEMAND
- && !submoduleRepo.hasObject(walk.getObjectId()))
- || recurseMode == FetchRecurseSubmodulesMode.YES) {
- FetchCommand f = new FetchCommand(submoduleRepo)
- .setProgressMonitor(monitor).setTagOpt(tagOption)
- .setCheckFetchedObjects(checkFetchedObjects)
- .setRemoveDeletedRefs(isRemoveDeletedRefs())
- .setThin(thin).setRefSpecs(refSpecs)
- .setDryRun(dryRun)
- .setRecurseSubmodules(recurseMode);
- configure(f);
- if (callback != null) {
- callback.fetchingSubmodule(walk.getPath());
+ FetchRecurseSubmodulesMode recurseMode = getRecurseMode(
+ walk.getPath());
+
+ // When the fetch mode is "yes" we always fetch. When the
+ // mode
+ // is "on demand", we only fetch if the submodule's revision
+ // was
+ // updated to an object that is not currently present in the
+ // submodule.
+ if ((recurseMode == FetchRecurseSubmodulesMode.ON_DEMAND
+ && !submoduleRepo.hasObject(walk.getObjectId()))
+ || recurseMode == FetchRecurseSubmodulesMode.YES) {
+ FetchCommand f = new FetchCommand(submoduleRepo)
+ .setProgressMonitor(monitor)
+ .setTagOpt(tagOption)
+ .setCheckFetchedObjects(checkFetchedObjects)
+ .setRemoveDeletedRefs(isRemoveDeletedRefs())
+ .setThin(thin).setRefSpecs(refSpecs)
+ .setDryRun(dryRun)
+ .setRecurseSubmodules(recurseMode);
+ configure(f);
+ if (callback != null) {
+ callback.fetchingSubmodule(walk.getPath());
+ }
+ results.addSubmodule(walk.getPath(), f.call());
}
- results.addSubmodule(walk.getPath(), f.call());
}
}
} catch (IOException e) {

Back to the top