diff

package
v5.4.6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultContextLines = 3

DefaultContextLines is the default number of context lines.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

type Chunk interface {
	// Content contains the portion of the file.
	Content() string
	// Type contains the Operation to do with this Chunk.
	Type() Operation
}

Chunk represents a portion of a file transformation to another.

type ColorConfig

type ColorConfig map[ColorKey]string

A ColorConfig is a color configuration. A nil or empty ColorConfig corresponds to no color.

func NewColorConfig

func NewColorConfig(options ...ColorConfigOption) ColorConfig

NewColorConfig returns a new ColorConfig.

func (ColorConfig) Reset

func (cc ColorConfig) Reset(key ColorKey) string

Reset returns the ANSI escape sequence to reset the color with key set from cc. If no color was set then no reset is needed so it returns the empty string.

type ColorConfigOption

type ColorConfigOption func(ColorConfig)

A ColorConfigOption sets an option on a ColorConfig.

func WithColor

func WithColor(key ColorKey, color string) ColorConfigOption

WithColor sets the color for key.

type ColorKey

type ColorKey string

A ColorKey is a key into a ColorConfig map and also equal to the key in the diff.color subsection of the config. See https://github.com/git/git/blob/v2.26.2/diff.c#L83-L106.

const (
	Context                   ColorKey = "context"
	Meta                      ColorKey = "meta"
	Frag                      ColorKey = "frag"
	Old                       ColorKey = "old"
	New                       ColorKey = "new"
	Commit                    ColorKey = "commit"
	Whitespace                ColorKey = "whitespace"
	Func                      ColorKey = "func"
	OldMoved                  ColorKey = "oldMoved"
	OldMovedAlternative       ColorKey = "oldMovedAlternative"
	OldMovedDimmed            ColorKey = "oldMovedDimmed"
	OldMovedAlternativeDimmed ColorKey = "oldMovedAlternativeDimmed"
	NewMoved                  ColorKey = "newMoved"
	NewMovedAlternative       ColorKey = "newMovedAlternative"
	NewMovedDimmed            ColorKey = "newMovedDimmed"
	NewMovedAlternativeDimmed ColorKey = "newMovedAlternativeDimmed"
	ContextDimmed             ColorKey = "contextDimmed"
	OldDimmed                 ColorKey = "oldDimmed"
	NewDimmed                 ColorKey = "newDimmed"
	ContextBold               ColorKey = "contextBold"
	OldBold                   ColorKey = "oldBold"
	NewBold                   ColorKey = "newBold"
)

ColorKeys.

type File

type File interface {
	// Hash returns the File Hash.
	Hash() plumbing.Hash
	// Mode returns the FileMode.
	Mode() filemode.FileMode
	// Path returns the complete Path to the file, including the filename.
	Path() string
}

File contains all the file metadata necessary to print some patch formats.

type FilePatch

type FilePatch interface {
	// IsBinary returns true if this patch is representing a binary file.
	IsBinary() bool
	// Files returns the from and to Files, with all the necessary metadata to
	// about them. If the patch creates a new file, "from" will be nil.
	// If the patch deletes a file, "to" will be nil.
	Files() (from, to File)
	// Chunks returns a slice of ordered changes to transform "from" File to
	// "to" File. If the file is a binary one, Chunks will be empty.
	Chunks() []Chunk
}

FilePatch represents the necessary steps to transform one file to another.

type Operation

type Operation int

Operation defines the operation of a diff item.

const (
	// Equal item represents a equals diff.
	Equal Operation = iota
	// Add item represents an insert diff.
	Add
	// Delete item represents a delete diff.
	Delete
)

type Patch

type Patch interface {
	// FilePatches returns a slice of patches per file.
	FilePatches() []FilePatch
	// Message returns an optional message that can be at the top of the
	// Patch representation.
	Message() string
}

Patch represents a collection of steps to transform several files.

type UnifiedEncoder

type UnifiedEncoder struct {
	io.Writer
	// contains filtered or unexported fields
}

UnifiedEncoder encodes an unified diff into the provided Writer. It does not support similarity index for renames or sorting hash representations.

func NewUnifiedEncoder

func NewUnifiedEncoder(w io.Writer, contextLines int) *UnifiedEncoder

NewUnifiedEncoder returns a new UnifiedEncoder that writes to w.

func (*UnifiedEncoder) Encode

func (e *UnifiedEncoder) Encode(patch Patch) error

Encode encodes patch.

func (*UnifiedEncoder) SetColor

func (e *UnifiedEncoder) SetColor(colorConfig ColorConfig) *UnifiedEncoder

SetColor sets e's color configuration and returns e.

func (*UnifiedEncoder) SetDstPrefix

func (e *UnifiedEncoder) SetDstPrefix(prefix string) *UnifiedEncoder

SetDstPrefix sets e's dstPrefix and returns e.

func (*UnifiedEncoder) SetSrcPrefix

func (e *UnifiedEncoder) SetSrcPrefix(prefix string) *UnifiedEncoder

SetSrcPrefix sets e's srcPrefix and returns e.

Jump to

Keyboard shortcuts

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