summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2014-04-22 15:59:07 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2014-04-22 15:59:07 -0400
commit616ebfc821f8637c54b60ba297f7be9d57cbf913 (patch)
treee7aaed8a4811a2f6083f9ac7751a710ee3b0d2b7
parent05226ac9502670d4d49228aba2c5ff8ce837b85c (diff)
parent2d76133ba229135fcc8a9631fe0619456290f34d (diff)
downloadjgit-616ebfc821f8637c54b60ba297f7be9d57cbf913.tar.gz
jgit-616ebfc821f8637c54b60ba297f7be9d57cbf913.zip
Merge changes Icb1d49e5,I8bcab447,I3fa19b86,I2cda031b,I8b2dbf63
* changes: blame: Reuse existing blameEntireRegionOnParent method blame: Remove unnecessary curly braces around single statement if blame: Allow candidate to manage its setup before output blame: Do not update candidate regionList during output blame: Only use computeRange if -L was requested
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java55
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameResult.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/blame/Candidate.java11
3 files changed, 42 insertions, 28 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
index 5b02ce6c92..ca695d2a8b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
@@ -143,7 +143,8 @@ public class BlameGenerator {
private int remaining;
/** Blame is currently assigned to this source. */
- private Candidate currentSource;
+ private Candidate outCandidate;
+ private Region outRegion;
/**
* Create a blame generator for the repository and path (relative to
@@ -466,19 +467,19 @@ public class BlameGenerator {
*/
public boolean next() throws IOException {
// If there is a source still pending, produce the next region.
- if (currentSource != null) {
- Region r = currentSource.regionList;
- Region n = r.next;
+ if (outRegion != null) {
+ Region r = outRegion;
remaining -= r.length;
- if (n != null) {
- currentSource.regionList = n;
+ if (r.next != null) {
+ outRegion = r.next;
return true;
}
- if (currentSource.queueNext != null)
- return result(currentSource.queueNext);
+ if (outCandidate.queueNext != null)
+ return result(outCandidate.queueNext);
- currentSource = null;
+ outCandidate = null;
+ outRegion = null;
}
// If there are no lines remaining, the entire result is done,
@@ -518,9 +519,9 @@ public class BlameGenerator {
}
private boolean result(Candidate n) throws IOException {
- if (n.sourceCommit != null)
- revPool.parseBody(n.sourceCommit);
- currentSource = n;
+ n.beginResult(revPool);
+ outCandidate = n;
+ outRegion = n.regionList;
return true;
}
@@ -688,9 +689,8 @@ public class BlameGenerator {
revPool.parseHeaders(parent);
if (!find(parent, n.sourcePath))
continue;
- if (!(n instanceof ReverseCandidate) && idBuf.equals(n.sourceBlob)) {
+ if (!(n instanceof ReverseCandidate) && idBuf.equals(n.sourceBlob))
return blameEntireRegionOnParent(n, parent);
- }
if (ids == null)
ids = new ObjectId[pCnt];
ids[pIdx] = idBuf.toObjectId();
@@ -720,10 +720,8 @@ public class BlameGenerator {
// have an exact content match. For performance reasons
// we choose to follow the one parent over trying to do
// possibly both parents.
- n.sourceCommit = parent;
n.setSourcePath(PathFilter.create(r.getOldPath()));
- push(n);
- return false;
+ return blameEntireRegionOnParent(n, parent);
}
renames[pIdx] = r;
@@ -847,12 +845,12 @@ public class BlameGenerator {
* @return current revision being blamed.
*/
public RevCommit getSourceCommit() {
- return currentSource.sourceCommit;
+ return outCandidate.sourceCommit;
}
/** @return current author being blamed. */
public PersonIdent getSourceAuthor() {
- return currentSource.getAuthor();
+ return outCandidate.getAuthor();
}
/** @return current committer being blamed. */
@@ -863,12 +861,12 @@ public class BlameGenerator {
/** @return path of the file being blamed. */
public String getSourcePath() {
- return currentSource.sourcePath.getPath();
+ return outCandidate.sourcePath.getPath();
}
/** @return rename score if a rename occurred in {@link #getSourceCommit}. */
public int getRenameScore() {
- return currentSource.renameScore;
+ return outCandidate.renameScore;
}
/**
@@ -878,7 +876,7 @@ public class BlameGenerator {
* {@link #getSourcePath()}.
*/
public int getSourceStart() {
- return currentSource.regionList.sourceStart;
+ return outRegion.sourceStart;
}
/**
@@ -888,7 +886,7 @@ public class BlameGenerator {
* {@link #getSourcePath()}.
*/
public int getSourceEnd() {
- Region r = currentSource.regionList;
+ Region r = outRegion;
return r.sourceStart + r.length;
}
@@ -897,7 +895,7 @@ public class BlameGenerator {
* blamed for providing. Line numbers use 0 based indexing.
*/
public int getResultStart() {
- return currentSource.regionList.resultStart;
+ return outRegion.resultStart;
}
/**
@@ -908,7 +906,7 @@ public class BlameGenerator {
* than {@link #getResultStart()}.
*/
public int getResultEnd() {
- Region r = currentSource.regionList;
+ Region r = outRegion;
return r.resultStart + r.length;
}
@@ -919,7 +917,7 @@ public class BlameGenerator {
* {@code getSourceEnd() - getSourceStart()}.
*/
public int getRegionLength() {
- return currentSource.regionList.length;
+ return outRegion.length;
}
/**
@@ -930,7 +928,7 @@ public class BlameGenerator {
* applications will want the result contents for display to users.
*/
public RawText getSourceContents() {
- return currentSource.sourceText;
+ return outCandidate.sourceText;
}
/**
@@ -951,7 +949,8 @@ public class BlameGenerator {
public void release() {
revPool.release();
queue = null;
- currentSource = null;
+ outCandidate = null;
+ outRegion = null;
}
private boolean find(RevCommit commit, PathFilter path) throws IOException {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameResult.java
index 2d445fd7b2..faaa227b48 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameResult.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameResult.java
@@ -290,6 +290,10 @@ public class BlameResult {
BlameGenerator gen = generator;
if (gen == null)
return;
+ if (start == 0 && end == resultContents.size()) {
+ computeAll();
+ return;
+ }
while (start < end) {
if (hasSourceData(start, end))
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/Candidate.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/Candidate.java
index a652278d05..c7c34f0a3a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/Candidate.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/Candidate.java
@@ -49,6 +49,7 @@ import org.eclipse.jgit.blame.ReverseWalk.ReverseCommit;
import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.diff.EditList;
import org.eclipse.jgit.diff.RawText;
+import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
@@ -56,6 +57,7 @@ import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevFlag;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.filter.PathFilter;
/**
@@ -114,6 +116,10 @@ class Candidate {
recursivePath = path.shouldBeRecursive();
}
+ void beginResult(RevWalk rw) throws MissingObjectException, IOException {
+ rw.parseBody(sourceCommit);
+ }
+
int getParentCount() {
return sourceCommit.getParentCount();
}
@@ -406,6 +412,11 @@ class Candidate {
}
@Override
+ void beginResult(RevWalk rw) {
+ // Blob candidates have nothing to prepare.
+ }
+
+ @Override
int getParentCount() {
return parent != null ? 1 : 0;
}