Merge "Fix file handle leak in FetchCommand#fetchSubmodules"

This commit is contained in:
Matthias Sohn 2018-01-04 06:45:00 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit 992980d856
1 changed files with 34 additions and 30 deletions

View File

@ -171,38 +171,42 @@ private void fetchSubmodules(FetchResult results)
}
walk.setTree(revWalk.parseTree(fetchHead));
while (walk.next()) {
Repository submoduleRepo = walk.getRepository();
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());
// 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());
}
results.addSubmodule(walk.getPath(), f.call());
}
results.addSubmodule(walk.getPath(), f.call());
}
}
} catch (IOException e) {