import java.util.Collections;
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.ReverseCandidate;
import org.eclipse.jgit.blame.ReverseWalk.ReverseCommit;
if (n.sourceCommit == null)
return result(n);
- DiffEntry r = findRename(parent, n.sourceCommit, n.sourcePath);
- if (r == null)
+ DiffEntry r;
+ try {
+ r = findRename(parent, n.sourceCommit, n.sourcePath);
+ if (r == null) {
+ return result(n);
+ }
+ } catch (CanceledException e) {
return result(n);
+ }
if (0 == r.getOldId().prefixCompare(n.sourceBlob)) {
// A 100% rename without any content change can also
return false;
}
- private boolean processMerge(Candidate n) throws IOException {
+ private boolean processMerge(Candidate n)
+ throws IOException {
int pCnt = n.getParentCount();
// If any single parent exactly matches the merge, follow only
if (ids != null && ids[pIdx] != null)
continue;
- DiffEntry r = findRename(parent, n.sourceCommit, n.sourcePath);
- if (r == null)
+ DiffEntry r;
+ try {
+ r = findRename(parent, n.sourceCommit, n.sourcePath);
+ if (r == null) {
+ continue;
+ }
+ } catch (CanceledException e) {
continue;
+ }
if (n instanceof ReverseCandidate) {
if (ids == null)
}
private DiffEntry findRename(RevCommit parent, RevCommit commit,
- PathFilter path) throws IOException {
+ PathFilter path) throws IOException, CanceledException {
if (renameDetector == null)
return null;
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.internal.JGitText;
* 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) {
+ return Collections.emptyList();
+ }
}
/**
* representing all files that have been changed.
* @throws java.io.IOException
* file contents cannot be read from the repository.
+ * @throws CanceledException
+ * if rename detection was cancelled
*/
- public List<DiffEntry> compute(ProgressMonitor pm) throws IOException {
+ public List<DiffEntry> compute(ProgressMonitor pm)
+ throws IOException, CanceledException {
if (!done) {
try {
return compute(objectReader, pm);
* representing all files that have been changed.
* @throws java.io.IOException
* file contents cannot be read from the repository.
+ * @throws CanceledException
+ * if rename detection was cancelled
*/
public List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm)
- throws IOException {
+ throws IOException, CanceledException {
final ContentSource cs = ContentSource.create(reader);
return compute(new ContentSource.Pair(cs, cs), pm);
}
* representing all files that have been changed.
* @throws java.io.IOException
* file contents cannot be read from the repository.
+ * @throws CanceledException
+ * if rename detection was cancelled
*/
public List<DiffEntry> compute(ContentSource.Pair reader, ProgressMonitor pm)
- throws IOException {
+ throws IOException, CanceledException {
if (!done) {
done = true;
done = false;
}
+ private void advanceOrCancel(ProgressMonitor pm) throws CanceledException {
+ if (pm.isCancelled()) {
+ throw new CanceledException(JGitText.get().renameCancelled);
+ }
+ pm.update(1);
+ }
+
private void breakModifies(ContentSource.Pair reader, ProgressMonitor pm)
- throws IOException {
+ throws IOException, CanceledException {
ArrayList<DiffEntry> newEntries = new ArrayList<>(entries.size());
pm.beginTask(JGitText.get().renamesBreakingModifies, entries.size());
} else {
newEntries.add(e);
}
- pm.update(1);
+ advanceOrCancel(pm);
}
entries = newEntries;
}
- private void rejoinModifies(ProgressMonitor pm) {
+ private void rejoinModifies(ProgressMonitor pm) throws CanceledException {
HashMap<String, DiffEntry> nameMap = new HashMap<>();
ArrayList<DiffEntry> newAdded = new ArrayList<>(added.size());
for (DiffEntry src : deleted) {
nameMap.put(src.oldPath, src);
- pm.update(1);
+ advanceOrCancel(pm);
}
for (DiffEntry dst : added) {
} else {
newAdded.add(dst);
}
- pm.update(1);
+ advanceOrCancel(pm);
}
added = newAdded;
private void findContentRenames(ContentSource.Pair reader,
ProgressMonitor pm)
- throws IOException {
+ throws IOException, CanceledException {
int cnt = Math.max(added.size(), deleted.size());
if (getRenameLimit() == 0 || cnt <= getRenameLimit()) {
SimilarityRenameDetector d;
}
@SuppressWarnings("unchecked")
- private void findExactRenames(ProgressMonitor pm) {
+ private void findExactRenames(ProgressMonitor pm) throws CanceledException {
pm.beginTask(JGitText.get().renamesFindingExact, //
added.size() + added.size() + deleted.size()
+ added.size() * deleted.size());
} else {
left.add(a);
}
- pm.update(1);
+ advanceOrCancel(pm);
}
for (List<DiffEntry> adds : nonUniqueAdds) {
int score = SimilarityRenameDetector.nameScore(addedName, deletedName);
matrix[mNext] = SimilarityRenameDetector.encode(score, delIdx, addIdx);
mNext++;
+ if (pm.isCancelled()) {
+ throw new CanceledException(
+ JGitText.get().renameCancelled);
+ }
}
}
DiffEntry a = adds.get(addIdx);
if (a == null) {
- pm.update(1);
+ advanceOrCancel(pm);
continue; // was already matched earlier
}
entries.add(DiffEntry.pair(type, d, a, 100));
adds.set(addIdx, null); // Claim the destination was matched.
- pm.update(1);
+ advanceOrCancel(pm);
}
} else {
left.addAll(adds);
}
+ advanceOrCancel(pm);
}
added = left;
@SuppressWarnings("unchecked")
private HashMap<AbbreviatedObjectId, Object> populateMap(
- List<DiffEntry> diffEntries, ProgressMonitor pm) {
+ List<DiffEntry> diffEntries, ProgressMonitor pm)
+ throws CanceledException {
HashMap<AbbreviatedObjectId, Object> map = new HashMap<>();
for (DiffEntry de : diffEntries) {
Object old = map.put(id(de), de);
((List<DiffEntry>) old).add(de);
map.put(id(de), old);
}
- pm.update(1);
+ advanceOrCancel(pm);
}
return map;
}
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.internal.JGitText;
renameScore = score;
}
- void compute(ProgressMonitor pm) throws IOException {
+ void compute(ProgressMonitor pm) throws IOException, CanceledException {
if (pm == null)
pm = NullProgressMonitor.INSTANCE;
// we have looked at everything that is above our minimum score.
//
for (--mNext; mNext >= 0; mNext--) {
+ if (pm.isCancelled()) {
+ throw new CanceledException(JGitText.get().renameCancelled);
+ }
long ent = matrix[mNext];
int sIdx = srcFile(ent);
int dIdx = dstFile(ent);
return r;
}
- private int buildMatrix(ProgressMonitor pm) throws IOException {
+ private int buildMatrix(ProgressMonitor pm)
+ 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.
//
SimilarityIndex s = null;
for (int dstIdx = 0; dstIdx < dsts.size(); dstIdx++) {
+ if (pm.isCancelled()) {
+ throw new CanceledException(JGitText.get().renameCancelled);
+ }
+
DiffEntry dstEnt = dsts.get(dstIdx);
if (!isFile(dstEnt.newMode)) {