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.
  • 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[] buf
      Buffer holding the patch data for this file.
    • startOffset

      final int startOffset
      Offset within buf to the "diff ..." line.
    • endOffset

      int endOffset
      Position 1 past the end of this file within buf.
    • patchType

      Type of patch used to modify this file
    • hunks

      private List<HunkHeader> hunks
      The hunks of this file
    • forwardBinaryHunk

      BinaryHunk forwardBinaryHunk
    • reverseBinaryHunk

      BinaryHunk reverseBinaryHunk
  • Constructor Details

    • FileHeader

      public FileHeader(byte[] headerLines, EditList edits, FileHeader.PatchType type)
      Constructs a new FileHeader
      Parameters:
      headerLines - buffer holding the diff header for this file
      edits - the edits for this file
      type - 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 in getBuffer().
      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 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 String getScriptText(Charset oldCharset, 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

      String getScriptText(Charset[] charsetGuess)
    • trySimpleConversion

      private static boolean trySimpleConversion(Charset[] charsetGuess)
    • extractFileLines

      private String[] extractFileLines(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 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 a FileHeader.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 a FileHeader.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 String parseName(String expect, int ptr, int end)
    • p1

      private static String p1(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 scan
      start - first position in the buffer to evaluate
      end - 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.