Top Description Fields Constructors Methods
org.eclipse.jgit.patch

public Class Patch

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.lib.Constants.encodeASCII, org.eclipse.jgit.patch.FileHeader.NEW_NAME, .FileHeader.OLD_NAME, .FileHeader.isHunkHdr, org.eclipse.jgit.util.RawParseUtils.match, .RawParseUtils.nextLF

A parsed collection of org.eclipse.jgit.patch.FileHeaders from a unified diff patch file

Field Summary

Modifier and TypeField and Description
private static final byte[][]
private static final byte[]
private static final byte[]
private static final byte[]
pack-priv static final byte[]
private final List<FormatError>
errors

Formatting errors, if any were identified.

private final List<FileHeader>
files

The files, in the order they were parsed out of the input.

private static final byte[]
pack-priv static final byte[]

Constructor Summary

AccessConstructor and Description
public
Patch()

Create an empty patch.

Method Summary

Modifier and TypeMethod and Description
public void
addError(FormatError
the error description.
err
)

Add a formatting error to this patch script.

public void
addFile(FileHeader
the header of the file.
fh
)

Add a single file to this patch.

pack-priv void
error(byte[] buf, int ptr, String msg)

public List<FormatError>

Returns:

collection of formatting errors, if any.
getErrors
()

Get collection of formatting errors.

public List<? extends FileHeader>

Returns:

list of files described in the patch, in occurrence order.
getFiles
()

Get list of files described in the patch, in occurrence order.

private static boolean
matchAny(final byte[] buf, final int c, final byte[][] srcs)

public void
parse(InputStream
the stream to read the patch data from. The stream is read until EOF is reached.
is
)

Parse a patch received from an InputStream.

public void
parse(byte[]
the buffer to parse.
buf
,
int
starting position to parse from.
ptr
,
int
1 past the last position to end parsing. The total length to be parsed is end - ptr.
end
)

Parse a patch stored in a byte[].

private int
parseDiffCombined(final byte[] hdr, final byte[] buf, final int start, final int end)

private int
parseDiffGit(byte[] buf, int start, int end)

private int
parseFile(byte[] buf, int c, int end)

private int
parseGitBinary(FileHeader fh, int c, int end)

private int
parseHunks(FileHeader fh, int c, int end)

private int
parseTraditionalPatch(final byte[] buf, final int start, final int end)

private static byte[]
private static int
skipFile(byte[] buf, int ptr)

pack-priv void
warn(byte[] buf, int ptr, String msg)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BIN_HEADERSback to summary
private static final byte[][] BIN_HEADERS
BIN_TRAILERback to summary
private static final byte[] BIN_TRAILER
DIFF_CCback to summary
private static final byte[] DIFF_CC
DIFF_COMBINEDback to summary
private static final byte[] DIFF_COMBINED
DIFF_GITback to summary
pack-priv static final byte[] DIFF_GIT
errorsback to summary
private final List<FormatError> errors

Formatting errors, if any were identified.

filesback to summary
private final List<FileHeader> files

The files, in the order they were parsed out of the input.

GIT_BINARYback to summary
private static final byte[] GIT_BINARY

Constructor Detail

Patchback to summary
public Patch()

Create an empty patch.

Method Detail

addErrorback to summary
public void addError(FormatError err)

Add a formatting error to this patch script.

Parameters
err:FormatError

the error description.

addFileback to summary
public void addFile(FileHeader fh)

Add a single file to this patch.

Typically files should be added by parsing the text through one of this class's parse methods.

Parameters
fh:FileHeader

the header of the file.

errorback to summary
pack-priv void error(byte[] buf, int ptr, String msg)
getErrorsback to summary
public List<FormatError> getErrors()

Get collection of formatting errors.

Returns:List<FormatError>

collection of formatting errors, if any.

getFilesback to summary
public List<? extends FileHeader> getFiles()

Get list of files described in the patch, in occurrence order.

Returns:List<? extends FileHeader>

list of files described in the patch, in occurrence order.

matchAnyback to summary
private static boolean matchAny(final byte[] buf, final int c, final byte[][] srcs)
parseback to summary
public void parse(InputStream is) throws IOException

Parse a patch received from an InputStream.

Multiple parse calls on the same instance will concatenate the patch data, but each parse input must start with a valid file header (don't split a single file across parse calls).

Parameters
is:InputStream

the stream to read the patch data from. The stream is read until EOF is reached.

Exceptions
IOException:
there was an error reading from the input stream.
parseback to summary
public void parse(byte[] buf, int ptr, int end)

Parse a patch stored in a byte[].

Multiple parse calls on the same instance will concatenate the patch data, but each parse input must start with a valid file header (don't split a single file across parse calls).

Parameters
buf:byte[]

the buffer to parse.

ptr:int

starting position to parse from.

end:int

1 past the last position to end parsing. The total length to be parsed is end - ptr.

parseDiffCombinedback to summary
private int parseDiffCombined(final byte[] hdr, final byte[] buf, final int start, final int end)
parseDiffGitback to summary
private int parseDiffGit(byte[] buf, int start, int end)
parseFileback to summary
private int parseFile(byte[] buf, int c, int end)
parseGitBinaryback to summary
private int parseGitBinary(FileHeader fh, int c, int end)
parseHunksback to summary
private int parseHunks(FileHeader fh, int c, int end)
parseTraditionalPatchback to summary
private int parseTraditionalPatch(final byte[] buf, final int start, final int end)
readFullyback to summary
private static byte[] readFully(InputStream is) throws IOException
skipFileback to summary
private static int skipFile(byte[] buf, int ptr)
warnback to summary
pack-priv void warn(byte[] buf, int ptr, String msg)