parser

package
v1.0.1-gitspaces-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	ErrLineTooLong = errors.New("line too long")
)

Functions

func BlobCut

func BlobCut(r io.Reader, params DiffCutParams) (CutHeader, Cut, error)

BlobCut parses raw file and returns lines specified with the parameter.

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

func DiffExtHeaderParseIndex(line string) (newSHA string, oldSHA string, ok bool)

DiffExtParseIndex parses the `index` extended diff header line.

func HasLineEnding

func HasLineEnding(line []byte) bool

func HasLineEndingCRLF

func HasLineEndingCRLF(line []byte) bool

func HasLineEndingLF

func HasLineEndingLF(line []byte) bool

func LimitLineLen

func LimitLineLen(lines *[]string, maxLen int)

func ParseDiffFileExtendedHeader

func ParseDiffFileExtendedHeader(line string) (string, string)

ParseDiffFileExtendedHeader parses a generic extended header line.

func ScanLinesWithEOF

func ScanLinesWithEOF(data []byte, atEOF bool) (advance int, token []byte, err error)

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

func ScanZeroSeparated

func ScanZeroSeparated(data []byte, atEOF bool) (advance int, token []byte, err error)

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 Cut

type Cut struct {
	CutHeader
	Lines []string
}

type CutHeader

type CutHeader struct {
	Line int
	Span int
}

type DiffCutParams

type DiffCutParams struct {
	LineStart    int
	LineStartNew bool
	LineEnd      int
	LineEndNew   bool
	BeforeLines  int
	AfterLines   int
	LineLimit    int
}

type DiffFileHeader

type DiffFileHeader struct {
	OldFileName string
	NewFileName string
	Extensions  map[string]string
}

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

type HunkHeader struct {
	OldLine int
	OldSpan int
	NewLine int
	NewSpan int
	Text    string
}

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

type Scanner interface {
	Scan() bool
	Err() error
	Bytes() []byte
	Text() string
}

func ReadTextFile

func ReadTextFile(r io.Reader, overwriteLE *string) (Scanner, string, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL