Преглед изворни кода

blame: Do not update candidate regionList during output

Instead of updating the candidate's regionList field to iterate
through the linked list of regions, use a special purpose field
in the BlameGenerator. This allows the candidate to be unmodified.

Change-Id: I2cda031b59220ab603ef82050e741ecbbaa1953f
tags/v3.4.0.201405051725-m7
Shawn Pearce пре 10 година
родитељ
комит
6afae79901
1 измењених фајлова са 24 додато и 21 уклоњено
  1. 24
    21
      org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java

+ 24
- 21
org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java Прегледај датотеку

private int remaining; private int remaining;


/** Blame is currently assigned to this source. */ /** 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 * Create a blame generator for the repository and path (relative to
*/ */
public boolean next() throws IOException { public boolean next() throws IOException {
// If there is a source still pending, produce the next region. // 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; remaining -= r.length;
if (n != null) {
currentSource.regionList = n;
if (r.next != null) {
outRegion = r.next;
return true; 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, // If there are no lines remaining, the entire result is done,
private boolean result(Candidate n) throws IOException { private boolean result(Candidate n) throws IOException {
if (n.sourceCommit != null) if (n.sourceCommit != null)
revPool.parseBody(n.sourceCommit); revPool.parseBody(n.sourceCommit);
currentSource = n;
outCandidate = n;
outRegion = n.regionList;
return true; return true;
} }


* @return current revision being blamed. * @return current revision being blamed.
*/ */
public RevCommit getSourceCommit() { public RevCommit getSourceCommit() {
return currentSource.sourceCommit;
return outCandidate.sourceCommit;
} }


/** @return current author being blamed. */ /** @return current author being blamed. */
public PersonIdent getSourceAuthor() { public PersonIdent getSourceAuthor() {
return currentSource.getAuthor();
return outCandidate.getAuthor();
} }


/** @return current committer being blamed. */ /** @return current committer being blamed. */


/** @return path of the file being blamed. */ /** @return path of the file being blamed. */
public String getSourcePath() { public String getSourcePath() {
return currentSource.sourcePath.getPath();
return outCandidate.sourcePath.getPath();
} }


/** @return rename score if a rename occurred in {@link #getSourceCommit}. */ /** @return rename score if a rename occurred in {@link #getSourceCommit}. */
public int getRenameScore() { public int getRenameScore() {
return currentSource.renameScore;
return outCandidate.renameScore;
} }


/** /**
* {@link #getSourcePath()}. * {@link #getSourcePath()}.
*/ */
public int getSourceStart() { public int getSourceStart() {
return currentSource.regionList.sourceStart;
return outRegion.sourceStart;
} }


/** /**
* {@link #getSourcePath()}. * {@link #getSourcePath()}.
*/ */
public int getSourceEnd() { public int getSourceEnd() {
Region r = currentSource.regionList;
Region r = outRegion;
return r.sourceStart + r.length; return r.sourceStart + r.length;
} }


* blamed for providing. Line numbers use 0 based indexing. * blamed for providing. Line numbers use 0 based indexing.
*/ */
public int getResultStart() { public int getResultStart() {
return currentSource.regionList.resultStart;
return outRegion.resultStart;
} }


/** /**
* than {@link #getResultStart()}. * than {@link #getResultStart()}.
*/ */
public int getResultEnd() { public int getResultEnd() {
Region r = currentSource.regionList;
Region r = outRegion;
return r.resultStart + r.length; return r.resultStart + r.length;
} }


* {@code getSourceEnd() - getSourceStart()}. * {@code getSourceEnd() - getSourceStart()}.
*/ */
public int getRegionLength() { public int getRegionLength() {
return currentSource.regionList.length;
return outRegion.length;
} }


/** /**
* applications will want the result contents for display to users. * applications will want the result contents for display to users.
*/ */
public RawText getSourceContents() { public RawText getSourceContents() {
return currentSource.sourceText;
return outCandidate.sourceText;
} }


/** /**
public void release() { public void release() {
revPool.release(); revPool.release();
queue = null; queue = null;
currentSource = null;
outCandidate = null;
outRegion = null;
} }


private boolean find(RevCommit commit, PathFilter path) throws IOException { private boolean find(RevCommit commit, PathFilter path) throws IOException {

Loading…
Откажи
Сачувај