Top Description Inners Fields Constructors Methods
org.eclipse.jgit.patch

public Class FileHeader

extends DiffEntry
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.patch.CombinedFileHeader
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.lib.Constants.encodeASCII, org.eclipse.jgit.util.RawParseUtils.decode, .RawParseUtils.decodeNoFallback, .RawParseUtils.extractBinaryString, .RawParseUtils.match, .RawParseUtils.nextLF, .RawParseUtils.parseBase10

Patch header describing an action for a single file path.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
FileHeader.PatchType

Type of patch used by this file.

Field Summary

Modifier and TypeField and Description
pack-priv final byte[]
buf

Buffer holding the patch data for this file.

private static final byte[]
private static final byte[]
pack-priv static final byte[]
private static final byte[]
pack-priv int
endOffset

Position 1 past the end of this file within buf.

pack-priv BinaryHunk
private List<HunkHeader>
hunks

The hunks of this file

pack-priv static final byte[]
pack-priv static final byte[]
private static final byte[]
pack-priv static final byte[]
private static final byte[]
pack-priv static final byte[]
pack-priv FileHeader.PatchType
patchType

Type of patch used to modify this file

private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
pack-priv BinaryHunk
private static final byte[]
pack-priv final int
startOffset

Offset within buf to the "diff ..." line.

Inherited from org.eclipse.jgit.diff.DiffEntry:
changeTypeDEV_NULLdiffAttributenewIdnewModenewPatholdIdoldModeoldPathscore

Constructor Summary

AccessConstructor and Description
public
FileHeader(byte[]
buffer holding the diff header for this file
headerLines
,
EditList
the edits for this file
edits
,
FileHeader.PatchType
the type of patch used to modify this file
type
)

Constructs a new FileHeader

pack-priv
FileHeader(byte[] b, int offset)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
private boolean
eq(int aPtr, int aEnd, int bPtr, int bEnd)

private String[]
public byte[]

Returns:

the byte array holding this file's patch script.
getBuffer
()

Get the byte array holding this file's patch script.

public int

Returns:

offset one past the end of the file script.
getEndOffset
()

Get offset one past the end of the file script.

public BinaryHunk

Returns:

the new-image delta/literal if this is a PatchType#GIT_BINARY.
getForwardBinaryHunk
()

Get the new-image delta/literal if this is a PatchType#GIT_BINARY.

public List<? extends HunkHeader>

Returns:

hunks altering this file; in order of appearance in patch.
getHunks
()

Get hunks altering this file; in order of appearance in patch

pack-priv int
public FileHeader.PatchType

Returns:

style of patch used to modify this file.
getPatchType
()

Get style of patch used to modify this file.

public BinaryHunk

Returns:

the old-image delta/literal if this is a PatchType#GIT_BINARY.
getReverseBinaryHunk
()

Get the old-image delta/literal if this is a PatchType#GIT_BINARY.

public String

Returns:

the patch script, as a Unicode string.
getScriptText
()

Convert the patch script for this file into a string.

public String

Returns:

the patch script, as a Unicode string.
getScriptText
(Charset
hint character set to decode the old lines with.
oldCharset
,
Charset
hint character set to decode the new lines with.
newCharset
)

Convert the patch script for this file into a string.

pack-priv String

Returns:

the patch script, as a Unicode string.
getScriptText
(Charset[]
hint which charset is used
charsetGuess
)

Convert the patch script for this file into a string.

public int

Returns:

offset of the start of this file's script in getBuffer().
getStartOffset
()

Get offset of the start of this file's script in getBuffer().

public boolean

Returns:

true if this patch modifies metadata about a file .
hasMetaDataChanges
()

Whether this patch modifies metadata about a file

pack-priv static int

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.
isHunkHdr
(byte[]
the buffer to scan
buf
,
int
first position in the buffer to evaluate
start
,
int
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.
end
)

Determine if this is a patch hunk header.

pack-priv HunkHeader
newHunkHeader(int offset)

private static String
p1(final String r)

pack-priv FileMode
parseFileMode(int ptr, int end)

pack-priv int

Returns:

first character after the LF at the end of the line; -1 on error.
parseGitFileName
(int
first character after the "diff --git " or "diff --cc " part.
ptr
,
int
one past the last position to parse.
end
)

Parse a "diff --git" or "diff --cc" line.

pack-priv int
parseGitHeaders(int ptr, int end)

