|
| 1 | +package diff |
| 2 | + |
| 3 | +import ( |
| 4 | + "gopkg.in/src-d/go-git.v4/plumbing" |
| 5 | + "gopkg.in/src-d/go-git.v4/plumbing/filemode" |
| 6 | +) |
| 7 | + |
| 8 | +// Operation defines the operation of a diff item. |
| 9 | +type Operation int |
| 10 | + |
| 11 | +const ( |
| 12 | + // Equal item represents a equals diff. |
| 13 | + Equal Operation = iota |
| 14 | + // Add item represents an insert diff. |
| 15 | + Add |
| 16 | + // Delete item represents a delete diff. |
| 17 | + Delete |
| 18 | +) |
| 19 | + |
| 20 | +// Patch represents a collection of steps to transform several files. |
| 21 | +type Patch interface { |
| 22 | + // FilePatches returns a slice of patches per file. |
| 23 | + FilePatches() []FilePatch |
| 24 | + // Message returns an optional message that can be at the top of the |
| 25 | + // Patch representation. |
| 26 | + Message() string |
| 27 | +} |
| 28 | + |
| 29 | +// FilePatch represents the necessary steps to transform one file to another. |
| 30 | +type FilePatch interface { |
| 31 | + // IsBinary returns true if this patch is representing a binary file. |
| 32 | + IsBinary() bool |
| 33 | + // Files returns the from and to Files, with all the necessary metadata to |
| 34 | + // about them. If the patch creates a new file, "from" will be nil. |
| 35 | + // If the patch deletes a file, "to" will be nil. |
| 36 | + Files() (from, to File) |
| 37 | + // Chunks returns a slice of ordered changes to transform "from" File to |
| 38 | + // "to" File. If the file is a binary one, Chunks will be empty. |
| 39 | + Chunks() []Chunk |
| 40 | +} |
| 41 | + |
| 42 | +// File contains all the file metadata necessary to print some patch formats. |
| 43 | +type File interface { |
| 44 | + // Hash returns the File Hash. |
| 45 | + Hash() plumbing.Hash |
| 46 | + // Mode returns the FileMode. |
| 47 | + Mode() filemode.FileMode |
| 48 | + // Path returns the complete Path to the file, including the filename. |
| 49 | + Path() string |
| 50 | +} |
| 51 | + |
| 52 | +// Chunk represents a portion of a file transformation to another. |
| 53 | +type Chunk interface { |
| 54 | + // Content contains the portion of the file. |
| 55 | + Content() string |
| 56 | + // Type contains the Operation to do with this Chunk. |
| 57 | + Type() Operation |
| 58 | +} |
0 commit comments