unidiff

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allower

type Allower struct {
	Patterns []string
	// contains filtered or unexported fields
}

Allower is a collection of parsed allow patterns.

func NewAllower

func NewAllower(patterns ...string) (*Allower, error)

NewAllower creates a new allower given a list of user-provided allow patterns.

func (*Allower) IsAllowed

func (i *Allower) IsAllowed(path string, directory bool) bool

IsAllowed determines whether or not the specified path should be allowed based on all provided allow patterns and their order.

type FileDiff

type FileDiff struct {
	OrigName string `json:"orig_name"`
	NewName  string `json:"new_name"`
	// PreferredName is either OrigName or NewName. Comments and suggestions are reffering to this name.
	PreferredName string `json:"preferred_name"`

	IsDeleted bool `json:"is_deleted"`
	IsNew     bool `json:"is_new"`
	IsMoved   bool `json:"is_moved"`

	IsLarge bool `json:"is_large"`
	// LargeFileInfo is non nil when IsLarge is true
	LargeFileInfo *LargeFileInfo `json:"large_file_info"`

	// If this is true, all other fields are empty.
	// Used to represent file that is hidden from the logged-in user.
	IsHidden bool `json:"is_hidden"`

	Hunks []Hunk `json:"hunks"`
}

type FileDiffMode

type FileDiffMode int
var (
	FileDiffModeNew     FileDiffMode = 1
	FileDiffModeChanged FileDiffMode = 2
	FileDiffModeDeleted FileDiffMode = 3
	FileDiffModeMoved   FileDiffMode = 4
)

func DiffFileStat

func DiffFileStat(fd *diff.FileDiff) (mode FileDiffMode, origName, newName string, err error)

TODO: Can we make this private?

type FilterFunc

type FilterFunc func(diff *diff.FileDiff) (bool, error)

FilterFunc is a func that if it returns true, the diff that it's filtering will be removed

type Hunk

type Hunk struct {
	ID string `json:"id"`

	Patch string `json:"patch"`

	// Used only in suggestions
	IsOutdated  bool `json:"is_outdated"`
	IsApplied   bool `json:"is_applied"`
	IsDismissed bool `json:"is_dismissed"`
}

func NewHunk

func NewHunk(patch string) Hunk

type LargeFileInfo

type LargeFileInfo struct {
	Size uint64 `json:"size"`
}

type Option

type Option func(*Unidiff)

func WithAllower

func WithAllower(allower *Allower) Option

func WithHunksFilter

func WithHunksFilter(id ...string) Option

func WithInverter

func WithInverter() Option

type PatchReader

type PatchReader interface {
	ReadPatch() (string, error)
}

func NewBytesPatchReader

func NewBytesPatchReader(s [][]byte) PatchReader

func NewGitPatchReader

func NewGitPatchReader(diff *git.Diff) PatchReader

func NewStringsPatchReader

func NewStringsPatchReader(s []string) PatchReader

type Unidiff

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

func NewUnidiff

func NewUnidiff(diffs PatchReader, logger *zap.Logger, options ...Option) *Unidiff

func (*Unidiff) Decorate

func (u *Unidiff) Decorate() ([]FileDiff, error)

Decorate consumes the input and returns a []FileDiff

func (*Unidiff) DecorateSeparateBinary

func (u *Unidiff) DecorateSeparateBinary() (binaryDiffs, nonBinaryDiffs []FileDiff, err error)

DecorateSeparateBinary consumes the input and returns two separate []FileDiffs

func (*Unidiff) DecorateSingle

func (u *Unidiff) DecorateSingle() (FileDiff, error)

DecorateSingle consumes one item from the input, and returns it as a FileDiff

func (*Unidiff) Patches

func (u *Unidiff) Patches() ([]string, error)

Patches consumes the input, and returns the patches

func (*Unidiff) PatchesBytes

func (u *Unidiff) PatchesBytes() ([][]byte, error)

PatchesBytes consumes the input, and returns the patches

func (*Unidiff) WithAllower

func (u *Unidiff) WithAllower(allower *Allower) *Unidiff

func (*Unidiff) WithExpandedHunks

func (u *Unidiff) WithExpandedHunks() *Unidiff

func (*Unidiff) WithFilterFunc

func (u *Unidiff) WithFilterFunc(fn FilterFunc) *Unidiff

func (*Unidiff) WithHunksFilter

func (u *Unidiff) WithHunksFilter(id ...string) *Unidiff

func (*Unidiff) WithIgnoreBinary

func (u *Unidiff) WithIgnoreBinary() *Unidiff

func (*Unidiff) WithInverter

func (u *Unidiff) WithInverter() *Unidiff

func (*Unidiff) WithJoiner

func (u *Unidiff) WithJoiner() *Unidiff

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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