diff

package
v16.9.0-rc44 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Binary          bool
	OverflowMarker  bool
	Collapsed       bool
	TooLarge        bool
	CollectAllPaths bool
	Status          byte

	FromID   string
	ToID     string
	OldMode  int32
	NewMode  int32
	FromPath []byte
	ToPath   []byte
	Patch    []byte
	// contains filtered or unexported fields
}

Diff represents a single parsed diff entry

func (*Diff) ClearPatch added in v16.1.0

func (d *Diff) ClearPatch()

ClearPatch clears only patch field of Diff d

func (*Diff) Reset

func (d *Diff) Reset()

Reset clears all fields of d in a way that lets the underlying memory allocations of the []byte fields be reused.

type Limits

type Limits struct {
	// If true, Max{Files,Lines,Bytes} will cause parsing to stop if any of these limits is reached
	EnforceLimits bool
	// If true, SafeMax{Files,Lines,Bytes} will cause diffs to collapse (i.e. patches are emptied) after any of these limits reached
	CollapseDiffs bool
	// If true, all diffs are parsed, processed, and returned but info outside of path may be empty
	CollectAllPaths bool
	// Number of maximum files to parse. The file parsed after this limit is reached is marked as the overflow.
	MaxFiles int
	// Number of diffs lines to parse (including lines preceded with --- or +++).
	// The file in which this limit is reached is discarded and marked as the overflow.
	MaxLines int
	// Number of bytes to parse (including lines preceded with --- or +++).
	// The file in which this limit is reached is discarded and marked as the overflow.
	MaxBytes int
	// Number of files to parse, after which all subsequent files are collapsed.
	SafeMaxFiles int
	// Number of lines to parse (including lines preceded with --- or +++), after which all subsequent files are collapsed.
	SafeMaxLines int
	// Number of bytes to parse (including lines preceded with --- or +++), after which all subsequent files are collapsed.
	SafeMaxBytes int
	// Number of bytes a single patch can have. Patches surpassing this limit are pruned / nullified.
	MaxPatchBytes int
	// Max number of bytes for specific file type. This overrides MaxPatchBytes
	MaxPatchBytesForFileExtension map[string]int
}

Limits holds the limits at which either parsing stops or patches are collapsed

type NumStat

type NumStat struct {
	Path      []byte
	OldPath   []byte
	Additions int32
	Deletions int32
}

NumStat represents a single parsed diff file change

type NumStatParser

type NumStatParser struct {
	// contains filtered or unexported fields
}

NumStatParser holds necessary state for parsing the numstat output

func NewDiffNumStatParser

func NewDiffNumStatParser(src io.Reader) *NumStatParser

NewDiffNumStatParser returns a new NumStatParser

func (*NumStatParser) NextNumStat

func (parser *NumStatParser) NextNumStat() (*NumStat, error)

NextNumStat reads from git diff --numstat -z command, parses the stats and returns a *NumStat.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser holds necessary state for parsing a diff stream

func NewDiffParser

func NewDiffParser(objectHash git.ObjectHash, src io.Reader, limits Limits) *Parser

NewDiffParser returns a new Parser

func (*Parser) Diff

func (parser *Parser) Diff() *Diff

Diff returns a successfully parsed diff. It should be called only when Parser.Parse() returns true. The return value is valid only until the next call to Parser.Parse().

func (*Parser) Err

func (parser *Parser) Err() error

Err returns the error encountered (if any) when parsing the diff stream. It should be called only when Parser.Parse() returns false.

func (*Parser) Parse

func (parser *Parser) Parse() bool

Parse parses a single diff. It returns true if successful, false if it finished parsing all diffs or when it encounters an error, in which case use Parser.Err() to get the error.

Jump to

Keyboard shortcuts

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