Package org.eclipse.jgit.patch
Class Patch
java.lang.Object
org.eclipse.jgit.patch.Patch
A parsed collection of
FileHeaders from a
unified diff patch file-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[][]private static final byte[]private static final byte[]private static final byte[](package private) static final byte[]private final List<FormatError>Formatting errors, if any were identified.private final List<FileHeader>The files, in the order they were parsed out of the input.private static final byte[](package private) static final byte[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddError(FormatError err) Add a formatting error to this patch script.voidaddFile(FileHeader fh) Add a single file to this patch.(package private) voidGet collection of formatting errors.List<? extends FileHeader>getFiles()Get list of files described in the patch, in occurrence order.private static booleanmatchAny(byte[] buf, int c, byte[][] srcs) voidparse(byte[] buf, int ptr, int end) Parse a patch stored in a byte[].voidparse(InputStream is) Parse a patch received from an InputStream.private intparseDiffCombined(byte[] hdr, byte[] buf, int start, int end) private intparseDiffGit(byte[] buf, int start, int end) private intparseFile(byte[] buf, int c, int end) private intparseGitBinary(FileHeader fh, int c, int end) private intparseHunks(FileHeader fh, int c, int end) private intparseTraditionalPatch(byte[] buf, int start, int end) private static byte[]readFully(InputStream is) private static intskipFile(byte[] buf, int ptr) (package private) void
-
Field Details
-
DIFF_GIT
static final byte[] DIFF_GIT -
DIFF_CC
private static final byte[] DIFF_CC -
DIFF_COMBINED
private static final byte[] DIFF_COMBINED -
BIN_HEADERS
private static final byte[][] BIN_HEADERS -
BIN_TRAILER
private static final byte[] BIN_TRAILER -
GIT_BINARY
private static final byte[] GIT_BINARY -
SIG_FOOTER
static final byte[] SIG_FOOTER -
files
The files, in the order they were parsed out of the input. -
errors
Formatting errors, if any were identified.
-
-
Constructor Details
-
Patch
public Patch()Create an empty patch.
-
-
Method Details
-
addFile
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- the header of the file.
-
getFiles
Get list of files described in the patch, in occurrence order.- Returns:
- list of files described in the patch, in occurrence order.
-
addError
Add a formatting error to this patch script.- Parameters:
err- the error description.
-
getErrors
Get collection of formatting errors.- Returns:
- collection of formatting errors, if any.
-
parse
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- the stream to read the patch data from. The stream is read until EOF is reached.- Throws:
IOException- there was an error reading from the input stream.
-
readFully
- Throws:
IOException
-
parse
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- the buffer to parse.ptr- starting position to parse from.end- 1 past the last position to end parsing. The total length to be parsed isend - ptr.
-
parseFile
private int parseFile(byte[] buf, int c, int end) -
parseDiffGit
private int parseDiffGit(byte[] buf, int start, int end) -
parseDiffCombined
private int parseDiffCombined(byte[] hdr, byte[] buf, int start, int end) -
parseTraditionalPatch
private int parseTraditionalPatch(byte[] buf, int start, int end) -
skipFile
private static int skipFile(byte[] buf, int ptr) -
parseHunks
-
parseGitBinary
-
warn
-
error
-
matchAny
private static boolean matchAny(byte[] buf, int c, byte[][] srcs)
-