Documentation ¶
Overview ¶
Package patch implements parsing and execution of the textual and binary patch descriptions used by version control tools such as CVS, Git, Mercurial, and Subversion.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPatchFailure = os.NewError("patch did not apply cleanly")
Functions ¶
This section is empty.
Types ¶
type Diff ¶
type Diff interface { // Apply applies the changes listed in the diff // to the string s, returning the new version of the string. // Note that the string s need not be a text string. Apply(old []byte) (new []byte, err os.Error) }
A Diff is any object that describes changes to transform an old byte stream to a new one.
var NoDiff Diff = noDiffType(0)
NoDiff is a no-op Diff implementation: it passes the old data through unchanged.
type File ¶
type File struct { Verb Verb Src string // source for Verb == Copy, Verb == Rename Dst string OldMode, NewMode int // 0 indicates not used Diff // changes to data; == NoDiff if operation does not edit file }
A File represents a collection of changes to be made to a single file.
type GitBinaryLiteral ¶
type GitBinaryLiteral struct { OldSHA1 []byte // if non-empty, the SHA1 hash of the original New []byte // the new contents }
GitBinaryLiteral represents a Git binary literal diff.
type Op ¶
type Op struct { Verb Verb // action Src string // source file Dst string // destination file Mode int // mode for destination (if non-zero) Data []byte // data for destination (if non-nil) }
An Op is a single operation to execute to apply a patch.
type Set ¶
A Set represents a set of patches to be applied as a single atomic unit. Patch sets are often preceded by a descriptive header.
func Parse ¶
Parse patches the patch text to create a patch Set. The patch text typically comprises a textual header and a sequence of file patches, as would be generated by CVS, Subversion, Mercurial, or Git.
func (*Set) Apply ¶
Apply applies the patch set to the files named in the patch set, constructing an in-memory copy of the new file state. It is the client's job to write the changes to the file system if desired.
The function readFile should return the contents of the named file. Typically this function will be io.ReadFile.
type SyntaxError ¶
type SyntaxError string
A SyntaxError represents a syntax error encountered while parsing a patch.
func (SyntaxError) String ¶
func (e SyntaxError) String() string
type TextChunk ¶
A TextChunk specifies an edit to a section of a file: the text beginning at Line, which should be exactly Old, is to be replaced with New.
Notes ¶
Bugs ¶
The Git binary delta format is not implemented, only Git binary literals.