public class FileHeader extends DiffEntry
Modifier and Type | Class and Description |
---|---|
static class |
FileHeader.PatchType
Type of patch used by this file.
|
DiffEntry.ChangeType, DiffEntry.Side
Modifier and Type | Field and Description |
---|---|
(package private) byte[] |
buf
Buffer holding the patch data for this file.
|
private static byte[] |
COPY_FROM |
private static byte[] |
COPY_TO |
(package private) static byte[] |
DELETED_FILE_MODE |
private static byte[] |
DISSIMILARITY_INDEX |
(package private) int |
endOffset
Position 1 past the end of this file within
buf . |
(package private) BinaryHunk |
forwardBinaryHunk
If
patchType is FileHeader.PatchType.GIT_BINARY , the new image |
private java.util.List<HunkHeader> |
hunks
The hunks of this file
|
(package private) static byte[] |
INDEX |
(package private) static byte[] |
NEW_FILE_MODE |
private static byte[] |
NEW_MODE |
(package private) static byte[] |
NEW_NAME |
private static byte[] |
OLD_MODE |
(package private) static byte[] |
OLD_NAME |
(package private) FileHeader.PatchType |
patchType
Type of patch used to modify this file
|
private static byte[] |
RENAME_FROM |
private static byte[] |
RENAME_NEW |
private static byte[] |
RENAME_OLD |
private static byte[] |
RENAME_TO |
(package private) BinaryHunk |
reverseBinaryHunk
If
patchType is FileHeader.PatchType.GIT_BINARY , the old image |
private static byte[] |
SIMILARITY_INDEX |
(package private) int |
startOffset
Offset within
buf to the "diff ..." line. |
Constructor and Description |
---|
FileHeader(byte[] headerLines,
EditList edits,
FileHeader.PatchType type)
Constructs a new FileHeader
|
FileHeader(byte[] b,
int offset) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
addHunk(HunkHeader h) |
private boolean |
eq(int aPtr,
int aEnd,
int bPtr,
int bEnd) |
private java.lang.String[] |
extractFileLines(java.nio.charset.Charset[] csGuess) |
byte[] |
getBuffer()
Get the byte array holding this file's patch script.
|
int |
getEndOffset()
Get offset one past the end of the file script.
|
BinaryHunk |
getForwardBinaryHunk()
Get the new-image delta/literal if this is a
FileHeader.PatchType.GIT_BINARY . |
java.util.List<? extends HunkHeader> |
getHunks()
Get hunks altering this file; in order of appearance in patch
|
(package private) int |
getParentCount() |
FileHeader.PatchType |
getPatchType()
Get style of patch used to modify this file.
|
BinaryHunk |
getReverseBinaryHunk()
Get the old-image delta/literal if this is a
FileHeader.PatchType.GIT_BINARY . |
java.lang.String |
getScriptText()
Convert the patch script for this file into a string.
|
(package private) java.lang.String |
getScriptText(java.nio.charset.Charset[] charsetGuess) |
java.lang.String |
getScriptText(java.nio.charset.Charset oldCharset,
java.nio.charset.Charset newCharset)
Convert the patch script for this file into a string.
|
int |
getStartOffset()
Get offset of the start of this file's script in
getBuffer() . |
boolean |
hasMetaDataChanges()
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 java.lang.String |
p1(java.lang.String r) |
(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 java.lang.String |
parseName(java.lang.String expect,
int ptr,
int end) |
(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) |
EditList |
toEditList()
Convert to a list describing the content edits performed on this file.
|
private static boolean |
trySimpleConversion(java.nio.charset.Charset[] charsetGuess) |
getChangeType, getDiffAttribute, getId, getMode, getNewId, getNewMode, getNewPath, getOldId, getOldMode, getOldPath, getPath, getScore, getTreeFilterMarks, isMarked, scan, scan, scan, toString
private static final byte[] OLD_MODE
private static final byte[] NEW_MODE
static final byte[] DELETED_FILE_MODE
static final byte[] NEW_FILE_MODE
private static final byte[] COPY_FROM
private static final byte[] COPY_TO
private static final byte[] RENAME_OLD
private static final byte[] RENAME_NEW
private static final byte[] RENAME_FROM
private static final byte[] RENAME_TO
private static final byte[] SIMILARITY_INDEX
private static final byte[] DISSIMILARITY_INDEX
static final byte[] INDEX
static final byte[] OLD_NAME
static final byte[] NEW_NAME
final byte[] buf
final int startOffset
buf
to the "diff ..." line.int endOffset
buf
.FileHeader.PatchType patchType
private java.util.List<HunkHeader> hunks
BinaryHunk forwardBinaryHunk
patchType
is FileHeader.PatchType.GIT_BINARY
, the new imageBinaryHunk reverseBinaryHunk
patchType
is FileHeader.PatchType.GIT_BINARY
, the old imagepublic FileHeader(byte[] headerLines, EditList edits, FileHeader.PatchType type)
headerLines
- buffer holding the diff header for this fileedits
- the edits for this filetype
- the type of patch used to modify this fileFileHeader(byte[] b, int offset)
int getParentCount()
public byte[] getBuffer()
public int getStartOffset()
getBuffer()
.getBuffer()
.public int getEndOffset()
public java.lang.String getScriptText()
The default character encoding
(StandardCharsets.UTF_8
) is assumed for both the
old and new files.
public java.lang.String getScriptText(java.nio.charset.Charset oldCharset, java.nio.charset.Charset newCharset)
oldCharset
- hint character set to decode the old lines with.newCharset
- hint character set to decode the new lines with.java.lang.String getScriptText(java.nio.charset.Charset[] charsetGuess)
private static boolean trySimpleConversion(java.nio.charset.Charset[] charsetGuess)
private java.lang.String[] extractFileLines(java.nio.charset.Charset[] csGuess)
public FileHeader.PatchType getPatchType()
public boolean hasMetaDataChanges()
true
if this patch modifies metadata about a file .public java.util.List<? extends HunkHeader> getHunks()
void addHunk(HunkHeader h)
HunkHeader newHunkHeader(int offset)
public BinaryHunk getForwardBinaryHunk()
FileHeader.PatchType.GIT_BINARY
.FileHeader.PatchType.GIT_BINARY
.public BinaryHunk getReverseBinaryHunk()
FileHeader.PatchType.GIT_BINARY
.FileHeader.PatchType.GIT_BINARY
.public EditList toEditList()
int parseGitFileName(int ptr, int end)
ptr
- first character after the "diff --git " or "diff --cc " part.end
- one past the last position to parse.int parseGitHeaders(int ptr, int end)
void parseOldName(int ptr, int eol)
void parseNewName(int ptr, int eol)
void parseNewFileMode(int ptr, int eol)
int parseTraditionalHeaders(int ptr, int end)
private java.lang.String parseName(java.lang.String expect, int ptr, int end)
private static java.lang.String p1(java.lang.String r)
FileMode parseFileMode(int ptr, int end)
void parseIndexLine(int ptr, int end)
private boolean eq(int aPtr, int aEnd, int bPtr, int bEnd)
static int isHunkHdr(byte[] buf, int start, int end)
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.