diff

package module
v0.0.0-...-b6b7b67 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2016 License: MIT Imports: 5 Imported by: 8

README

GoDoc License Build Status

go-diff

Library for generating Git-style diff patchsets in Go.

Built to be used in the pure-Go implementation of the Git backend for sourcegraph's go-vcs.

Status: Prototyping. None of the backends produce complete output yet, but the difflib one is closest and least broken.

Features

  • Git-style patch headers for each file (are there other styles to support?).
  • Bring your own diff algorithm by implementing the Differ interface.
  • Includes a few diffing backends:

Sponsors

Work on this package is sponsored by Sourcegraph.

License

MIT.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyComparsion = errors.New("no objects to compare, both are empty")

ErrEmptyComparison is used when both src and dst are EmptyObjects

Functions

This section is empty.

Types

type Differ

type Differ interface {
	// Diff writes a generated patch to out for the diff between a and b.
	Diff(out io.Writer, a io.ReadSeeker, b io.ReadSeeker) error
}

Differ supplies a stream-based diffing algorithm implementation.

func DefaultDiffer

func DefaultDiffer() Differ

DefaultDiffer returns a diffmatchpatch-based differ.

type Object

type Object struct {
	io.ReadSeeker
	// ID is the sha1 of the object
	ID [20]byte
	// Path is the root-relative path of the object
	Path string
	// Mode is the entry mode of the object
	Mode int
}

Object is the minimum representation for generating diffs with git-style headers.

var EmptyObject Object

EmptyObject can be used when there is no corresponding src or dst entry, such as during deletions or creations.

type Writer

type Writer struct {
	io.Writer
	Differ
	SrcPrefix string
	DstPrefix string
}

Writer writes diffs using a given Differ including git-style headers between each patch.

func (*Writer) Diff

func (w *Writer) Diff(src, dst Object) error

Diff writes the header and the generated the diff body when appropriate.

func (*Writer) WriteDiff

func (w *Writer) WriteDiff(a, b io.ReadSeeker) error

WriteDiff performs a Diff between a and b and writes only the resulting diff. It does not write the header.

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(src, dst Object) error

WriteHeader writes only the header for the comparison between the src and dst Objects.

Directories

Path Synopsis
This package implements the diff.Differ interface using github.com/mb0/diff as a backend.
This package implements the diff.Differ interface using github.com/mb0/diff as a backend.
This package implements the diff.Differ interface using diffmatchpatch as a backend
This package implements the diff.Differ interface using diffmatchpatch as a backend
This package implements the diff.Differ interface using github.com/mb0/diff as a backend.
This package implements the diff.Differ interface using github.com/mb0/diff as a backend.

Jump to

Keyboard shortcuts

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