Documentation
¶
Index ¶
- Variables
- func BlobCut(r io.Reader, params DiffCutParams) (CutHeader, Cut, error)
- func DiffCut(r io.Reader, params DiffCutParams) (HunkHeader, Hunk, error)
- func DiffExtHeaderParseIndex(line string) (newSHA string, oldSHA string, ok bool)
- func HasLineEnding(line []byte) bool
- func HasLineEndingCRLF(line []byte) bool
- func HasLineEndingLF(line []byte) bool
- func LimitLineLen(lines *[]string, maxLen int)
- func ParseDiffFileExtendedHeader(line string) (string, string)
- func ScanLinesWithEOF(data []byte, atEOF bool) (advance int, token []byte, err error)
- func ScanZeroSeparated(data []byte, atEOF bool) (advance int, token []byte, err error)
- type BatchCheckObject
- type Cut
- type CutHeader
- type DiffCutParams
- type DiffFileHeader
- type DiffFileHunkHeaders
- type DiffRawFile
- type DiffStatus
- type Hunk
- type HunkHeader
- type Scanner
- type ScannerWithPeek
Constants ¶
This section is empty.
Variables ¶
var ( ErrSHADoesNotMatch = errors.InvalidArgument("sha does not match") ErrHunkNotFound = errors.NotFound("hunk not found") ErrBinaryFile = errors.InvalidArgument("can't handle a binary file") ErrPeekedMoreThanOnce = errors.PreconditionFailed("peeking more than once in a row is not supported") )
var (
ErrLineTooLong = errors.New("line too long")
)
Functions ¶
func DiffCut ¶
func DiffCut(r io.Reader, params DiffCutParams) (HunkHeader, Hunk, error)
DiffCut parses git diff output that should consist of a single hunk (usually generated with large value passed to the "--unified" parameter) and returns lines specified with the parameters.
func DiffExtHeaderParseIndex ¶
DiffExtParseIndex parses the `index` extended diff header line.
func HasLineEnding ¶
func HasLineEndingCRLF ¶
func HasLineEndingLF ¶
func LimitLineLen ¶
func ParseDiffFileExtendedHeader ¶
ParseDiffFileExtendedHeader parses a generic extended header line.
func ScanLinesWithEOF ¶
ScanLinesWithEOF is a variation of bufio's ScanLine method that returns the line endings. https://cs.opensource.google/go/go/+/master:src/bufio/scan.go;l=355;drc=bc2124dab14fa292e18df2937037d782f7868635
Types ¶
type BatchCheckObject ¶
type BatchCheckObject struct { SHA sha.SHA // TODO: Use proper TreeNodeType Type string Size int64 }
func CatFileBatchCheckAllObjects ¶
func CatFileBatchCheckAllObjects(r io.Reader) ([]BatchCheckObject, error)
type DiffCutParams ¶
type DiffFileHeader ¶
func ParseDiffFileHeader ¶
func ParseDiffFileHeader(line string) (DiffFileHeader, bool)
type DiffFileHunkHeaders ¶
type DiffFileHunkHeaders struct { FileHeader DiffFileHeader HunksHeaders []HunkHeader }
func GetHunkHeaders ¶
func GetHunkHeaders(r io.Reader) ([]*DiffFileHunkHeaders, error)
GetHunkHeaders parses git diff output and returns all diff headers for all files. See for documentation: https://git-scm.com/docs/git-diff#generate_patch_text_with_p
type DiffRawFile ¶
type DiffRawFile struct { OldFileMode string NewFileMode string OldBlobSHA string NewBlobSHA string Status DiffStatus OldPath string Path string }
func DiffRaw ¶
func DiffRaw(r io.Reader) ([]DiffRawFile, error)
DiffRaw parses raw git diff output (git diff --raw). Each entry (a line) is a changed file. The format is:
:100644 100644 <old-hash> <new-hash> <status>NULL<file-name>NULL
Old-hash and new-hash are the file object hashes. Status can be A added, D deleted, M modified, R renamed, C copied. When the status is A then the old-hash is the zero hash, when the status is D the new-hash is the zero hash. If the status is R or C then the output is:
:100644 100644 <old-hash> <new-hash> R<similarity index>NULL<old-name>NULL<new-name>NULL
type DiffStatus ¶
type DiffStatus byte
const ( DiffStatusModified DiffStatus = 'M' DiffStatusAdded DiffStatus = 'A' DiffStatusDeleted DiffStatus = 'D' DiffStatusRenamed DiffStatus = 'R' DiffStatusCopied DiffStatus = 'C' DiffStatusType DiffStatus = 'T' )
func (DiffStatus) String ¶
func (s DiffStatus) String() string
type Hunk ¶
type Hunk struct { HunkHeader Lines []string }
type HunkHeader ¶
func ParseDiffHunkHeader ¶
func ParseDiffHunkHeader(line string) (HunkHeader, bool)
func (*HunkHeader) IsValid ¶
func (h *HunkHeader) IsValid() bool
func (*HunkHeader) IsZero ¶
func (h *HunkHeader) IsZero() bool
func (*HunkHeader) String ¶
func (h *HunkHeader) String() string
type Scanner ¶
func ReadTextFile ¶
ReadTextFile returns a Scanner that reads the provided text file line by line.
The returned Scanner fulfills the following:
- If any line is larger than 64kb, the scanning fails with ErrBinaryFile
- If the reader returns invalid UTF-8, the scanning fails with ErrBinaryFile
- Line endings are returned as-is, unless overwriteLE is provided
type ScannerWithPeek ¶
type ScannerWithPeek struct {
// contains filtered or unexported fields
}
func NewScannerWithPeek ¶
func NewScannerWithPeek(r io.Reader, split bufio.SplitFunc) *ScannerWithPeek
func (*ScannerWithPeek) Bytes ¶
func (s *ScannerWithPeek) Bytes() []byte
func (*ScannerWithPeek) Err ¶
func (s *ScannerWithPeek) Err() error
func (*ScannerWithPeek) Peek ¶
func (s *ScannerWithPeek) Peek() bool
func (*ScannerWithPeek) Scan ¶
func (s *ScannerWithPeek) Scan() bool
func (*ScannerWithPeek) Text ¶
func (s *ScannerWithPeek) Text() string