pack-priv void
parseIndexLine(int ptr, int end)

private String
parseName(String expect, int ptr, int end)

pack-priv void
parseNewFileMode(int ptr, int eol)

pack-priv void
parseNewName(int ptr, int eol)

pack-priv void
parseOldName(int ptr, int eol)

pack-priv int
parseTraditionalHeaders(int ptr, int end)

public EditList

Returns:

a list describing the content edits performed on this file.
toEditList
()

Convert to a list describing the content edits performed on this file.

private static boolean
trySimpleConversion(Charset[] charsetGuess)

Inherited from org.eclipse.jgit.diff.DiffEntry:
getChangeTypegetDiffAttributegetIdgetModegetNewIdgetNewModegetNewPathgetOldIdgetOldModegetOldPathgetPathgetScoregetTreeFilterMarksisMarkedscanscanscantoString

Field Detail

bufback to summary
pack-priv final byte[] buf

Buffer holding the patch data for this file.

COPY_FROMback to summary
private static final byte[] COPY_FROM
COPY_TOback to summary
private static final byte[] COPY_TO
DELETED_FILE_MODEback to summary
pack-priv static final byte[] DELETED_FILE_MODE
DISSIMILARITY_INDEXback to summary
private static final byte[] DISSIMILARITY_INDEX
endOffsetback to summary
pack-priv int endOffset

Position 1 past the end of this file within buf.

forwardBinaryHunkback to summary
pack-priv BinaryHunk forwardBinaryHunk

If patchType is PatchType#GIT_BINARY, the new image

hunksback to summary
private List<HunkHeader> hunks

The hunks of this file

INDEXback to summary
pack-priv static final byte[] INDEX
NEW_FILE_MODEback to summary
pack-priv static final byte[] NEW_FILE_MODE
NEW_MODEback to summary
private static final byte[] NEW_MODE
NEW_NAMEback to summary
pack-priv static final byte[] NEW_NAME
OLD_MODEback to summary
private static final byte[] OLD_MODE
OLD_NAMEback to summary
pack-priv static final byte[] OLD_NAME
patchTypeback to summary
pack-priv FileHeader.PatchType patchType

Type of patch used to modify this file

RENAME_FROMback to summary
private static final byte[] RENAME_FROM
RENAME_NEWback to summary
private static final byte[] RENAME_NEW
RENAME_OLDback to summary
private static final byte[] RENAME_OLD
RENAME_TOback to summary
private static final byte[] RENAME_TO
reverseBinaryHunkback to summary
pack-priv BinaryHunk reverseBinaryHunk

If patchType is PatchType#GIT_BINARY, the old image

SIMILARITY_INDEXback to summary
private static final byte[] SIMILARITY_INDEX
startOffsetback to summary
pack-priv final int startOffset

Offset within buf to the "diff ..." line.

Constructor Detail

FileHeaderback to summary
public FileHeader(byte[] headerLines, EditList edits, FileHeader.PatchType type)

Constructs a new FileHeader

Parameters
headerLines:byte[]

buffer holding the diff header for this file

edits:EditList

the edits for this file

type:FileHeader.PatchType

the type of patch used to modify this file

FileHeaderback to summary
pack-priv FileHeader(byte[] b, int offset)

Method Detail

addHunkback to summary
pack-priv void addHunk(HunkHeader h)
eqback to summary
private boolean eq(int aPtr, int aEnd, int bPtr, int bEnd)
extractFileLinesback to summary
private String[] extractFileLines(Charset[] csGuess)
getBufferback to summary
public byte[] getBuffer()

Get the byte array holding this file's patch script.

Returns:byte[]

the byte array holding this file's patch script.

getEndOffsetback to summary
public int getEndOffset()

Get offset one past the end of the file script.

Returns:int

offset one past the end of the file script.

getForwardBinaryHunkback to summary
public BinaryHunk getForwardBinaryHunk()

Get the new-image delta/literal if this is a PatchType#GIT_BINARY.

Returns:BinaryHunk

the new-image delta/literal if this is a PatchType#GIT_BINARY.

getHunksback to summary
public List<? extends HunkHeader> getHunks()

Get hunks altering this file; in order of appearance in patch

Returns:List<? extends HunkHeader>

hunks altering this file; in order of appearance in patch.

getParentCountback to summary
pack-priv int getParentCount()
getPatchTypeback to summary
public FileHeader.PatchType getPatchType()

