patch

package
v0.0.0-...-305ff81 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compute

func Compute(doc Document, lineIndices []int, dir Direction) (string, error)

func GetLines

func GetLines(content string) []line

func GetNextHunk

func GetNextHunk(lines []Line, index int) int

func TryGetHunkInformation

func TryGetHunkInformation(hunkLine string) (hunkInfo, bool)

Hunk information looks like this: @@ -0,0 +1,29 @@ <maybe some garbage afterwards>

func TryParseRange

func TryParseRange(s, marker string) (rng, bool)

Types

type Changes

type Changes struct {
	Path    string
	OldPath string

	Mode    string
	OldMode string
}

func ChangesFromHeader

func ChangesFromHeader(header []Line) Changes

type Direction

type Direction int
const (
	Stage Direction = iota
	Unstage
	Reset
)

func (Direction) IsUndo

func (d Direction) IsUndo() bool

type Document

type Document struct {
	Height  int
	Width   int
	Entries []Entry
	Lines   []Line
}

func ParseDocument

func ParseDocument(patches []string) Document

func (Document) FindEntry

func (d Document) FindEntry(lineIndex int) (Entry, bool)

func (Document) FindEntryIndex

func (d Document) FindEntryIndex(lineIndex int) int

func (Document) GetLine

func (d Document) GetLine(index int) string

type Entry

type Entry struct {
	Offset  int
	Length  int
	Hunks   []Hunk
	Changes Changes
}

func (Entry) ContainsLine

func (pe Entry) ContainsLine(l int) bool

func (Entry) FindHunk

func (pe Entry) FindHunk(lineIndex int) (Hunk, bool)

func (Entry) FindHunkIndex

func (pe Entry) FindHunkIndex(lineIndex int) int

func (Entry) LineEnd

func (pe Entry) LineEnd() int

func (Entry) LineStart

func (pe Entry) LineStart() int

type Hunk

type Hunk struct {
	Offset    int
	Length    int
	OldStart  int
	OldLength int
	NewStart  int
	NewLength int
}

func (Hunk) ContainsLine

func (h Hunk) ContainsLine(l int) bool

func (Hunk) LineEnd

func (h Hunk) LineEnd() int

func (Hunk) LineStart

func (h Hunk) LineStart() int

type Line

type Line struct {
	Kind      LineKind
	Text      string
	LineBreak string
}

func ParseLines

func ParseLines(lines []line) []Line

func (Line) String

func (l Line) String() string

type LineKind

type LineKind int
const (
	DiffLine LineKind = iota
	HeaderLine
	HunkLine
	ContextLine
	AdditionLine
	RemovalLine
	NoEndOfLineLine
)

func (LineKind) IsAdditionOrRemoval

func (lk LineKind) IsAdditionOrRemoval() bool

func (LineKind) String

func (i LineKind) String() string

Jump to

Keyboard shortcuts

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