diff

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColoredText

func ColoredText(d *DiffSolution) string

func DiffToHTML

func DiffToHTML(a, b string) (string, error)

func DiffToText

func DiffToText(a, b string) string

func HTML

func HTML(d *DiffSolution) string

HTML builds up a html diff. Here be dragons! This is meant for the delta GUI.

func HTMLLine

func HTMLLine(d *DiffSolution) (string, string)

HTMLLine renders a diff solution into a before and after string. Words are added one at a time, and changes are marked with spans.

func Text

func Text(d *DiffSolution) string

Types

type DiffSolution

type DiffSolution struct {
	Lines [][3]string
}

DiffSolution contains a set of lines, where each element of lines comprises the left and right line, and whether the change was from A or B.

func DiffLine

func DiffLine(a, b string) *DiffSolution

DiffLine diffs on words

func HistogramDiff

func HistogramDiff(a, b string) *DiffSolution

HistogramDiff uses the histogram diff algorithm to generate a line-based diff between two strings

func SequenceDiff

func SequenceDiff(a, b string) *DiffSolution

SequenceDiff two strings using dynamic programming and return a DiffSolution.

func (*DiffSolution) HTML

func (d *DiffSolution) HTML() (*bytes.Buffer, error)

func (*DiffSolution) PostProcess

func (d *DiffSolution) PostProcess()

PostProcess loops over the solution. For each changed region, see if we can move it forward. i.e. if we have the following changeset:

a [b c d] b c

then we move the modified region forward so we have instead:

a b c [d b c]

this heuristic only moves additions or deletions (but never both in a move).

func (*DiffSolution) Text

func (d *DiffSolution) Text() string

type HistogramDiffer

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

HistogramDiffer implements the histogram diff algorithm.

func NewHistogramDiffer

func NewHistogramDiffer(a, b []string) *HistogramDiffer

NewHistogramDiffer returns a HistogramDiffer which diffs the given sequence of words.

func (*HistogramDiffer) Solve

func (h *HistogramDiffer) Solve() *DiffSolution

Solve returns a DiffSolution. Internally it uses solveRange to find all matching regions, then it uses the standard differ to create diffs on the intra-region area.

type LineSource

type LineSource string

LineSource indicates the origin of the solution line.

const (
	Unknown          LineSource = ""
	LineFromA        LineSource = "<"
	LineFromB        LineSource = ">"
	LineFromBoth     LineSource = "="
	LineFromBothEdit LineSource = "~"
)

These are valid values for LineSource.

type Metadata

type Metadata struct {
	From      string `json:"from"`
	To        string `json:"to"`
	Merged    string `json:"merged"`
	Dir       string `json:"dir"`
	Change    change `json:"change"`
	Hash      string `json:"hash"`
	DirHash   string `json:"dirhash"`
	Timestamp int64  `json:"timestamp"`
}

type SequenceDiffer

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

SequenceDiffer computes a diff using a dynamic programming algorithm.

func NewSequenceDiffer

func NewSequenceDiffer(a, b []string) *SequenceDiffer

NewSequenceDiffer returns a new SequenceDiffer to compare two lists of strings.

func (*SequenceDiffer) Solve

func (d *SequenceDiffer) Solve() *DiffSolution

Solve the diff using dyanmic programming.

type Solver

type Solver interface {
	Solve() *DiffSolution
}

Solver is an interface implemented by the diff algorithms.

Jump to

Keyboard shortcuts

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