Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit f663a93

Browse files
authored
Merge pull request #388 from ajnavarro/feature/commit-diff
format/diff: unified diff encoder and public API
2 parents 2ff77a8 + 65416cf commit f663a93

File tree

13 files changed

+1614
-1
lines changed

13 files changed

+1614
-1
lines changed

COMPATIBILITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ is supported by go-git.
3939
| **patching** |
4040
| apply ||
4141
| cherry-pick ||
42-
| diff | |
42+
| diff | | Patch object with UnifiedDiff output representation |
4343
| rebase ||
4444
| revert ||
4545
| **debugging** |

plumbing/format/diff/patch.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

Comments
 (0)