Class BlameResult
A result is usually updated incrementally as the BlameGenerator digs back further through history. Applications that want to lay annotations down text to the original source file in a viewer may find the BlameResult structure an easy way to acquire the information, at the expense of keeping tables in memory tracking every line of the result file.
This class is not thread-safe.
During blame processing there are two files involved:
- result - The file whose lines are being examined. This is the revision the user is trying to view blame/annotation information alongside of.
- source - The file that was blamed with supplying one or more lines of data into result. The source may be a different file path (due to copy or rename). Source line numbers may differ from result line numbers due to lines being added/removed in intermediate revisions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BlameGenerator
private int
private RawText
private final String
private final PersonIdent[]
private final RevCommit[]
private final PersonIdent[]
private final int[]
Warning: these are actually 1-based.private final String[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Compute all pending information.int
Compute the next available segment and return the first index.void
computeRange
(int start, int end) Compute until the entire range has been populated.static BlameResult
create
(BlameGenerator gen) Construct a new BlameResult for a generator.void
Throw away thegetResultContents()
.Get result contentsGet result pathgetSourceAuthor
(int idx) Get the author that provided the specified line of the result.getSourceCommit
(int idx) Get the commit that provided the specified line of the result.getSourceCommitter
(int idx) Get the committer that provided the specified line of the result.int
getSourceLine
(int idx) Get the corresponding line number in the source file.getSourcePath
(int idx) Get the file path that provided the specified line of the result.boolean
hasSourceData
(int idx) Check if the given result line has been annotated yet.boolean
hasSourceData
(int start, int end) Check if the given result line has been annotated yet.int
Get last lengthprivate void
loadFrom
(BlameGenerator gen) toString()
-
Field Details
-
resultPath
-
sourceCommits
-
sourceAuthors
-
sourceCommitters
-
sourcePaths
-
sourceLines
private final int[] sourceLinesWarning: these are actually 1-based. -
resultContents
-
generator
-
lastLength
private int lastLength
-
-
Constructor Details
-
BlameResult
BlameResult(BlameGenerator bg, String path, RawText text)
-
-
Method Details
-
create
Construct a new BlameResult for a generator.- Parameters:
gen
- the generator the result will consume records from.- Returns:
- the new result object. null if the generator cannot find the path it starts from.
- Throws:
IOException
- the repository cannot be read.
-
getResultPath
Get result path- Returns:
- path of the file this result annotates
-
getResultContents
Get result contents- Returns:
- contents of the result file, available for display
-
discardResultContents
public void discardResultContents()Throw away thegetResultContents()
. -
hasSourceData
public boolean hasSourceData(int idx) Check if the given result line has been annotated yet.- Parameters:
idx
- line to read data of, 0 based.- Returns:
- true if the data has been annotated, false otherwise.
-
hasSourceData
public boolean hasSourceData(int start, int end) Check if the given result line has been annotated yet.- Parameters:
start
- first index to examine.end
- last index to examine.- Returns:
- true if the data has been annotated, false otherwise.
-
getSourceCommit
Get the commit that provided the specified line of the result.The source commit may be null if the line was blamed to an uncommitted revision, such as the working tree copy, or during a reverse blame if the line survives to the end revision (e.g. the branch tip).
- Parameters:
idx
- line to read data of, 0 based.- Returns:
- commit that provided line
idx
. May be null.
-
getSourceAuthor
Get the author that provided the specified line of the result.- Parameters:
idx
- line to read data of, 0 based.- Returns:
- author that provided line
idx
. May be null.
-
getSourceCommitter
Get the committer that provided the specified line of the result.- Parameters:
idx
- line to read data of, 0 based.- Returns:
- committer that provided line
idx
. May be null.
-
getSourcePath
Get the file path that provided the specified line of the result.- Parameters:
idx
- line to read data of, 0 based.- Returns:
- source file path that provided line
idx
.
-
getSourceLine
public int getSourceLine(int idx) Get the corresponding line number in the source file.- Parameters:
idx
- line to read data of, 0 based.- Returns:
- matching line number in the source file.
-
computeAll
Compute all pending information.- Throws:
IOException
- the repository cannot be read.
-
computeNext
Compute the next available segment and return the first index.Computes one segment and returns to the caller the first index that is available. After return the caller can also inspect
lastLength()
to determine how many lines of the result were computed.- Returns:
- index that is now available. -1 if no more are available.
- Throws:
IOException
- the repository cannot be read.
-
lastLength
public int lastLength()Get last length- Returns:
- length of the last segment found by
computeNext()
-
computeRange
Compute until the entire range has been populated.- Parameters:
start
- first index to examine (inclusive).end
- end index (exclusive).- Throws:
IOException
- the repository cannot be read.
-
toString
-
loadFrom
-