diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java index 4e9fab7b5..167d0e08a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java @@ -384,7 +384,32 @@ public void setFilter(TreeFilter filter) { * @throws java.io.IOException */ public boolean diff() throws IOException { - return diff(null, 0, 0, ""); //$NON-NLS-1$ + return diff(null); + } + + /** + * Run the diff operation. Until this is called, all lists will be empty. + * Use + * {@link #diff(ProgressMonitor, int, int, String, RepositoryBuilderFactory)} + * if a progress monitor is required. + *
+ * The operation may create repositories for submodules using builders + * provided by the given {@code factory}, if any, and will also close these + * submodule repositories again. + *
+ * + * @param factory + * the {@link RepositoryBuilderFactory} to use to create builders + * to create submodule repositories, if needed; if {@code null}, + * submodule repositories will be built using a plain + * {@link RepositoryBuilder}. + * @return if anything is different between index, tree, and workdir + * @throws java.io.IOException + * @since 5.6 + */ + public boolean diff(RepositoryBuilderFactory factory) + throws IOException { + return diff(null, 0, 0, "", factory); //$NON-NLS-1$ } /** @@ -410,6 +435,45 @@ public boolean diff() throws IOException { public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, final String title) throws IOException { + return diff(monitor, estWorkTreeSize, estIndexSize, title, null); + } + + /** + * Run the diff operation. Until this is called, all lists will be empty. + *+ * The operation may be aborted by the progress monitor. In that event it + * will report what was found before the cancel operation was detected. + * Callers should ignore the result if monitor.isCancelled() is true. If a + * progress monitor is not needed, callers should use {@link #diff()} + * instead. Progress reporting is crude and approximate and only intended + * for informing the user. + *
+ *+ * The operation may create repositories for submodules using builders + * provided by the given {@code factory}, if any, and will also close these + * submodule repositories again. + *
+ * + * @param monitor + * for reporting progress, may be null + * @param estWorkTreeSize + * number or estimated files in the working tree + * @param estIndexSize + * number of estimated entries in the cache + * @param title + * a {@link java.lang.String} object. + * @param factory + * the {@link RepositoryBuilderFactory} to use to create builders + * to create submodule repositories, if needed; if {@code null}, + * submodule repositories will be built using a plain + * {@link RepositoryBuilder}. + * @return if anything is different between index, tree, and workdir + * @throws java.io.IOException + * @since 5.6 + */ + public boolean diff(ProgressMonitor monitor, int estWorkTreeSize, + int estIndexSize, String title, RepositoryBuilderFactory factory) + throws IOException { dirCache = repository.readDirCache(); try (TreeWalk treeWalk = new TreeWalk(repository)) { @@ -537,6 +601,7 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize, if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) { try (SubmoduleWalk smw = new SubmoduleWalk(repository)) { smw.setTree(new DirCacheIterator(dirCache)); + smw.setBuilderFactory(factory); while (smw.next()) { IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode; try { @@ -568,7 +633,7 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize, subRepo)); submoduleIndexDiffs.put(subRepoPath, smid); } - if (smid.diff()) { + if (smid.diff(factory)) { if (localIgnoreSubmoduleMode == IgnoreSubmoduleMode.UNTRACKED && smid.getAdded().isEmpty() && smid.getChanged().isEmpty() diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryBuilderFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryBuilderFactory.java new file mode 100644 index 000000000..fc1251683 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryBuilderFactory.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019, Thomas Wolf+ * Note that a {@link BaseRepositoryBuilder} should be used only once to build a + * repository. Otherwise subsequently built repositories may be built using + * settings made for earlier built repositories. + *
+ * + * @since 5.6 + */ +public interface RepositoryBuilderFactory extends + Supplier