Browse Source

Merge "Fix file handle leak in FetchCommand#fetchSubmodules"

stable-4.11
Matthias Sohn 7 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
992980d856
  1. 64
      org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java

64
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)); walk.setTree(revWalk.parseTree(fetchHead));
while (walk.next()) { while (walk.next()) {
Repository submoduleRepo = walk.getRepository(); try (Repository submoduleRepo = walk.getRepository()) {
// Skip submodules that don't exist locally (have not been // Skip submodules that don't exist locally (have not been
// cloned), are not registered in the .gitmodules file, or // cloned), are not registered in the .gitmodules file, or
// not registered in the parent repository's config. // not registered in the parent repository's config.
if (submoduleRepo == null || walk.getModulesPath() == null if (submoduleRepo == null || walk.getModulesPath() == null
|| walk.getConfigUrl() == null) { || walk.getConfigUrl() == null) {
continue; continue;
} }
FetchRecurseSubmodulesMode recurseMode = getRecurseMode( FetchRecurseSubmodulesMode recurseMode = getRecurseMode(
walk.getPath()); walk.getPath());
// When the fetch mode is "yes" we always fetch. When the mode // When the fetch mode is "yes" we always fetch. When the
// is "on demand", we only fetch if the submodule's revision was // mode
// updated to an object that is not currently present in the // is "on demand", we only fetch if the submodule's revision
// submodule. // was
if ((recurseMode == FetchRecurseSubmodulesMode.ON_DEMAND // updated to an object that is not currently present in the
&& !submoduleRepo.hasObject(walk.getObjectId())) // submodule.
|| recurseMode == FetchRecurseSubmodulesMode.YES) { if ((recurseMode == FetchRecurseSubmodulesMode.ON_DEMAND
FetchCommand f = new FetchCommand(submoduleRepo) && !submoduleRepo.hasObject(walk.getObjectId()))
.setProgressMonitor(monitor).setTagOpt(tagOption) || recurseMode == FetchRecurseSubmodulesMode.YES) {
.setCheckFetchedObjects(checkFetchedObjects) FetchCommand f = new FetchCommand(submoduleRepo)
.setRemoveDeletedRefs(isRemoveDeletedRefs()) .setProgressMonitor(monitor)
.setThin(thin).setRefSpecs(refSpecs) .setTagOpt(tagOption)
.setDryRun(dryRun) .setCheckFetchedObjects(checkFetchedObjects)
.setRecurseSubmodules(recurseMode); .setRemoveDeletedRefs(isRemoveDeletedRefs())
configure(f); .setThin(thin).setRefSpecs(refSpecs)
if (callback != null) { .setDryRun(dryRun)
callback.fetchingSubmodule(walk.getPath()); .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) { } catch (IOException e) {

Loading…
Cancel
Save