Browse Source

Fix API breakage introduced by da254106

Use org.eclipse.jgit.errors.CancelledException which is a subclass of
IOException instead of org.eclipse.jgit.api.errors.CanceledException in
order to avoid breaking API. We can reconsider this with the next major
version 6.0.

Bug: 536324
Change-Id: Ia6f84f59aa6b7d78b8fccaba24ade320a54f7458
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-5.1
Matthias Sohn 6 years ago committed by Thomas Wolf
parent
commit
cf6463bddc
  1. 26
      org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
  3. 41
      org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java
  4. 16
      org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java

26
org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java

@ -52,7 +52,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.blame.Candidate.BlobCandidate; import org.eclipse.jgit.blame.Candidate.BlobCandidate;
import org.eclipse.jgit.blame.Candidate.ReverseCandidate; import org.eclipse.jgit.blame.Candidate.ReverseCandidate;
import org.eclipse.jgit.blame.ReverseWalk.ReverseCommit; import org.eclipse.jgit.blame.ReverseWalk.ReverseCommit;
@ -628,15 +627,9 @@ public class BlameGenerator implements AutoCloseable {
if (n.sourceCommit == null) if (n.sourceCommit == null)
return result(n); return result(n);
DiffEntry r; DiffEntry r = findRename(parent, n.sourceCommit, n.sourcePath);
try { if (r == null)
r = findRename(parent, n.sourceCommit, n.sourcePath);
if (r == null) {
return result(n);
}
} catch (CanceledException e) {
return result(n); return result(n);
}
if (0 == r.getOldId().prefixCompare(n.sourceBlob)) { if (0 == r.getOldId().prefixCompare(n.sourceBlob)) {
// A 100% rename without any content change can also // A 100% rename without any content change can also
@ -694,8 +687,7 @@ public class BlameGenerator implements AutoCloseable {
return false; return false;
} }
private boolean processMerge(Candidate n) private boolean processMerge(Candidate n) throws IOException {
throws IOException {
int pCnt = n.getParentCount(); int pCnt = n.getParentCount();
// If any single parent exactly matches the merge, follow only // If any single parent exactly matches the merge, follow only
@ -722,15 +714,9 @@ public class BlameGenerator implements AutoCloseable {
if (ids != null && ids[pIdx] != null) if (ids != null && ids[pIdx] != null)
continue; continue;
DiffEntry r; DiffEntry r = findRename(parent, n.sourceCommit, n.sourcePath);
try { if (r == null)
r = findRename(parent, n.sourceCommit, n.sourcePath);
if (r == null) {
continue;
}
} catch (CanceledException e) {
continue; continue;
}
if (n instanceof ReverseCandidate) { if (n instanceof ReverseCandidate) {
if (ids == null) if (ids == null)
@ -1035,7 +1021,7 @@ public class BlameGenerator implements AutoCloseable {
} }
private DiffEntry findRename(RevCommit parent, RevCommit commit, private DiffEntry findRename(RevCommit parent, RevCommit commit,
PathFilter path) throws IOException, CanceledException { PathFilter path) throws IOException {
if (renameDetector == null) if (renameDetector == null)
return null; return null;

7
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -62,12 +62,12 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm; import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.AmbiguousObjectException; import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.BinaryBlobException; import org.eclipse.jgit.errors.BinaryBlobException;
import org.eclipse.jgit.errors.CancelledException;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
@ -580,7 +580,10 @@ public class DiffFormatter implements AutoCloseable {
renameDetector.addAll(files); renameDetector.addAll(files);
try { try {
return renameDetector.compute(reader, progressMonitor); return renameDetector.compute(reader, progressMonitor);
} catch (CanceledException e) { } catch (CancelledException e) {
// TODO: consider propagating once bug 536323 is tackled
// (making DiffEntry.scan() and DiffFormatter.scan() and
// format() cancellable).
return Collections.emptyList(); return Collections.emptyList();
} }
} }

41
org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java

@ -55,9 +55,9 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.diff.SimilarityIndex.TableFullException; import org.eclipse.jgit.diff.SimilarityIndex.TableFullException;
import org.eclipse.jgit.errors.CancelledException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
@ -321,11 +321,7 @@ public class RenameDetector {
* file contents cannot be read from the repository. * file contents cannot be read from the repository.
*/ */
public List<DiffEntry> compute() throws IOException { public List<DiffEntry> compute() throws IOException {
try {
return compute(NullProgressMonitor.INSTANCE); return compute(NullProgressMonitor.INSTANCE);
} catch (CanceledException e) {
return Collections.emptyList();
}
} }
/** /**
@ -337,11 +333,13 @@ public class RenameDetector {
* representing all files that have been changed. * representing all files that have been changed.
* @throws java.io.IOException * @throws java.io.IOException
* file contents cannot be read from the repository. * file contents cannot be read from the repository.
* @throws CanceledException * @throws CancelledException
* if rename detection was cancelled * if rename detection was cancelled
*/ */
// TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major
// version
public List<DiffEntry> compute(ProgressMonitor pm) public List<DiffEntry> compute(ProgressMonitor pm)
throws IOException, CanceledException { throws IOException, CancelledException {
if (!done) { if (!done) {
try { try {
return compute(objectReader, pm); return compute(objectReader, pm);
@ -363,11 +361,13 @@ public class RenameDetector {
* representing all files that have been changed. * representing all files that have been changed.
* @throws java.io.IOException * @throws java.io.IOException
* file contents cannot be read from the repository. * file contents cannot be read from the repository.
* @throws CanceledException * @throws CancelledException
* if rename detection was cancelled * 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) public List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm)
throws IOException, CanceledException { throws IOException, CancelledException {
final ContentSource cs = ContentSource.create(reader); final ContentSource cs = ContentSource.create(reader);
return compute(new ContentSource.Pair(cs, cs), pm); return compute(new ContentSource.Pair(cs, cs), pm);
} }
@ -383,11 +383,13 @@ public class RenameDetector {
* representing all files that have been changed. * representing all files that have been changed.
* @throws java.io.IOException * @throws java.io.IOException
* file contents cannot be read from the repository. * file contents cannot be read from the repository.
* @throws CanceledException * @throws CancelledException
* if rename detection was cancelled * 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) public List<DiffEntry> compute(ContentSource.Pair reader, ProgressMonitor pm)
throws IOException, CanceledException { throws IOException, CancelledException {
if (!done) { if (!done) {
done = true; done = true;
@ -427,15 +429,15 @@ public class RenameDetector {
done = false; done = false;
} }
private void advanceOrCancel(ProgressMonitor pm) throws CanceledException { private void advanceOrCancel(ProgressMonitor pm) throws CancelledException {
if (pm.isCancelled()) { if (pm.isCancelled()) {
throw new CanceledException(JGitText.get().renameCancelled); throw new CancelledException(JGitText.get().renameCancelled);
} }
pm.update(1); pm.update(1);
} }
private void breakModifies(ContentSource.Pair reader, ProgressMonitor pm) private void breakModifies(ContentSource.Pair reader, ProgressMonitor pm)
throws IOException, CanceledException { throws IOException, CancelledException {
ArrayList<DiffEntry> newEntries = new ArrayList<>(entries.size()); ArrayList<DiffEntry> newEntries = new ArrayList<>(entries.size());
pm.beginTask(JGitText.get().renamesBreakingModifies, entries.size()); pm.beginTask(JGitText.get().renamesBreakingModifies, entries.size());
@ -462,7 +464,7 @@ public class RenameDetector {
entries = newEntries; entries = newEntries;
} }
private void rejoinModifies(ProgressMonitor pm) throws CanceledException { private void rejoinModifies(ProgressMonitor pm) throws CancelledException {
HashMap<String, DiffEntry> nameMap = new HashMap<>(); HashMap<String, DiffEntry> nameMap = new HashMap<>();
ArrayList<DiffEntry> newAdded = new ArrayList<>(added.size()); ArrayList<DiffEntry> newAdded = new ArrayList<>(added.size());
@ -517,7 +519,7 @@ public class RenameDetector {
private void findContentRenames(ContentSource.Pair reader, private void findContentRenames(ContentSource.Pair reader,
ProgressMonitor pm) ProgressMonitor pm)
throws IOException, CanceledException { throws IOException, CancelledException {
int cnt = Math.max(added.size(), deleted.size()); int cnt = Math.max(added.size(), deleted.size());
if (getRenameLimit() == 0 || cnt <= getRenameLimit()) { if (getRenameLimit() == 0 || cnt <= getRenameLimit()) {
SimilarityRenameDetector d; SimilarityRenameDetector d;
@ -535,7 +537,8 @@ public class RenameDetector {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void findExactRenames(ProgressMonitor pm) throws CanceledException { private void findExactRenames(ProgressMonitor pm)
throws CancelledException {
pm.beginTask(JGitText.get().renamesFindingExact, // pm.beginTask(JGitText.get().renamesFindingExact, //
added.size() + added.size() + deleted.size() added.size() + added.size() + deleted.size()
+ added.size() * deleted.size()); + added.size() * deleted.size());
@ -624,7 +627,7 @@ public class RenameDetector {
matrix[mNext] = SimilarityRenameDetector.encode(score, delIdx, addIdx); matrix[mNext] = SimilarityRenameDetector.encode(score, delIdx, addIdx);
mNext++; mNext++;
if (pm.isCancelled()) { if (pm.isCancelled()) {
throw new CanceledException( throw new CancelledException(
JGitText.get().renameCancelled); JGitText.get().renameCancelled);
} }
} }
@ -717,7 +720,7 @@ public class RenameDetector {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private HashMap<AbbreviatedObjectId, Object> populateMap( private HashMap<AbbreviatedObjectId, Object> populateMap(
List<DiffEntry> diffEntries, ProgressMonitor pm) List<DiffEntry> diffEntries, ProgressMonitor pm)
throws CanceledException { throws CancelledException {
HashMap<AbbreviatedObjectId, Object> map = new HashMap<>(); HashMap<AbbreviatedObjectId, Object> map = new HashMap<>();
for (DiffEntry de : diffEntries) { for (DiffEntry de : diffEntries) {
Object old = map.put(id(de), de); Object old = map.put(id(de), de);

16
org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java

@ -52,9 +52,9 @@ import java.util.Arrays;
import java.util.BitSet; import java.util.BitSet;
import java.util.List; import java.util.List;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.diff.SimilarityIndex.TableFullException; import org.eclipse.jgit.diff.SimilarityIndex.TableFullException;
import org.eclipse.jgit.errors.CancelledException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.NullProgressMonitor;
@ -129,7 +129,7 @@ class SimilarityRenameDetector {
renameScore = score; renameScore = score;
} }
void compute(ProgressMonitor pm) throws IOException, CanceledException { void compute(ProgressMonitor pm) throws IOException, CancelledException {
if (pm == null) if (pm == null)
pm = NullProgressMonitor.INSTANCE; pm = NullProgressMonitor.INSTANCE;
@ -144,7 +144,9 @@ class SimilarityRenameDetector {
// //
for (--mNext; mNext >= 0; mNext--) { for (--mNext; mNext >= 0; mNext--) {
if (pm.isCancelled()) { if (pm.isCancelled()) {
throw new CanceledException(JGitText.get().renameCancelled); // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException
// in next major version
throw new CancelledException(JGitText.get().renameCancelled);
} }
long ent = matrix[mNext]; long ent = matrix[mNext];
int sIdx = srcFile(ent); int sIdx = srcFile(ent);
@ -214,7 +216,7 @@ class SimilarityRenameDetector {
} }
private int buildMatrix(ProgressMonitor pm) private int buildMatrix(ProgressMonitor pm)
throws IOException, CanceledException { throws IOException, CancelledException {
// Allocate for the worst-case scenario where every pair has a // Allocate for the worst-case scenario where every pair has a
// score that we need to consider. We might not need that many. // score that we need to consider. We might not need that many.
// //
@ -240,7 +242,11 @@ class SimilarityRenameDetector {
for (int dstIdx = 0; dstIdx < dsts.size(); dstIdx++) { for (int dstIdx = 0; dstIdx < dsts.size(); dstIdx++) {
if (pm.isCancelled()) { if (pm.isCancelled()) {
throw new CanceledException(JGitText.get().renameCancelled); // TODO(ms): use
// org.eclipse.jgit.api.errors.CanceledException in next
// major version
throw new CancelledException(
JGitText.get().renameCancelled);
} }
DiffEntry dstEnt = dsts.get(dstIdx); DiffEntry dstEnt = dsts.get(dstIdx);

Loading…
Cancel
Save