Top Description Inners Fields Constructors Methods
org.eclipse.jgit.diff

public Class DiffFormatter

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Known Direct Subclasses
org.eclipse.jgit.diff.PatchIdDiffFormatter
Static Imports
org.eclipse.jgit.diff.DiffEntry.ChangeType.ADD, .DiffEntry.ChangeType.COPY, .DiffEntry.ChangeType.DELETE, .DiffEntry.ChangeType.MODIFY, .DiffEntry.ChangeType.RENAME, .DiffEntry.Side.NEW, .DiffEntry.Side.OLD, org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH, .Constants.encode, .Constants.encodeASCII, .FileMode.GITLINK

Format a Git style patch script.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private int
private int
private boolean
private RawTextComparator
private int
private static final int
private DiffAlgorithm
private DiffConfig
private static final byte[]
EMPTY

Magic return content indicating it is empty or no content present.

private String
private static final byte[]
private String
private final OutputStream
private TreeFilter
private ProgressMonitor
private Boolean
private ObjectReader
private RenameDetector
private Repository
private ContentSource.Pair

Constructor Summary

AccessConstructor and Description
public
DiffFormatter(OutputStream
the stream the formatter will write line data to. This stream should have buffering arranged by the caller, as many small writes are performed to it.
out
)

Create a new formatter with a default level of context.

Method Summary

Modifier and TypeMethod and Description
private void
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

private boolean
combineA(List<Edit> e, int i)

private boolean
combineB(List<Edit> e, int i)

private DiffFormatter.FormatResult
private List<DiffEntry>
private EditList
private static boolean
end(Edit edit, int a, int b)

private int
findCombinedEnd(List<Edit> edits, int i)

public void
flush()

Flush the underlying output stream of this formatter.

public void
format(AnyObjectId
the old (or previous) side or null
a
,
AnyObjectId
the new (or updated) side or null
b
)

Format the differences between two trees.

public void
format(RevTree
the old (or previous) side or null
a
,
RevTree
the new (or updated) side or null
b
)

Format the differences between two trees.

public void
format(AbstractTreeIterator
the old (or previous) side or null
a
,
AbstractTreeIterator
the new (or updated) side or null
b
)

Format the differences between two trees.

public void
format(List<? extends DiffEntry>
entries describing the affected files.
entries
)

Format a patch script from a list of difference entries.

public void
format(DiffEntry
the entry to be formatted.
ent
)

Format a patch script for one file entry.

private String
public void
format(FileHeader
existing file header containing the header lines to copy.
head
,
RawText
text source for the pre-image version of the content. This must match the content of org.eclipse.jgit.patch.FileHeader#getOldId().
a
,
RawText
text source for the post-image version of the content. This must match the content of org.eclipse.jgit.patch.FileHeader#getNewId().
b
,
DiffDriver
the diff driver used to obtain function names in hunk headers
diffDriver
)

Format a patch script, reusing a previously parsed FileHeader.

public void
format(FileHeader
existing file header containing the header lines to copy.
head
,
RawText
text source for the pre-image version of the content. This must match the content of org.eclipse.jgit.patch.FileHeader#getOldId().
a
,
RawText
text source for the post-image version of the content. This must match the content of org.eclipse.jgit.patch.FileHeader#getNewId().
b
)

Format a patch script, reusing a previously parsed FileHeader.

public void
format(EditList
some differences which have been calculated between A and B
edits
,
RawText
the text A which was compared
a
,
RawText
the text B which was compared
b
)

Formats a list of edits in unified diff format

public void
format(EditList
some differences which have been calculated between A and B
edits
,
RawText
the text A which was compared
a
,
RawText
the text B which was compared
b
,
DiffDriver
the diff driver used to obtain function names in hunk headers
diffDriver
)

Formats a list of edits in unified diff format

protected void
formatGitDiffFirstHeaderLine(ByteArrayOutputStream
The stream the formatter will write the first header line to
o
,
final DiffEntry.ChangeType type, final String
old path to the file
oldPath
,
final String
new path to the file
newPath
)

Output the first header line

private void
protected void
formatIndexLine(OutputStream
the stream the formatter will write line data to
o
,
DiffEntry
the DiffEntry to create the FileHeader for
ent
)

Format index line

private void
private DiffDriver
private static TreeFilter
private String
getFuncName(RawText text, int startAt, DiffDriver diffDriver)

public String

Returns:

the prefix
getNewPrefix
()

Get the prefix applied in front of new file paths.

public String

Returns:

the prefix
getOldPrefix
()

Get the prefix applied in front of old file paths.

protected OutputStream

Returns:

the stream we are outputting data to
getOutputStream
()

Get output stream

public TreeFilter

Returns:

the current path filter
getPathFilter
()

Get path filter

public RenameDetector

Returns:

the rename detector if rename detection is enabled
getRenameDetector
()

