{"modulePath":"sourcegraph.com/sourcegraph/go-diff","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package diff\n\n\tPackage diff is a generated protocol buffer package.\n\n\tIt is generated from these files:\n\t\tdiff.proto\n\n\tIt has these top-level messages:\n\t\tFileDiff\n\t\tHunk\n\t\tStat\n\nPackage diff provides a parser for unified diffs.\n\n## Variables\n\n```go\nvar (\n\tErrInvalidLengthDiff = fmt.Errorf(\"proto: negative length found during unmarshaling\")\n\tErrIntOverflowDiff   = fmt.Errorf(\"proto: integer overflow\")\n)\n```\n\n```go\nvar (\n\t// ErrNoFileHeader is when a file unified diff has no file header\n\t// (i.e., the lines that begin with \"---\" and \"+++\").\n\tErrNoFileHeader = errors.New(\"expected file header, got EOF\")\n\n\t// ErrBadFileHeader is when a file unified diff has a malformed\n\t// file header (i.e., the lines that begin with \"---\" and \"+++\").\n\tErrBadFileHeader = errors.New(\"bad file header\")\n\n\t// ErrExtendedHeadersEOF is when an EOF was encountered while reading extended file headers, which means that there were no ---/+++ headers encountered before hunks (if any) began.\n\tErrExtendedHeadersEOF = errors.New(\"expected file header while reading extended headers, got EOF\")\n)\n```\n\n```go\nvar ErrNoHunkHeader = errors.New(\"no hunk header\")\n```\nErrNoHunkHeader indicates that a unified diff hunk header was expected but not found during parsing.\n\n## Functions\n\n```go\nfunc PrintFileDiff(d *FileDiff) ([]byte, error)\n```\nPrintFileDiff prints a FileDiff in unified diff format.\n\nTODO(sqs): handle escaping whitespace/etc. chars in filenames\n\n```go\nfunc PrintHunks(hunks []*Hunk) ([]byte, error)\n```\nPrintHunks prints diff hunks in unified diff format.\n\n```go\nfunc PrintMultiFileDiff(ds []*FileDiff) ([]byte, error)\n```\nPrintMultiFileDiff prints a multi-file diff in unified diff format.\n\n## Types\n\n```go\ntype ErrBadHunkHeader struct {\n\t// contains filtered or unexported fields\n}\n```\nErrBadHunkHeader indicates that a malformed unified diff hunk header was encountered during parsing.\n\n```go\nfunc (e *ErrBadHunkHeader) Error() string\n```\n\n```go\ntype ErrBadHunkLine struct {\n\tLine []byte\n}\n```\nErrBadHunkLine is when a line not beginning with ' ', '-', '+', or '\\\\' is encountered while reading a hunk. In the context of reading a single hunk or file, it is an unexpected error. In a multi-file diff, however, it indicates that the current file's diff is complete (and remaining diff data will describe another file unified diff).\n\n```go\nfunc (e *ErrBadHunkLine) Error() string\n```\n\n```go\ntype FileDiff struct {\n\t// the original name of the file\n\tOrigName string `protobuf:\"bytes,1,opt,name=OrigName,proto3\" json:\"OrigName,omitempty\"`\n\t// the original timestamp (nil if not present)\n\tOrigTime *pbtypes.Timestamp `protobuf:\"bytes,2,opt,name=OrigTime\" json:\"OrigTime,omitempty\"`\n\t// the new name of the file (often same as OrigName)\n\tNewName string `protobuf:\"bytes,3,opt,name=NewName,proto3\" json:\"NewName,omitempty\"`\n\t// the new timestamp (nil if not present)\n\tNewTime *pbtypes.Timestamp `protobuf:\"bytes,4,opt,name=NewTime\" json:\"NewTime,omitempty\"`\n\t// extended header lines (e.g., git's \"new mode \u003cmode\u003e\", \"rename from \u003cpath\u003e\", etc.)\n\tExtended []string `protobuf:\"bytes,5,rep,name=Extended\" json:\"Extended,omitempty\"`\n\t// hunks that were changed from orig to new\n\tHunks []*Hunk `protobuf:\"bytes,6,rep,name=Hunks\" json:\"Hunks,omitempty\"`\n}\n```\nA FileDiff represents a unified diff for a single file.\n\nA file unified diff has a header that resembles the following:\n\n\t--- oldname\t2009-10-11 15:12:20.000000000 -0700\n\t+++ newname\t2009-10-11 15:12:30.000000000 -0700\n\n```go\nfunc ParseFileDiff(diff []byte) (*FileDiff, error)\n```\nParseFileDiff parses a file unified diff.\n\n```go\nfunc ParseMultiFileDiff(diff []byte) ([]*FileDiff, error)\n```\nParseMultiFileDiff parses a multi-file unified diff. It returns an error if parsing failed as a whole, but does its best to parse as many files in the case of per-file errors. In the case of non-fatal per-file errors, the error return value is null and the Errs field in the returned MultiFileDiff is set.\n\n```go\nfunc (m *FileDiff) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *FileDiff) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*FileDiff) ProtoMessage()\n```\n\n```go\nfunc (m *FileDiff) Reset()\n```\n\n```go\nfunc (m *FileDiff) Size() (n int)\n```\n\n```go\nfunc (d *FileDiff) Stat() Stat\n```\nStat computes the number of lines added/changed/deleted in all hunks in this file's diff.\n\n```go\nfunc (m *FileDiff) String() string\n```\n\n```go\nfunc (m *FileDiff) Unmarshal(data []byte) error\n```\n\n```go\ntype FileDiffReader struct {\n\t// contains filtered or unexported fields\n}\n```\nFileDiffReader reads a unified file diff.\n\n```go\nfunc NewFileDiffReader(r io.Reader) *FileDiffReader\n```\nNewFileDiffReader returns a new FileDiffReader that reads a file unified diff.\n\n```go\nfunc (r *FileDiffReader) HunksReader() *HunksReader\n```\nHunksReader returns a new HunksReader that reads hunks from r. The HunksReader's line and offset (used in error messages) is set to start where the file diff header ended (which means errors have the correct position information).\n\n```go\nfunc (r *FileDiffReader) Read() (*FileDiff, error)\n```\nRead reads a file unified diff, including headers and hunks, from r.\n\n```go\nfunc (r *FileDiffReader) ReadAllHeaders() (*FileDiff, error)\n```\nReadAllHeaders reads the file headers and extended headers (if any) from a file unified diff. It does not read hunks, and the returned FileDiff's Hunks field is nil. To read the hunks, call the (\\*FileDiffReader).HunksReader() method to get a HunksReader and read hunks from that.\n\n```go\nfunc (r *FileDiffReader) ReadExtendedHeaders() ([]string, error)\n```\nReadExtendedHeaders reads the extended header lines, if any, from a unified diff file (e.g., git's \"diff --git a/foo.go b/foo.go\", \"new mode \\\u003cmode\u003e\", \"rename from \\\u003cpath\u003e\", etc.).\n\n```go\nfunc (r *FileDiffReader) ReadFileHeaders() (origName, newName string, origTimestamp, newTimestamp *time.Time, err error)\n```\nReadFileHeaders reads the unified file diff header (the lines that start with \"---\" and \"+++\" with the orig/new file names and timestamps).\n\n```go\ntype Hunk struct {\n\t// starting line number in original file\n\tOrigStartLine int32 `protobuf:\"varint,1,opt,name=OrigStartLine,proto3\" json:\"OrigStartLine,omitempty\"`\n\t// number of lines the hunk applies to in the original file\n\tOrigLines int32 `protobuf:\"varint,2,opt,name=OrigLines,proto3\" json:\"OrigLines,omitempty\"`\n\t// if \u003e 0, then the original file had a 'No newline at end of file' mark at this offset\n\tOrigNoNewlineAt int32 `protobuf:\"varint,3,opt,name=OrigNoNewlineAt,proto3\" json:\"OrigNoNewlineAt,omitempty\"`\n\t// starting line number in new file\n\tNewStartLine int32 `protobuf:\"varint,4,opt,name=NewStartLine,proto3\" json:\"NewStartLine,omitempty\"`\n\t// number of lines the hunk applies to in the new file\n\tNewLines int32 `protobuf:\"varint,5,opt,name=NewLines,proto3\" json:\"NewLines,omitempty\"`\n\t// optional section heading\n\tSection string `protobuf:\"bytes,6,opt,name=Section,proto3\" json:\"Section,omitempty\"`\n\t// 0-indexed line offset in unified file diff (including section headers); this is\n\t// only set when Hunks are read from entire file diff (i.e., when ReadAllHunks is\n\t// called) This accounts for hunk headers, too, so the StartPosition of the first\n\t// hunk will be 1.\n\tStartPosition int32 `protobuf:\"varint,7,opt,name=StartPosition,proto3\" json:\"StartPosition,omitempty\"`\n\t// hunk body (lines prefixed with '-', '+', or ' ')\n\tBody []byte `protobuf:\"bytes,8,opt,name=Body,proto3\" json:\"Body,omitempty\"`\n}\n```\nA Hunk represents a series of changes (additions or deletions) in a file's unified diff.\n\n```go\nfunc ParseHunks(diff []byte) ([]*Hunk, error)\n```\nParseHunks parses hunks from a unified diff. The diff must consist only of hunks and not include a file header; if it has a file header, use ParseFileDiff.\n\n```go\nfunc (m *Hunk) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *Hunk) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*Hunk) ProtoMessage()\n```\n\n```go\nfunc (m *Hunk) Reset()\n```\n\n```go\nfunc (m *Hunk) Size() (n int)\n```\n\n```go\nfunc (h *Hunk) Stat() Stat\n```\nStat computes the number of lines added/changed/deleted in this hunk.\n\n```go\nfunc (m *Hunk) String() string\n```\n\n```go\nfunc (m *Hunk) Unmarshal(data []byte) error\n```\n\n```go\ntype HunksReader struct {\n\t// contains filtered or unexported fields\n}\n```\nA HunksReader reads hunks from a unified diff.\n\n```go\nfunc NewHunksReader(r io.Reader) *HunksReader\n```\nNewHunksReader returns a new HunksReader that reads unified diff hunks from r.\n\n```go\nfunc (r *HunksReader) ReadAllHunks() ([]*Hunk, error)\n```\nReadAllHunks reads all remaining hunks from r. A successful call returns err == nil, not err == EOF. Because ReadAllHunks is defined to read until EOF, it does not treat end of file as an error to be reported.\n\n```go\nfunc (r *HunksReader) ReadHunk() (*Hunk, error)\n```\nReadHunk reads one hunk from r. If there are no more hunks, it returns error io.EOF.\n\n```go\ntype MultiFileDiffReader struct {\n\t// contains filtered or unexported fields\n}\n```\nMultiFileDiffReader reads a multi-file unified diff.\n\n```go\nfunc NewMultiFileDiffReader(r io.Reader) *MultiFileDiffReader\n```\nNewMultiFileDiffReader returns a new MultiFileDiffReader that reads a multi-file unified diff from r.\n\n```go\nfunc (r *MultiFileDiffReader) ReadAllFiles() ([]*FileDiff, error)\n```\nReadAllFiles reads all file unified diffs (including headers and all hunks) remaining in r.\n\n```go\nfunc (r *MultiFileDiffReader) ReadFile() (*FileDiff, error)\n```\nReadFile reads the next file unified diff (including headers and all hunks) from r. If there are no more files in the diff, it returns error io.EOF.\n\n```go\ntype OverflowError string\n```\nOverflowError is returned when we have overflowed into the start of the next file while reading extended headers.\n\n```go\nfunc (e OverflowError) Error() string\n```\n\n```go\ntype ParseError struct {\n\tLine   int   // Line where the error occurred\n\tOffset int64 // Offset where the error occurred\n\tErr    error // The actual error\n}\n```\nA ParseError is a description of a unified diff syntax error.\n\n```go\nfunc (e *ParseError) Error() string\n```\n\n```go\ntype Stat struct {\n\t// number of lines added\n\tAdded int32 `protobuf:\"varint,1,opt,name=Added,proto3\" json:\"\"`\n\t// number of lines changed\n\tChanged int32 `protobuf:\"varint,2,opt,name=Changed,proto3\" json:\"\"`\n\t// number of lines deleted\n\tDeleted int32 `protobuf:\"varint,3,opt,name=Deleted,proto3\" json:\"\"`\n}\n```\nA Stat is a diff stat that represents the number of lines added/changed/deleted.\n\n```go\nfunc (m *Stat) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *Stat) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*Stat) ProtoMessage()\n```\n\n```go\nfunc (m *Stat) Reset()\n```\n\n```go\nfunc (m *Stat) Size() (n int)\n```\n\n```go\nfunc (m *Stat) String() string\n```\n\n```go\nfunc (m *Stat) Unmarshal(data []byte) error\n```\n\n","path":"sourcegraph.com/sourcegraph/go-diff/diff","name":"diff","synopsis":"Package diff is a generated protocol buffer package.","isRedistributable":true}
