diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-06-01 03:34:46 +0800 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-05-31 20:34:46 +0100 |
commit | 8a343dda39b187627db6ffb4c24a6e0ae615867b (patch) | |
tree | c72f6c3d7ec007f5c085ca343116e7683c3f8693 /vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go | |
parent | fb4438a815b013895f3171f8f2f1ed22f79596de (diff) | |
download | gitea-8a343dda39b187627db6ffb4c24a6e0ae615867b.tar.gz gitea-8a343dda39b187627db6ffb4c24a6e0ae615867b.zip |
update go git from v4.10.0 to v4.11.0 (#7096)
Diffstat (limited to 'vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go')
-rw-r--r-- | vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go b/vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go index f49ae55bae..6142ed0515 100644 --- a/vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go +++ b/vendor/gopkg.in/src-d/go-git.v4/utils/diff/diff.go @@ -8,14 +8,30 @@ package diff import ( "bytes" + "time" "github.com/sergi/go-diff/diffmatchpatch" ) // Do computes the (line oriented) modifications needed to turn the src -// string into the dst string. +// string into the dst string. The underlying algorithm is Meyers, +// its complexity is O(N*d) where N is min(lines(src), lines(dst)) and d +// is the size of the diff. func Do(src, dst string) (diffs []diffmatchpatch.Diff) { + // the default timeout is time.Second which may be too small under heavy load + return DoWithTimeout(src, dst, time.Hour) +} + +// DoWithTimeout computes the (line oriented) modifications needed to turn the src +// string into the dst string. The `timeout` argument specifies the maximum +// amount of time it is allowed to spend in this function. If the timeout +// is exceeded, the parts of the strings which were not considered are turned into +// a bulk delete+insert and the half-baked suboptimal result is returned at once. +// The underlying algorithm is Meyers, its complexity is O(N*d) where N is +// min(lines(src), lines(dst)) and d is the size of the diff. +func DoWithTimeout (src, dst string, timeout time.Duration) (diffs []diffmatchpatch.Diff) { dmp := diffmatchpatch.New() + dmp.DiffTimeout = timeout wSrc, wDst, warray := dmp.DiffLinesToRunes(src, dst) diffs = dmp.DiffMainRunes(wSrc, wDst, false) diffs = dmp.DiffCharsToLines(diffs, warray) |