1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-01 08:47:40 -04:00
gitea/vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go
Lauris BH 08bf443016 Implement git refs API for listing references (branches, tags and other) (#5354)
* Inital routes to git refs api

* Git refs API implementation

* Update swagger

* Fix copyright

* Make swagger happy add basic test

* Fix test

* Fix test again :)
2018-11-27 16:52:20 -05:00

46 lines
1.2 KiB
Go

// Package diff implements line oriented diffs, similar to the ancient
// Unix diff command.
//
// The current implementation is just a wrapper around Sergi's
// go-diff/diffmatchpatch library, which is a go port of Neil
// Fraser's google-diff-match-patch code
package diff
import (
"bytes"
"github.com/sergi/go-diff/diffmatchpatch"
)
// Do computes the (line oriented) modifications needed to turn the src
// string into the dst string.
func Do(src, dst string) (diffs []diffmatchpatch.Diff) {
dmp := diffmatchpatch.New()
wSrc, wDst, warray := dmp.DiffLinesToRunes(src, dst)
diffs = dmp.DiffMainRunes(wSrc, wDst, false)
diffs = dmp.DiffCharsToLines(diffs, warray)
return diffs
}
// Dst computes and returns the destination text.
func Dst(diffs []diffmatchpatch.Diff) string {
var text bytes.Buffer
for _, d := range diffs {
if d.Type != diffmatchpatch.DiffDelete {
text.WriteString(d.Text)
}
}
return text.String()
}
// Src computes and returns the source text
func Src(diffs []diffmatchpatch.Diff) string {
var text bytes.Buffer
for _, d := range diffs {
if d.Type != diffmatchpatch.DiffInsert {
text.WriteString(d.Text)
}
}
return text.String()
}