Applications that want a simple one-shot computation of blame for a file
should use computeBlameResult() to prepare the entire result in one
method call. This may block for significant time as the history of the
repository must be traversed until information is gathered for every line.
Applications that want more incremental update behavior may use either the
raw next() streaming approach supported by this class, or construct
a org. using
org. and
incrementally construct the result with
org..
This class is not thread-safe.
An instance of BlameGenerator can only be used once. To blame multiple files the application must create a new BlameGenerator.
During blame processing there are two files involved:
The blame algorithm is implemented by initially assigning responsibility for all lines of the result to the starting commit. A difference against the commit's ancestor is computed, and responsibility is passed to the ancestor commit for any lines that are common. The starting commit is blamed only for the lines that do not appear in the ancestor, if any. The loop repeats using the ancestor, until there are no more lines to acquire information on, or the file's creation point is discovered in history.
| Modifier and Type | Class and Description |
|---|---|
| public static class | BlameGenerator.
Stats about the work done by the generator |
| Modifier and Type | Field and Description |
|---|---|
| private final BlameCache | |
| private DiffAlgorithm | |
| private final MutableObjectId | |
| private Candidate | outCandidate
Blame is currently assigned to this source. |
| private Region | |
| private Candidate | queue
Potential candidates, sorted by commit time descending. |
| private ObjectReader | |
| private int | remaining
Number of lines that still need to be discovered. |
| private RenameDetector | |
| private final Repository | |
| private final PathFilter | |
| private RevWalk | revPool
Revision pool used to acquire commits from. |
| private RevFlag | SEEN
Indicates the commit was put into the queue at least once. |
| private final BlameGenerator. | |
| private RawTextComparator | |
| private TreeWalk | |
| private boolean | useCache
Blame in reverse order needs the source lines, but we don't have them in the cache. |
| Access | Constructor and Description |
|---|---|
| public | BlameGenerator(Repository
repository to access revision data from. repository, String initial path of the file to start scanning (relative to the
repository). path)Create a blame generator for the repository and path (relative to repository) |
| public | BlameGenerator(Repository
repository to access revision data from. repository, String initial path of the file to start scanning (relative to the
repository). path, BlameCache previously calculated blames. This generator will *not*
populate it, just consume it. blameCache)Create a blame generator for the repository and path (relative to repository) |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| public void | close()
Implements java. Closes this resource, relinquishing any underlying resources. |
| public BlameResult | Returns: the complete result. Null if no file exists for the given path.Execute the generator in a blocking fashion until all data is ready. |
| private boolean | |
| private boolean | |
| private DiffEntry | |
| private static byte[] | |
| private List | |
| public int | Returns: number of lines in the current region being blamed togetSourceCommit(). This is always the value of the
expression getResultEnd() - getResultStart(), but also
getSourceEnd() - getSourceStart().Get number of lines in the current region being blamed to
|
| public RenameDetector | Returns: the rename detector, ornull if
setFollowFileRenames(false).Obtain the RenameDetector, allowing the application to configure its settings for rename score and breaking behavior. |
| public int | |
| public Repository | |
| public RawText | Returns: complete file contents of the result file blame is annotating. This value is accessible only after being configured and only immediately before the first call tonext(). Returns
null if the path does not exist.Get complete file contents of the result file blame is annotating |
| public int | Returns: one past the range of the result thatgetSourceCommit()
has been blamed for providing. Line numbers use 0 based indexing.
Because a source cannot be blamed for an empty region of the
result, getResultEnd() is always at least one larger
than getResultStart().Get one past the range of the result that |
| public String | |
| public int | Returns: first line of the result thatgetSourceCommit() has been
blamed for providing. Line numbers use 0 based indexing.Get first line of the result that |
| public PersonIdent | |
| public RevCommit | Returns: current revision being blamed.Get the revision blamed for the current region. |
| public PersonIdent | |
| public RawText | Returns: complete contents of the source file blamed for the current output region. This is the contents ofgetSourcePath()
within getSourceCommit(). The source contents is
temporarily available as an artifact of the blame algorithm. Most
applications will want the result contents for display to users.Get complete contents of the source file blamed for the current output region |
| public int | Returns: one past the range of the source data that has been blamed for the current region. This is line number of where the region was added duringgetSourceCommit() in file
getSourcePath().Get one past the range of the source data that has been blamed for the current region This value is not reliable when the generator is reusing cached values. |
| public String | |
| public int | Returns: first line of the source data that has been blamed for the current region. This is line number of where the region was added duringgetSourceCommit() in file
getSourcePath().Get first line of the source data that has been blamed for the current region This value is not reliable when the generator is reusing cached values. |
| public BlameGenerator. | |
| private void | |
| private static final boolean | |
| private static boolean | |
| public RevFlag | |
| public boolean | Returns: true if the generator has found a region's source. The getSource* andgetResultStart(), getResultEnd() methods
can be used to inspect the region found. False if there are no
more regions to describe.Step the blame algorithm one iteration. |
| private Candidate | |
| public BlameGenerator | Returns: thisPushes HEAD, index, and working tree as appropriate for blaming the file
given in the constructor |
| private boolean | |
| private boolean | |
| public BlameGenerator | |
| public BlameGenerator | |
| public BlameGenerator | Returns: thisdescription of the blob revision, such as "Working Tree". description, AnyObjectId may be a commit or a blob. id)Push a candidate object onto the generator's traversal stack. |
| private void | |
| private void | |
| private boolean | |
| public BlameGenerator | Returns: thisoldest commit to traverse from. The result file will be loaded
from this commit's tree. start, AnyObjectId most recent commit to stop traversal at. Usually an active
branch tip, tag, or HEAD. end)Configure the generator to compute reverse blame (history of deletes). |
| public BlameGenerator | Returns: thisoldest commit to traverse from. The result file will be loaded
from this commit's tree. start, Collection<? extends ObjectId> most recent commits to stop traversal at. Usually an active
branch tip, tag, or HEAD. end)Configure the generator to compute reverse blame (history of deletes). |
| private boolean | |
| public BlameGenerator | Returns: thisDifference algorithm to use when comparing revisions. |
| public BlameGenerator | Returns: thisenable following. follow)Enable (or disable) following file renames, on by default. |
| public BlameGenerator | Returns: thisText comparator to use when comparing revisions. |
| public void | setUseCache(boolean
should this generator use the cache. useCache)Enable/disable the use of cache (if present). |
| private boolean | |
| private boolean |
| blameCache | back to summary |
|---|---|
| private final BlameCache blameCache | |
| diffAlgorithm | back to summary |
|---|---|
| private DiffAlgorithm diffAlgorithm | |
| idBuf | back to summary |
|---|---|
| private final MutableObjectId idBuf | |
| outCandidate | back to summary |
|---|---|
| private Candidate outCandidate Blame is currently assigned to this source. | |
| outRegion | back to summary |
|---|---|
| private Region outRegion | |
| queue | back to summary |
|---|---|
| private Candidate queue Potential candidates, sorted by commit time descending. | |
| reader | back to summary |
|---|---|
| private ObjectReader reader | |
| remaining | back to summary |
|---|---|
| private int remaining Number of lines that still need to be discovered. | |
| renameDetector | back to summary |
|---|---|
| private RenameDetector renameDetector | |
| repository | back to summary |
|---|---|
| private final Repository repository | |
| resultPath | back to summary |
|---|---|
| private final PathFilter resultPath | |
| revPool | back to summary |
|---|---|
| private RevWalk revPool Revision pool used to acquire commits from. | |
| SEEN | back to summary |
|---|---|
| private RevFlag SEEN Indicates the commit was put into the queue at least once. | |
| stats | back to summary |
|---|---|
| private final BlameGenerator. | |
| textComparator | back to summary |
|---|---|
| private RawTextComparator textComparator | |
| treeWalk | back to summary |
|---|---|
| private TreeWalk treeWalk | |
| useCache | back to summary |
|---|---|
| private boolean useCache Blame in reverse order needs the source lines, but we don't have them in the cache. We need to ignore the cache in that case. | |
| BlameGenerator | back to summary |
|---|---|
| public BlameGenerator(Repository repository, String path) Create a blame generator for the repository and path (relative to repository)
| |
| BlameGenerator | back to summary |
|---|---|
| public BlameGenerator(Repository repository, String path, BlameCache blameCache) Create a blame generator for the repository and path (relative to repository)
| |
| blameEntireRegionOnParent | back to summary |
|---|---|
| private boolean blameEntireRegionOnParent(Candidate n, RevCommit parent) | |
| close | back to summary |
|---|---|
| public void close() Implements java. Doc from java. Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
Release the current blame session.
| |
| computeBlameResult | back to summary |
|---|---|
| public BlameResult computeBlameResult() throws IOException Execute the generator in a blocking fashion until all data is ready.
| |
| done | back to summary |
|---|---|
| private boolean done() | |
| find | back to summary |
|---|---|
| private boolean find(RevCommit commit, PathFilter path) throws IOException | |
| findRename | back to summary |
|---|---|
| private DiffEntry findRename(RevCommit parent, RevCommit commit, PathFilter path) throws IOException | |
| getBytes | back to summary |
|---|---|
| private static byte[] getBytes(String path, InputStream in, long maxLength) throws IOException | |
| getHeads | back to summary |
|---|---|
| private List | |
| getRegionLength | back to summary |
|---|---|
| public int getRegionLength() Get number of lines in the current region being blamed to
| |
| getRenameDetector | back to summary |
|---|---|
| public RenameDetector getRenameDetector() Obtain the RenameDetector, allowing the application to configure its settings for rename score and breaking behavior.
| |
| getRenameScore | back to summary |
|---|---|
| public int getRenameScore() Get rename score
| |
| getRepository | back to summary |
|---|---|
| public Repository getRepository() Get repository
| |
| getResultContents | back to summary |
|---|---|
| public RawText getResultContents() throws IOException Get complete file contents of the result file blame is annotating
| |
| getResultEnd | back to summary |
|---|---|
| public int getResultEnd() Get one past the range of the result that
| |
| getResultPath | back to summary |
|---|---|
| public String getResultPath() Get result path
| |
| getResultStart | back to summary |
|---|---|
| public int getResultStart() Get first line of the result that
| |
| getSourceAuthor | back to summary |
|---|---|
| public PersonIdent getSourceAuthor() Get source author
| |
| getSourceCommit | back to summary |
|---|---|
| public RevCommit getSourceCommit() Get the revision blamed for the current region. 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).
| |
| getSourceCommitter | back to summary |
|---|---|
| public PersonIdent getSourceCommitter() Get source committer
| |
| getSourceContents | back to summary |
|---|---|
| public RawText getSourceContents() Get complete contents of the source file blamed for the current output region
| |
| getSourceEnd | back to summary |
|---|---|
| public int getSourceEnd() Get one past the range of the source data that has been blamed for the current region This value is not reliable when the generator is reusing cached values. Cache doesn't keep the source lines, the returned value is based on the result and can be off if the region moved in previous commits.
| |
| getSourcePath | back to summary |
|---|---|
| public String getSourcePath() Get source path
| |
| getSourceStart | back to summary |
|---|---|
| public int getSourceStart() Get first line of the source data that has been blamed for the current region This value is not reliable when the generator is reusing cached values. Cache doesn't keep the source lines, the returned value is based on the result and can be off if the region moved in previous commits.
| |
| getStats | back to summary |
|---|---|
| public BlameGenerator. Stats about this generator
| |
| initRevPool | back to summary |
|---|---|
| private void initRevPool(boolean reverse) | |
| isFile | back to summary |
|---|---|
| private static final boolean isFile(int rawMode) | |
| isRename | back to summary |
|---|---|
| private static boolean isRename(DiffEntry ent) | |
| newFlag | back to summary |
|---|---|
| public RevFlag newFlag(String name) Allocate a new RevFlag for use by the caller. | |
| next | back to summary |
|---|---|
| public boolean next() throws IOException Step the blame algorithm one iteration.
| |
| pop | back to summary |
|---|---|
| private Candidate pop() | |
| prepareHead | back to summary |
|---|---|
| public BlameGenerator prepareHead() throws NoHeadException, IOException Pushes HEAD, index, and working tree as appropriate for blaming the file
given in the constructor
| |
| processMerge | back to summary |
|---|---|
| private boolean processMerge(Candidate n) throws IOException | |
| processOne | back to summary |
|---|---|
| private boolean processOne(Candidate n) throws IOException | |
| push | back to summary |
|---|---|
| public BlameGenerator push(String description, byte[] contents) throws IOException Push a candidate blob onto the generator's traversal stack. Candidates should be pushed in history order from oldest-to-newest. Applications should push the starting commit first, then the index revision (if the index is interesting), and finally the working tree copy (if the working tree is interesting).
| |
| push | back to summary |
|---|---|
| public BlameGenerator push(String description, RawText contents) throws IOException Push a candidate blob onto the generator's traversal stack. Candidates should be pushed in history order from oldest-to-newest. Applications should push the starting commit first, then the index revision (if the index is interesting), and finally the working tree copy (if the working tree is interesting).
| |
| push | back to summary |
|---|---|
| public BlameGenerator push(String description, AnyObjectId id) throws IOException Push a candidate object onto the generator's traversal stack. Candidates should be pushed in history order from oldest-to-newest. Applications should push the starting commit first, then the index revision (if the index is interesting), and finally the working tree copy (if the working tree is interesting).
| |
| push | back to summary |
|---|---|
| private void push(Candidate. | |
| push | back to summary |
|---|---|
| private void push(Candidate toInsert) | |
| result | back to summary |
|---|---|
| private boolean result(Candidate n) throws IOException | |
| reverse | back to summary |
|---|---|
| public BlameGenerator reverse(AnyObjectId start, AnyObjectId end) throws IOException Configure the generator to compute reverse blame (history of deletes).
This method is expensive as it immediately runs a RevWalk over the
history spanning the expression
A reverse blame may produce multiple sources for the same result line,
each of these is a descendant commit that removed the line, typically
this occurs when the same deletion appears in multiple side branches such
as due to a cherry-pick. Applications relying on reverse should use
| |
| reverse | back to summary |
|---|---|
| public BlameGenerator reverse(AnyObjectId start, Collection<? extends ObjectId> end) throws IOException Configure the generator to compute reverse blame (history of deletes).
This method is expensive as it immediately runs a RevWalk over the
history spanning the expression
A reverse blame may produce multiple sources for the same result line,
each of these is a descendant commit that removed the line, typically
this occurs when the same deletion appears in multiple side branches such
as due to a cherry-pick. Applications relying on reverse should use
| |
| reverseResult | back to summary |
|---|---|
| private boolean reverseResult(Candidate parent, Candidate source) throws IOException | |
| setDiffAlgorithm | back to summary |
|---|---|
| public BlameGenerator setDiffAlgorithm(DiffAlgorithm algorithm) Difference algorithm to use when comparing revisions.
| |
| setFollowFileRenames | back to summary |
|---|---|
| public BlameGenerator setFollowFileRenames(boolean follow) Enable (or disable) following file renames, on by default.
If true renames are followed using the standard FollowFilter behavior
used by RevWalk (which matches
| |
| setTextComparator | back to summary |
|---|---|
| public BlameGenerator setTextComparator(RawTextComparator comparator) Text comparator to use when comparing revisions.
| |
| setUseCache | back to summary |
|---|---|
| public void setUseCache(boolean useCache) Enable/disable the use of cache (if present). Enabled by default. If caller need source line numbers, the generator cannot use the cache (source lines are not there). Use this method to disable the cache in that case.
| |
| split | back to summary |
|---|---|
| private boolean split(Candidate parent, Candidate source) throws IOException | |
| splitBlameWithParent | back to summary |
|---|---|
| private boolean splitBlameWithParent(Candidate n, RevCommit parent) throws IOException | |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private int | candidatesVisited
Candidates taken from the queue |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: number of candidates taken from the queueNumber of candidates taken from the queue The generator could signal it's done without exhausting all candidates if there is no more remaining lines or the last visited candidate is found in the cache. |
| public boolean | Returns: true if we used results from the cacheThe generator found a blamed version in the cache |
| cacheHit | back to summary |
|---|---|
| private boolean cacheHit | |
| candidatesVisited | back to summary |
|---|---|
| private int candidatesVisited Candidates taken from the queue | |
| Stats | back to summary |
|---|---|
| public Stats() | |
| getCandidatesVisited | back to summary |
|---|---|
| public int getCandidatesVisited() Number of candidates taken from the queue The generator could signal it's done without exhausting all candidates if there is no more remaining lines or the last visited candidate is found in the cache.
| |
| isCacheHit | back to summary |
|---|---|
| public boolean isCacheHit() The generator found a blamed version in the cache
| |