Package org.eclipse.jgit.patch
Class Patch
- java.lang.Object
-
- org.eclipse.jgit.patch.Patch
-
public class Patch extends java.lang.Object
A parsed collection ofFileHeader
s from a unified diff patch file
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[][]
BIN_HEADERS
private static byte[]
BIN_TRAILER
private static byte[]
DIFF_CC
private static byte[]
DIFF_COMBINED
(package private) static byte[]
DIFF_GIT
private java.util.List<FormatError>
errors
Formatting errors, if any were identified.private java.util.List<FileHeader>
files
The files, in the order they were parsed out of the input.private static byte[]
GIT_BINARY
(package private) static byte[]
SIG_FOOTER
-
Constructor Summary
Constructors Constructor Description Patch()
Create an empty patch.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addError(FormatError err)
Add a formatting error to this patch script.void
addFile(FileHeader fh)
Add a single file to this patch.(package private) void
error(byte[] buf, int ptr, java.lang.String msg)
java.util.List<FormatError>
getErrors()
Get collection of formatting errors.java.util.List<? extends FileHeader>
getFiles()
Get list of files described in the patch, in occurrence order.private static boolean
matchAny(byte[] buf, int c, byte[][] srcs)
void
parse(byte[] buf, int ptr, int end)
Parse a patch stored in a byte[].void
parse(java.io.InputStream is)
Parse a patch received from an InputStream.private int
parseDiffCombined(byte[] hdr, byte[] buf, int start, 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(byte[] buf, int start, int end)
private static byte[]
readFully(java.io.InputStream is)
private static int
skipFile(byte[] buf, int ptr)
(package private) void
warn(byte[] buf, int ptr, java.lang.String msg)
-
-
-
Field Detail
-
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
private final java.util.List<FileHeader> files
The files, in the order they were parsed out of the input.
-
errors
private final java.util.List<FormatError> errors
Formatting errors, if any were identified.
-
-
Method Detail
-
addFile
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
- the header of the file.
-
getFiles
public java.util.List<? extends FileHeader> getFiles()
Get list of files described in the patch, in occurrence order.- Returns:
- list of files described in the patch, in occurrence order.
-
addError
public void addError(FormatError err)
Add a formatting error to this patch script.- Parameters:
err
- the error description.
-
getErrors
public java.util.List<FormatError> getErrors()
Get collection of formatting errors.- Returns:
- collection of formatting errors, if any.
-
parse
public void parse(java.io.InputStream is) throws java.io.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
- the stream to read the patch data from. The stream is read until EOF is reached.- Throws:
java.io.IOException
- there was an error reading from the input stream.
-
readFully
private static byte[] readFully(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.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
private int parseHunks(FileHeader fh, int c, int end)
-
parseGitBinary
private int parseGitBinary(FileHeader fh, int c, int end)
-
warn
void warn(byte[] buf, int ptr, java.lang.String msg)
-
error
void error(byte[] buf, int ptr, java.lang.String msg)
-
matchAny
private static boolean matchAny(byte[] buf, int c, byte[][] srcs)
-
-