https://github.com/valsov/git-diff
Git diff algorithms implementation
https://github.com/valsov/git-diff
Last synced: about 1 year ago
JSON representation
Git diff algorithms implementation
- Host: GitHub
- URL: https://github.com/valsov/git-diff
- Owner: valsov
- Created: 2023-09-29T19:26:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-14T17:50:38.000Z (over 2 years ago)
- Last Synced: 2025-01-26T05:41:32.789Z (about 1 year ago)
- Language: Go
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GitDiff
Git diff algorithm implementation. The program structure allows for easy addition of diff algorithms.
Currently, only [Myers diff](http://www.xmailserver.org/diff2.pdf) is implemented.
## Example use
```go
input1 := `DELETED
UNCHANGED
UNCHANGED`
previous := gitdiff.NewDocument(input1)
input2 := `ADDED
UNCHANGED
UNCHANGED
ADDED`
current := gitdiff.NewDocument(input2)
differ, _ := gitdiff.NewDiffProducer(gitdiff.MYERS_DIFF)
diffs, err := differ.ComputeDiff(previous, current, -1) // -1 to include all lines, not only changed ones
```
The diffs can then be handled as you like, or printed using the `printer` utility. The above example would produce this:
```diff
- 1 DELETED
+ 1 ADDED
2 2 UNCHANGED
3 3 UNCHANGED
+ 4 ADDED
```