diff

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package diff provides a parser for git diff output. It parses the output of: git diff --raw --full-index --find-renames Based on gitaly's implementation (MIT License).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limits

type Limits struct {
	// EnforceLimits causes parsing to stop if Max{Files,Lines,Bytes} is reached.
	EnforceLimits bool
	// CollapseDiffs causes patches to be emptied after SafeMax{Files,Lines,Bytes} reached.
	CollapseDiffs bool
	// CollectAllPaths parses all diffs but info outside of path may be empty.
	CollectAllPaths bool
	// MaxFiles is the maximum number of files to parse.
	MaxFiles int
	// MaxLines is the maximum number of diff lines to parse.
	MaxLines int
	// MaxBytes is the maximum number of bytes to parse.
	MaxBytes int
	// SafeMaxFiles is the number of files after which subsequent files are collapsed.
	SafeMaxFiles int
	// SafeMaxLines is the number of lines after which subsequent files are collapsed.
	SafeMaxLines int
	// SafeMaxBytes is the number of bytes after which subsequent files are collapsed.
	SafeMaxBytes int
	// MaxPatchBytes is the maximum bytes a single patch can have.
	MaxPatchBytes int
	// MaxPatchBytesForFileExtension overrides MaxPatchBytes for specific file types.
	MaxPatchBytesForFileExtension map[string]int
	// PatchLimitsOnly uses only MaxPatchBytes limits, ignoring cumulative limits.
	PatchLimitsOnly bool
}

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

type Parser

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

Parser holds necessary state for parsing a diff stream.

func NewParser

func NewParser(hashFormat git.HashFormat, src io.Reader, limits Limits) *Parser

NewParser returns a new Parser.

func (*Parser) Err

func (parser *Parser) Err() error

Err returns the error encountered during parsing.

func (*Parser) Parse

func (parser *Parser) Parse() bool

Parse parses a single diff. It returns true if successful, false if finished or error.

func (*Parser) Patch

func (parser *Parser) Patch() *Patch

Patch returns a successfully parsed patch. Valid until next Parse() call.

type Patch

type Patch struct {
	*diferenco.Patch
	Status          byte // 'A', 'D', 'M', 'R', 'C', 'T' etc.
	OverflowMarker  bool
	Collapsed       bool
	TooLarge        bool
	CollectAllPaths bool
	PatchSize       int32
	LinesAdded      int32
	LinesRemoved    int32
	// contains filtered or unexported fields
}

Patch represents a single parsed diff entry, extending diferenco.Patch with git metadata.

func (*Patch) ClearPatch

func (p *Patch) ClearPatch()

ClearPatch clears only the patch content.

func (*Patch) Reset

func (p *Patch) Reset()

Reset clears all fields of p, allocating a fresh embedded Patch.

Jump to

Keyboard shortcuts

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