Documentation ¶
Overview ¶
Copyright (c) 2012-2016 The go-diff authors. All rights reserved. https://github.com/sergi/go-diff See the included LICENSE file for license details.
go-diff is a Go implementation of Google's Diff, Match, and Patch library Original library is Copyright (c) 2006 Google Inc. http://code.google.com/p/google-diff-match-patch/
Refer to https://github.com/pascalkuthe/imara-diff reimplemented in Golang.
Copyright (c) 2024 epic labs Package diff3 implements a three-way merge algorithm Original version in Javascript by Bryan Housel @bhousel: https://github.com/bhousel/node-diff3, which in turn is based on project Synchrotron, created by Tony Garnock-Jones. For more detail please visit: http://homepages.kcbbs.gen.nz/tonyg/projects/synchrotron.html https://github.com/tonyg/synchrotron
Ported to go by Javier Peletier @jpeletier
SOURCE: https://github.com/epiclabs-io/diff3
SPDX-License-Identifier: MIT
Copyright (c) 2014-2021 Akinori Hattori <hattya@gmail.com> SPDX-License-Identifier: MIT SOURCE: https://github.com/hattya/go.diff
Package diff implements the difference algorithm, which is based upon S. Wu, U. Manber, G. Myers, and W. Miller, "An O(NP) Sequence Comparison Algorithm" August 1989.
Copyright 2019 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func Merge(ctx context.Context, o, a, b string, labelO, labelA, labelB string) (string, bool, error)
- type Algorithm
- type Change
- func HistogramDiff[E comparable](ctx context.Context, L1, L2 []E) ([]Change, error)
- func MinimalDiff[E comparable](ctx context.Context, L1 []E, L2 []E) ([]Change, error)
- func MyersDiff[E comparable](ctx context.Context, L1 []E, L2 []E) ([]Change, error)
- func OnpDiff[E comparable](ctx context.Context, L1, L2 []E) ([]Change, error)
- func PatienceDiff[E comparable](ctx context.Context, L1 []E, L2 []E) ([]Change, error)
- type Conflict
- type Dfio
- type Diff3MergeResult
- type FastArrayNegativeIndices
- type FastIntArray
- type File
- type FileStat
- type Hunk
- type Lcs
- type LcsSearch
- type Line
- type Operation
- type Options
- type Sink
- func (s *Sink) AsStringDiff(o []Dfio[int]) []StringDiff
- func (s *Sink) ScanLines(r io.Reader) ([]int, error)
- func (s *Sink) ScanRawLines(r io.Reader) ([]int, error)
- func (s *Sink) SplitLines(text string) []int
- func (s *Sink) SplitRawLines(text string) []int
- func (s *Sink) ToUnified(from, to *File, changes []Change, linesA, linesB []int, contextLines int) *Unified
- func (s *Sink) WriteLine(w io.Writer, E ...int)
- type SnakePath
- type StringDiff
- type Unified
- type UnifiedEncoder
Constants ¶
const ( // Sep1 signifies the start of a conflict. Sep1 = "<<<<<<<" // Sep2 signifies the middle of a conflict. Sep2 = "=======" // Sep3 signifies the end of a conflict. Sep3 = ">>>>>>>" )
const ( NEWLINE_RAW = iota NEWLINE_LF NEWLINE_CRLF )
const DefaultContextLines = 3
DefaultContextLines is the number of unchanged lines of surrounding context displayed by Unified. Use ToUnified to specify a different value.
const MaxChainLen = 63
const (
ZERO_OID = "0000000000000000000000000000000000000000000000000000000000000000" // zeta zero OID
)
Variables ¶
var (
ErrUnsupportedAlgorithm = errors.New("unsupport algorithm")
)
Functions ¶
Types ¶
type Change ¶
type Change struct { P1 int // before: position in before P2 int // after: position in after Del int // number of elements that deleted from a Ins int // number of elements that inserted into b }
func HistogramDiff ¶
func HistogramDiff[E comparable](ctx context.Context, L1, L2 []E) ([]Change, error)
HistogramDiff: calculates the difference using the histogram algorithm
func MinimalDiff ¶
func MinimalDiff[E comparable](ctx context.Context, L1 []E, L2 []E) ([]Change, error)
MinimalDiff: Myers: An O(ND) Difference Algorithm and Its Variations
func MyersDiff ¶
func MyersDiff[E comparable](ctx context.Context, L1 []E, L2 []E) ([]Change, error)
MyersDiff: An O(ND) diff algorithm that has a quadratic space worst-case complexity.
func OnpDiff ¶
func OnpDiff[E comparable](ctx context.Context, L1, L2 []E) ([]Change, error)
OnpDiff returns the differences between []E. It makes O(NP) (the worst case) calls to equal.
func PatienceDiff ¶
func PatienceDiff[E comparable](ctx context.Context, L1 []E, L2 []E) ([]Change, error)
PatienceDiff: Calculates the difference using the patience algorithm
type Conflict ¶
type Conflict[E comparable] struct { // contains filtered or unexported fields }
Conflict describes a merge conflict
type Dfio ¶
type Dfio[E comparable] struct { T Operation E []E }
func DiffSlices ¶
func DiffSlices[E comparable](ctx context.Context, S1, S2 []E) ([]Dfio[E], error)
type Diff3MergeResult ¶
type Diff3MergeResult[E comparable] struct { // contains filtered or unexported fields }
Diff3MergeResult describes a merge result
func Diff3Merge ¶
func Diff3Merge[E comparable](a, o, b []E, excludeFalseConflicts bool) []*Diff3MergeResult[E]
Diff3Merge applies the output of diff3MergeIndices to actually construct the merged file; the returned result alternates between 'ok' and 'conflict' blocks.
type FastArrayNegativeIndices ¶
type FastArrayNegativeIndices struct {
// contains filtered or unexported fields
}
An array that supports fast negative indices.
type FastIntArray ¶
type FastIntArray struct {
// contains filtered or unexported fields
}
func NewFastIntArray ¶
func NewFastIntArray() *FastIntArray
type Hunk ¶
type Hunk struct { // The line in the original source where the hunk starts. FromLine int `json:"from_line"` // The line in the original source where the hunk finishes. ToLine int `json:"to_line"` // The set of line based edits to apply. Lines []Line `json:"lines,omitempty"` }
Hunk represents a contiguous set of line edits to apply.
type LcsSearch ¶
type LcsSearch[E comparable] struct { // contains filtered or unexported fields }
type Sink ¶
func (*Sink) AsStringDiff ¶
func (s *Sink) AsStringDiff(o []Dfio[int]) []StringDiff
func (*Sink) SplitLines ¶
func (*Sink) SplitRawLines ¶
type SnakePath ¶
type SnakePath struct {
// contains filtered or unexported fields
}
func NewSnakePath ¶
type StringDiff ¶
StringDiff represents one diff operation
type Unified ¶
type Unified struct { // From is the name of the original file. From *File `json:"from,omitempty"` // To is the name of the modified file. To *File `json:"to,omitempty"` // IsBinary returns true if this patch is representing a binary file. IsBinary bool `json:"binary"` // Fragments returns true if this patch is representing a fragments file. IsFragments bool `json:"fragments"` // Message prefix, eg: warning: something Message string `json:"message"` // Hunks is the set of edit Hunks needed to transform the file content. Hunks []*Hunk `json:"hunks,omitempty"` }
unified represents a set of edits as a unified diff.
type UnifiedEncoder ¶
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) *UnifiedEncoder
NewUnifiedEncoder returns a new UnifiedEncoder that writes to w.
func (*UnifiedEncoder) Encode ¶
func (e *UnifiedEncoder) Encode(patches []*Unified) error
func (*UnifiedEncoder) SetColor ¶
func (e *UnifiedEncoder) SetColor(colorConfig color.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.