Package org.eclipse.jgit.patch
Class FileHeader
java.lang.Object
org.eclipse.jgit.diff.DiffEntry
org.eclipse.jgit.patch.FileHeader
- Direct Known Subclasses:
CombinedFileHeader
Patch header describing an action for a single file path.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Type of patch used by this file.Nested classes/interfaces inherited from class org.eclipse.jgit.diff.DiffEntry
DiffEntry.ChangeType, DiffEntry.Side
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final byte[]
Buffer holding the patch data for this file.private static final byte[]
private static final byte[]
(package private) static final byte[]
private static final byte[]
(package private) int
Position 1 past the end of this file withinbuf
.(package private) BinaryHunk
IfpatchType
isFileHeader.PatchType.GIT_BINARY
, the new imageprivate List<HunkHeader>
The hunks of this file(package private) static final byte[]
(package private) static final byte[]
private static final byte[]
(package private) static final byte[]
private static final byte[]
(package private) static final byte[]
(package private) FileHeader.PatchType
Type of patch used to modify this fileprivate static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
(package private) BinaryHunk
IfpatchType
isFileHeader.PatchType.GIT_BINARY
, the old imageprivate static final byte[]
(package private) final int
Offset withinbuf
to the "diff ..." line. -
Constructor Summary
ConstructorsConstructorDescriptionFileHeader
(byte[] b, int offset) FileHeader
(byte[] headerLines, EditList edits, FileHeader.PatchType type) Constructs a new FileHeader -
Method Summary
Modifier and TypeMethodDescription(package private) void
private boolean
eq
(int aPtr, int aEnd, int bPtr, int bEnd) private String[]
extractFileLines
(Charset[] csGuess) byte[]
Get the byte array holding this file's patch script.int
Get offset one past the end of the file script.Get the new-image delta/literal if this is aFileHeader.PatchType.GIT_BINARY
.List<? extends HunkHeader>
getHunks()
Get hunks altering this file; in order of appearance in patch(package private) int
Get style of patch used to modify this file.Get the old-image delta/literal if this is aFileHeader.PatchType.GIT_BINARY
.Convert the patch script for this file into a string.(package private) String
getScriptText
(Charset[] charsetGuess) getScriptText
(Charset oldCharset, Charset newCharset) Convert the patch script for this file into a string.int
Get offset of the start of this file's script ingetBuffer()
.boolean
Whether this patch modifies metadata about a file(package private) static int
isHunkHdr
(byte[] buf, int start, int end) Determine if this is a patch hunk header.(package private) HunkHeader
newHunkHeader
(int offset) private static String
(package private) FileMode
parseFileMode
(int ptr, int end) (package private) int
parseGitFileName
(int ptr, int end) Parse a "diff --git" or "diff --cc" line.(package private) int
parseGitHeaders
(int ptr, int end) (package private) void
parseIndexLine
(int ptr, int end) private String
(package private) void
parseNewFileMode
(int ptr, int eol) (package private) void
parseNewName
(int ptr, int eol) (package private) void
parseOldName
(int ptr, int eol) (package private) int
parseTraditionalHeaders
(int ptr, int end) Convert to a list describing the content edits performed on this file.private static boolean
trySimpleConversion
(Charset[] charsetGuess) Methods inherited from class org.eclipse.jgit.diff.DiffEntry
getChangeType, getDiffAttribute, getId, getMode, getNewId, getNewMode, getNewPath, getOldId, getOldMode, getOldPath, getPath, getScore, getTreeFilterMarks, isMarked, scan, scan, scan, toString
-
Field Details
-
OLD_MODE
private static final byte[] OLD_MODE -
NEW_MODE
private static final byte[] NEW_MODE -
DELETED_FILE_MODE
static final byte[] DELETED_FILE_MODE -
NEW_FILE_MODE
static final byte[] NEW_FILE_MODE -
COPY_FROM
private static final byte[] COPY_FROM -
COPY_TO
private static final byte[] COPY_TO -
RENAME_OLD
private static final byte[] RENAME_OLD -
RENAME_NEW
private static final byte[] RENAME_NEW -
RENAME_FROM
private static final byte[] RENAME_FROM -
RENAME_TO
private static final byte[] RENAME_TO -
SIMILARITY_INDEX
private static final byte[] SIMILARITY_INDEX -
DISSIMILARITY_INDEX
private static final byte[] DISSIMILARITY_INDEX -
INDEX
static final byte[] INDEX -
OLD_NAME
static final byte[] OLD_NAME -
NEW_NAME
static final byte[] NEW_NAME -
buf
final byte[] bufBuffer holding the patch data for this file. -
startOffset
final int startOffsetOffset withinbuf
to the "diff ..." line. -
endOffset
int endOffsetPosition 1 past the end of this file withinbuf
. -
patchType
FileHeader.PatchType patchTypeType of patch used to modify this file -
hunks
The hunks of this file -
forwardBinaryHunk
BinaryHunk forwardBinaryHunkIfpatchType
isFileHeader.PatchType.GIT_BINARY
, the new image -
reverseBinaryHunk
BinaryHunk reverseBinaryHunkIfpatchType
isFileHeader.PatchType.GIT_BINARY
, the old image
-
-
Constructor Details
-
FileHeader
Constructs a new FileHeader- Parameters:
headerLines
- buffer holding the diff header for this fileedits
- the edits for this filetype
- the type of patch used to modify this file
-
FileHeader
FileHeader(byte[] b, int offset)
-
-
Method Details
-
getParentCount
int getParentCount() -
getBuffer
public byte[] getBuffer()Get the byte array holding this file's patch script.- Returns:
- the byte array holding this file's patch script.
-
getStartOffset
public int getStartOffset()Get offset of the start of this file's script ingetBuffer()
.- Returns:
- offset of the start of this file's script in
getBuffer()
.
-
getEndOffset
public int getEndOffset()Get offset one past the end of the file script.- Returns:
- offset one past the end of the file script.
-
getScriptText
Convert the patch script for this file into a string.The default character encoding (
StandardCharsets.UTF_8
) is assumed for both the old and new files.- Returns:
- the patch script, as a Unicode string.
-
getScriptText
Convert the patch script for this file into a string.- Parameters:
oldCharset
- hint character set to decode the old lines with.newCharset
- hint character set to decode the new lines with.- Returns:
- the patch script, as a Unicode string.
-
getScriptText
-
trySimpleConversion
-
extractFileLines
-
getPatchType
Get style of patch used to modify this file.- Returns:
- style of patch used to modify this file.
-
hasMetaDataChanges
public boolean hasMetaDataChanges()Whether this patch modifies metadata about a file- Returns:
true
if this patch modifies metadata about a file .
-
getHunks
Get hunks altering this file; in order of appearance in patch- Returns:
- hunks altering this file; in order of appearance in patch.
-
addHunk
-
newHunkHeader
-
getForwardBinaryHunk
Get the new-image delta/literal if this is aFileHeader.PatchType.GIT_BINARY
.- Returns:
- the new-image delta/literal if this is a
FileHeader.PatchType.GIT_BINARY
.
-
getReverseBinaryHunk
Get the old-image delta/literal if this is aFileHeader.PatchType.GIT_BINARY
.- Returns:
- the old-image delta/literal if this is a
FileHeader.PatchType.GIT_BINARY
.
-
toEditList
Convert to a list describing the content edits performed on this file.- Returns:
- a list describing the content edits performed on this file.
-
parseGitFileName
int parseGitFileName(int ptr, int end) Parse a "diff --git" or "diff --cc" line.- Parameters:
ptr
- first character after the "diff --git " or "diff --cc " part.end
- one past the last position to parse.- Returns:
- first character after the LF at the end of the line; -1 on error.
-
parseGitHeaders
int parseGitHeaders(int ptr, int end) -
parseOldName
void parseOldName(int ptr, int eol) -
parseNewName
void parseNewName(int ptr, int eol) -
parseNewFileMode
void parseNewFileMode(int ptr, int eol) -
parseTraditionalHeaders
int parseTraditionalHeaders(int ptr, int end) -
parseName
-
p1
-
parseFileMode
-
parseIndexLine
void parseIndexLine(int ptr, int end) -
eq
private boolean eq(int aPtr, int aEnd, int bPtr, int bEnd) -
isHunkHdr
static int isHunkHdr(byte[] buf, int start, int end) Determine if this is a patch hunk header.- Parameters:
buf
- the buffer to scanstart
- first position in the buffer to evaluateend
- last position to consider; usually the end of the buffer (buf.length
) or the first position on the next line. This is only used to avoid very long runs of '@' from killing the scan loop.- Returns:
- the number of "ancestor revisions" in the hunk header. A traditional two-way diff ("@@ -...") returns 1; a combined diff for a 3 way-merge returns 3. If this is not a hunk header, 0 is returned instead.
-