Browse Source

IndexDiff: close SubmoduleWalk and use already loaded DirCache

If the SubModuleWalk isn't closed its TreeWalk's ObjectReader won't
be closed. Re-loading the DirCache during an IndexDiff is not only
inefficient but could also give strange results if an external
process had modified the index in the meantime: file diffs would
be based on a "before" state, but submodule diffs on an "after"
state.

Change-Id: Iab948c08ac342138b37263c9028d80b84101f6d6
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
next
Thomas Wolf 5 years ago
parent
commit
36e16435be
  1. 20
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

20
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

@ -536,7 +536,8 @@ public class IndexDiff {
if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) { if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) {
IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode; IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode;
SubmoduleWalk smw = SubmoduleWalk.forIndex(repository); try (SubmoduleWalk smw = new SubmoduleWalk(repository)) {
smw.setTree(new DirCacheIterator(dirCache));
while (smw.next()) { while (smw.next()) {
try { try {
if (localIgnoreSubmoduleMode == null) if (localIgnoreSubmoduleMode == null)
@ -558,12 +559,13 @@ public class IndexDiff {
modified.add(subRepoPath); modified.add(subRepoPath);
recordFileMode(subRepoPath, FileMode.GITLINK); recordFileMode(subRepoPath, FileMode.GITLINK);
} else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) { } else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
IndexDiff smid = submoduleIndexDiffs.get(smw IndexDiff smid = submoduleIndexDiffs
.getPath()); .get(smw.getPath());
if (smid == null) { if (smid == null) {
smid = new IndexDiff(subRepo, smid = new IndexDiff(subRepo,
smw.getObjectId(), smw.getObjectId(),
wTreeIt.getWorkingTreeIterator(subRepo)); wTreeIt.getWorkingTreeIterator(
subRepo));
submoduleIndexDiffs.put(subRepoPath, smid); submoduleIndexDiffs.put(subRepoPath, smid);
} }
if (smid.diff()) { if (smid.diff()) {
@ -577,13 +579,14 @@ public class IndexDiff {
continue; continue;
} }
modified.add(subRepoPath); modified.add(subRepoPath);
recordFileMode(subRepoPath, FileMode.GITLINK); recordFileMode(subRepoPath,
FileMode.GITLINK);
} }
} }
} else if (missingSubmodules.remove(subRepoPath)) { } else if (missingSubmodules.remove(subRepoPath)) {
// If the directory is there and empty but the submodule // If the directory is there and empty but the
// repository in .git/modules doesn't exist yet it isn't // submodule repository in .git/modules doesn't
// "missing". // exist yet it isn't "missing".
File gitDir = new File( File gitDir = new File(
new File(repository.getDirectory(), new File(repository.getDirectory(),
Constants.MODULES), Constants.MODULES),
@ -598,6 +601,7 @@ public class IndexDiff {
} }
} }
} }
}
} }

Loading…
Cancel
Save