Package org.eclipse.jgit.patch
Class FileHeader
- java.lang.Object
-
- org.eclipse.jgit.diff.DiffEntry
-
- org.eclipse.jgit.patch.FileHeader
-
- Direct Known Subclasses:
CombinedFileHeader
public class FileHeader extends DiffEntry
Patch header describing an action for a single file path.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileHeader.PatchType
Type of patch used by this file.-
Nested classes/interfaces inherited from class org.eclipse.jgit.diff.DiffEntry
DiffEntry.ChangeType, DiffEntry.Side
-
-
Field Summary
Fields Modifier and Type Field 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 withinbuf
.(package private) BinaryHunk
forwardBinaryHunk
IfpatchType
isFileHeader.PatchType.GIT_BINARY
, the new imageprivate 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 fileprivate static byte[]
RENAME_FROM
private static byte[]
RENAME_NEW
private static byte[]
RENAME_OLD
private static byte[]
RENAME_TO
(package private) BinaryHunk
reverseBinaryHunk
IfpatchType
isFileHeader.PatchType.GIT_BINARY
, the old imageprivate static byte[]
SIMILARITY_INDEX
(package private) int
startOffset
Offset withinbuf
to the "diff ..." line.
-
Constructor Summary
Constructors Constructor Description FileHeader(byte[] b, int offset)
FileHeader(byte[] headerLines, EditList edits, FileHeader.PatchType type)
Constructs a new FileHeader
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 aFileHeader.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 aFileHeader.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 ingetBuffer()
.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)
-
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 Detail
-
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[] buf
Buffer holding the patch data for this file.
-
startOffset
final int startOffset
Offset withinbuf
to the "diff ..." line.
-
endOffset
int endOffset
Position 1 past the end of this file withinbuf
.
-
patchType
FileHeader.PatchType patchType
Type of patch used to modify this file
-
hunks
private java.util.List<HunkHeader> hunks
The hunks of this file
-
forwardBinaryHunk
BinaryHunk forwardBinaryHunk
IfpatchType
isFileHeader.PatchType.GIT_BINARY
, the new image
-
reverseBinaryHunk
BinaryHunk reverseBinaryHunk
IfpatchType
isFileHeader.PatchType.GIT_BINARY
, the old image
-
-
Constructor Detail
-
FileHeader
public FileHeader(byte[] headerLines, EditList edits, FileHeader.PatchType type)
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 Detail
-
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
public java.lang.String 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
public java.lang.String getScriptText(java.nio.charset.Charset oldCharset, java.nio.charset.Charset newCharset)
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
java.lang.String getScriptText(java.nio.charset.Charset[] charsetGuess)
-
trySimpleConversion
private static boolean trySimpleConversion(java.nio.charset.Charset[] charsetGuess)
-
extractFileLines
private java.lang.String[] extractFileLines(java.nio.charset.Charset[] csGuess)
-
getPatchType
public FileHeader.PatchType 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
public java.util.List<? extends HunkHeader> getHunks()
Get hunks altering this file; in order of appearance in patch- Returns:
- hunks altering this file; in order of appearance in patch.
-
addHunk
void addHunk(HunkHeader h)
-
newHunkHeader
HunkHeader newHunkHeader(int offset)
-
getForwardBinaryHunk
public BinaryHunk 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
public BinaryHunk 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
public EditList 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
private java.lang.String parseName(java.lang.String expect, int ptr, int end)
-
p1
private static java.lang.String p1(java.lang.String r)
-
parseFileMode
FileMode parseFileMode(int ptr, int end)
-
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.
-
-