Get style of patch used to modify this file.

Returns:FileHeader.PatchType

style of patch used to modify this file.

getReverseBinaryHunkback to summary
public BinaryHunk getReverseBinaryHunk()

Get the old-image delta/literal if this is a PatchType#GIT_BINARY.

Returns:BinaryHunk

the old-image delta/literal if this is a PatchType#GIT_BINARY.

getScriptTextback to summary
public String getScriptText()

Convert the patch script for this file into a string.

The default character encoding (java.nio.charset.StandardCharsets#UTF_8) is assumed for both the old and new files.

Returns:String

the patch script, as a Unicode string.

getScriptTextback to summary
public String getScriptText(Charset oldCharset, Charset newCharset)

Convert the patch script for this file into a string.

Parameters
oldCharset:Charset

hint character set to decode the old lines with.

newCharset:Charset

hint character set to decode the new lines with.

Returns:String

the patch script, as a Unicode string.

getScriptTextback to summary
pack-priv String getScriptText(Charset[] charsetGuess)

Convert the patch script for this file into a string.

Parameters
charsetGuess:Charset[]

hint which charset is used

Returns:String

the patch script, as a Unicode string.

getStartOffsetback to summary
public int getStartOffset()

Get offset of the start of this file's script in getBuffer().

Returns:int

offset of the start of this file's script in getBuffer().

hasMetaDataChangesback to summary
public boolean hasMetaDataChanges()

Whether this patch modifies metadata about a file

Returns:boolean

true if this patch modifies metadata about a file .

isHunkHdrback to summary
pack-priv static int isHunkHdr(byte[] buf, int start, int end)

Determine if this is a patch hunk header.

Parameters
buf:byte[]

the buffer to scan

start:int

first position in the buffer to evaluate

end:int

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:int

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.

newHunkHeaderback to summary
pack-priv HunkHeader newHunkHeader(int offset)
p1back to summary
private static String p1(final String r)
parseFileModeback to summary
pack-priv FileMode parseFileMode(int ptr, int end)
parseGitFileNameback to summary
pack-priv int parseGitFileName(int ptr, int end)

Parse a "diff --git" or "diff --cc" line.

Parameters
ptr:int

first character after the "diff --git " or "diff --cc " part.

end:int

one past the last position to parse.

Returns:int

first character after the LF at the end of the line; -1 on error.

parseGitHeadersback to summary
pack-priv int parseGitHeaders(int ptr, int end)
parseIndexLineback to summary
pack-priv void parseIndexLine(int ptr, int end)
parseNameback to summary
private String parseName(String expect, int ptr, int end)
parseNewFileModeback to summary
pack-priv void parseNewFileMode(int ptr, int eol)
parseNewNameback to summary
pack-priv void parseNewName(int ptr, int eol)
parseOldNameback to summary
pack-priv void parseOldName(int ptr, int eol)
parseTraditionalHeadersback to summary
pack-priv int parseTraditionalHeaders(int ptr, int end)
toEditListback to summary
public EditList toEditList()

Convert to a list describing the content edits performed on this file.

Returns:EditList

a list describing the content edits performed on this file.

trySimpleConversionback to summary
private static boolean trySimpleConversion(Charset[] charsetGuess)
org.eclipse.jgit.patch back to summary

public final Enum FileHeader.PatchType

extends Enum<FileHeader.PatchType>
Class Inheritance

Type of patch used by this file.

Field Summary

Modifier and TypeField and Description
public static final FileHeader.PatchType
BINARY

An empty patch with a message "Binary files ...

public static final FileHeader.PatchType
GIT_BINARY

A Git binary patch, holding pre and post image deltas

public static final FileHeader.PatchType
UNIFIED

A traditional unified diff style patch of a text file.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static FileHeader.PatchType
public static FileHeader.PatchType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BINARYback to summary
public static final FileHeader.PatchType BINARY

An empty patch with a message "Binary files ... differ"

GIT_BINARYback to summary
public static final FileHeader.PatchType GIT_BINARY

A Git binary patch, holding pre and post image deltas

UNIFIEDback to summary
public static final FileHeader.PatchType UNIFIED

A traditional unified diff style patch of a text file.

Constructor Detail

PatchTypeback to summary
private PatchType()

Method Detail

valueOfback to summary
public static FileHeader.PatchType valueOf(String name)
valuesback to summary
public static FileHeader.PatchType[] values()