Get rename detector

private boolean
public boolean

Returns:

true if rename detection is enabled
isDetectRenames
()

Get if rename detection is enabled

private static boolean
isEndOfLineMissing(RawText text, int line)

private static boolean
private AbstractTreeIterator
private boolean
matchesAny(List<Pattern> patterns, String text)

private RawText
private String
public List<DiffEntry>

Returns:

the paths that are different.
scan
(AnyObjectId
the old (or previous) side or null
a
,
AnyObjectId
the new (or updated) side or null
b
)

Determine the differences between two trees.

public List<DiffEntry>

Returns:

the paths that are different.
scan
(RevTree
the old (or previous) side or null
a
,
RevTree
the new (or updated) side or null
b
)

Determine the differences between two trees.

public List<DiffEntry>

Returns:

the paths that are different.
scan
(AbstractTreeIterator
the old (or previous) side.
a
,
AbstractTreeIterator
the new (or updated) side.
b
)

Determine the differences between two trees.

public void
setAbbreviationLength(int
number of digits to show in an ObjectId.
count
)

Change the number of digits to show in an ObjectId.

public void
setBinaryFileThreshold(int
the limit, in bytes. Files larger than this size will be assumed to be binary, even if they aren't.
threshold
)

Set maximum file size for text files.

public void
setContext(int
number of lines of context to see before the first modification and after the last modification within a hunk of the modified file.
lineCount
)

Change the number of lines of context to display.

public void
setDetectRenames(boolean
if rename detection should be enabled.
on
)

Enable or disable rename detection.

public void
setDiffAlgorithm(DiffAlgorithm
the algorithm to produce text file differences.
alg
)

Set the algorithm that constructs difference output.

public void
setDiffComparator(RawTextComparator
The equivalence function used to determine if two lines of text are identical. The function can be changed to ignore various types of whitespace.
cmp
)

Set the line equivalence function for text file differences.

public void
setNewPrefix(String
the prefix in front of new paths. Typically this is the standard string "b/", but may be any prefix desired by the caller. Must not be null. Use the empty string to have no prefix at all.
prefix
)

Set the prefix applied in front of new file paths.

public void
setOldPrefix(String
the prefix in front of old paths. Typically this is the standard string "a/", but may be any prefix desired by the caller. Must not be null. Use the empty string to have no prefix at all.
prefix
)

Set the prefix applied in front of old file paths.

public void
setPathFilter(TreeFilter
the tree filter to apply.
filter
)

Set the filter to produce only specific paths.

public void
setProgressMonitor(ProgressMonitor
progress monitor to receive rename detection status through.
pm
)

Set the progress monitor for long running rename detection.

public void
setQuotePaths(boolean
whether to quote path names
quote
)

Sets whether or not path names should be quoted.

public void
setReader(ObjectReader
source reader holding referenced objects. Caller is responsible for closing the reader.
reader
,
Config
config specifying diff algorithm and rename detection options.
cfg
)

Set the repository the formatter can load object contents from.

private void
setReader(ObjectReader reader, Config cfg, boolean closeReader)

public void
setRepository(Repository
source repository holding referenced objects.
repository
)

Set the repository the formatter can load object contents from.

private ContentSource
public FileHeader

Returns:

a FileHeader representing the DiffEntry. The FileHeader's buffer will contain only the header of the diff output. It will also contain one org.eclipse.jgit.patch.HunkHeader.
toFileHeader
(DiffEntry
the DiffEntry to create the FileHeader for
ent
)

Creates a org.eclipse.jgit.patch.FileHeader representing the given org.eclipse.jgit.diff.DiffEntry

This method does not use the OutputStream associated with this DiffFormatter instance.

private List<DiffEntry>
protected void
writeAddedLine(RawText
RawText for accessing raw data
text
,
int
the line number within text
line
)

Output an added line.

protected void
writeContextLine(RawText
RawText for accessing raw data
text
,
int
the line number within text
line
)

Output a line of context (unmodified line).

private static byte[]
protected void
writeHunkHeader(int
within first source
aStartLine
,
int
within first source
aEndLine
,
int
within second source
bStartLine
,
int
within second source
bEndLine
)

Output a hunk header

protected void
writeHunkHeader(int
within first source
aStartLine
,
int
within first source
aEndLine
,
int
within second source
bStartLine
,
int
within second source
bEndLine
,
String
function name of this hunk
funcName
)

Output a hunk header

protected void
writeLine(final char
prefix before the line, typically '-', '+', ' '.
prefix
,
final RawText
the text object to obtain the line from.
text
,
final int
line number to output.
cur
)

Write a standard patch script line.

private void
writeRange(char prefix, int begin, int cnt)

protected void
writeRemovedLine(RawText
RawText for accessing raw data
text
,
int
the line number within text
line
)

Output a removed line

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait