diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2021-11-22 08:55:01 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2021-11-22 17:57:26 -0500 |
commit | ce6826f5061297d7e8c949127e34e08488f2f229 (patch) | |
tree | aeb9c0b94d9b5d3086c7c5a535843cc862c3d04e | |
parent | a4542d06bbd6f635f0ac9ebf8df4f9fd5efdccdf (diff) | |
download | jgit-ce6826f5061297d7e8c949127e34e08488f2f229.tar.gz jgit-ce6826f5061297d7e8c949127e34e08488f2f229.zip |
[6.0 API cleanup] CancelledException vs. CanceledException
Use the GitAPIException CanceledException instead of IOException
CancelledException in the rename detector.
Change-Id: I5121719eb714a123ec57769fc113c84857bd3c6c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
3 files changed, 29 insertions, 34 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java index ec21954aa2..49da95c9ab 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java @@ -29,12 +29,12 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.eclipse.jgit.api.errors.CanceledException; import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm; import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.errors.AmbiguousObjectException; import org.eclipse.jgit.errors.BinaryBlobException; -import org.eclipse.jgit.errors.CancelledException; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; @@ -578,7 +578,7 @@ public class DiffFormatter implements AutoCloseable { renameDetector.addAll(files); try { return renameDetector.compute(reader, progressMonitor); - } catch (CancelledException e) { + } catch (CanceledException e) { // TODO: consider propagating once bug 536323 is tackled // (making DiffEntry.scan() and DiffFormatter.scan() and // format() cancellable). diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java index 225921ecc1..c33f53adde 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java @@ -23,9 +23,9 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import org.eclipse.jgit.api.errors.CanceledException; import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.SimilarityIndex.TableFullException; -import org.eclipse.jgit.errors.CancelledException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.FileMode; @@ -336,6 +336,7 @@ public class RenameDetector { * Detect renames in the current file set. * <p> * This convenience function runs without a progress monitor. + * </p> * * @return an unmodifiable list of {@link org.eclipse.jgit.diff.DiffEntry}s * representing all files that have been changed. @@ -343,7 +344,12 @@ public class RenameDetector { * file contents cannot be read from the repository. */ public List<DiffEntry> compute() throws IOException { - return compute(NullProgressMonitor.INSTANCE); + try { + return compute(NullProgressMonitor.INSTANCE); + } catch (CanceledException e) { + // Won't happen with a NullProgressMonitor + return Collections.emptyList(); + } } /** @@ -355,13 +361,11 @@ public class RenameDetector { * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. - * @throws CancelledException + * @throws CanceledException * if rename detection was cancelled */ - // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major - // version public List<DiffEntry> compute(ProgressMonitor pm) - throws IOException, CancelledException { + throws IOException, CanceledException { if (!done) { try { return compute(objectReader, pm); @@ -383,13 +387,11 @@ public class RenameDetector { * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. - * @throws CancelledException + * @throws CanceledException * if rename detection was cancelled */ - // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major - // version public List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm) - throws IOException, CancelledException { + throws IOException, CanceledException { final ContentSource cs = ContentSource.create(reader); return compute(new ContentSource.Pair(cs, cs), pm); } @@ -405,13 +407,11 @@ public class RenameDetector { * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. - * @throws CancelledException + * @throws CanceledException * if rename detection was cancelled */ - // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major - // version public List<DiffEntry> compute(ContentSource.Pair reader, ProgressMonitor pm) - throws IOException, CancelledException { + throws IOException, CanceledException { if (!done) { done = true; @@ -451,15 +451,15 @@ public class RenameDetector { done = false; } - private void advanceOrCancel(ProgressMonitor pm) throws CancelledException { + private void advanceOrCancel(ProgressMonitor pm) throws CanceledException { if (pm.isCancelled()) { - throw new CancelledException(JGitText.get().renameCancelled); + throw new CanceledException(JGitText.get().renameCancelled); } pm.update(1); } private void breakModifies(ContentSource.Pair reader, ProgressMonitor pm) - throws IOException, CancelledException { + throws IOException, CanceledException { ArrayList<DiffEntry> newEntries = new ArrayList<>(entries.size()); pm.beginTask(JGitText.get().renamesBreakingModifies, entries.size()); @@ -486,7 +486,7 @@ public class RenameDetector { entries = newEntries; } - private void rejoinModifies(ProgressMonitor pm) throws CancelledException { + private void rejoinModifies(ProgressMonitor pm) throws CanceledException { HashMap<String, DiffEntry> nameMap = new HashMap<>(); ArrayList<DiffEntry> newAdded = new ArrayList<>(added.size()); @@ -541,7 +541,7 @@ public class RenameDetector { private void findContentRenames(ContentSource.Pair reader, ProgressMonitor pm) - throws IOException, CancelledException { + throws IOException, CanceledException { int cnt = Math.max(added.size(), deleted.size()); if (getRenameLimit() == 0 || cnt <= getRenameLimit()) { SimilarityRenameDetector d; @@ -562,7 +562,7 @@ public class RenameDetector { @SuppressWarnings("unchecked") private void findExactRenames(ProgressMonitor pm) - throws CancelledException { + throws CanceledException { pm.beginTask(JGitText.get().renamesFindingExact, // added.size() + added.size() + deleted.size() + added.size() * deleted.size()); @@ -651,7 +651,7 @@ public class RenameDetector { matrix[mNext] = SimilarityRenameDetector.encode(score, delIdx, addIdx); mNext++; if (pm.isCancelled()) { - throw new CancelledException( + throw new CanceledException( JGitText.get().renameCancelled); } } @@ -744,7 +744,7 @@ public class RenameDetector { @SuppressWarnings("unchecked") private HashMap<AbbreviatedObjectId, Object> populateMap( List<DiffEntry> diffEntries, ProgressMonitor pm) - throws CancelledException { + throws CanceledException { HashMap<AbbreviatedObjectId, Object> map = new HashMap<>(); for (DiffEntry de : diffEntries) { Object old = map.put(id(de), de); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java index 5871b4aeea..9ac94895b1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java @@ -20,9 +20,9 @@ import java.util.Arrays; import java.util.BitSet; import java.util.List; +import org.eclipse.jgit.api.errors.CanceledException; import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.SimilarityIndex.TableFullException; -import org.eclipse.jgit.errors.CancelledException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.NullProgressMonitor; @@ -115,7 +115,7 @@ class SimilarityRenameDetector { skipBinaryFiles = value; } - void compute(ProgressMonitor pm) throws IOException, CancelledException { + void compute(ProgressMonitor pm) throws IOException, CanceledException { if (pm == null) pm = NullProgressMonitor.INSTANCE; @@ -130,9 +130,7 @@ class SimilarityRenameDetector { // for (--mNext; mNext >= 0; mNext--) { if (pm.isCancelled()) { - // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException - // in next major version - throw new CancelledException(JGitText.get().renameCancelled); + throw new CanceledException(JGitText.get().renameCancelled); } long ent = matrix[mNext]; int sIdx = srcFile(ent); @@ -202,7 +200,7 @@ class SimilarityRenameDetector { } private int buildMatrix(ProgressMonitor pm) - throws IOException, CancelledException { + throws IOException, CanceledException { // Allocate for the worst-case scenario where every pair has a // score that we need to consider. We might not need that many. // @@ -228,10 +226,7 @@ class SimilarityRenameDetector { for (int dstIdx = 0; dstIdx < dsts.size(); dstIdx++) { if (pm.isCancelled()) { - // TODO(ms): use - // org.eclipse.jgit.api.errors.CanceledException in next - // major version - throw new CancelledException( + throw new CanceledException( JGitText.get().renameCancelled); } |