diff --git a/Makefile b/Makefile index 710bc83..082c9ec 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: all clean clean-coverage install install-dependencies install-tools lint test test-verbose test-with-coverage export ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) -export PKG := github.com/sergi/go-diff +export PKG := github.com/katbyte/sergi-go-diff export ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) $(eval $(ARGS):;@:) # turn arguments into do-nothing targets diff --git a/README.md b/README.md index 597437b..666a3de 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# go-diff [![GoDoc](https://godoc.org/github.com/sergi/go-diff?status.png)](https://godoc.org/github.com/sergi/go-diff/diffmatchpatch) [![Build Status](https://travis-ci.org/sergi/go-diff.svg?branch=master)](https://travis-ci.org/sergi/go-diff) [![Coverage Status](https://coveralls.io/repos/sergi/go-diff/badge.png?branch=master)](https://coveralls.io/r/sergi/go-diff?branch=master) +# go-diff [![GoDoc](https://godoc.org/github.com/katbyte/sergi-go-diff?status.png)](https://godoc.org/github.com/katbyte/sergi-go-diff/diffmatchpatch) [![Build Status](https://travis-ci.org/katbyte/sergi-go-diff.svg?branch=master)](https://travis-ci.org/katbyte/sergi-go-diff) [![Coverage Status](https://coveralls.io/repos/katbyte/sergi-go-diff/badge.png?branch=master)](https://coveralls.io/r/katbyte/sergi-go-diff?branch=master) go-diff offers algorithms to perform operations required for synchronizing plain text: @@ -9,7 +9,7 @@ go-diff offers algorithms to perform operations required for synchronizing plain ## Installation ```bash -go get -u github.com/sergi/go-diff/... +go get -u github.com/katbyte/sergi-go-diff/... ``` ## Usage @@ -22,7 +22,7 @@ package main import ( "fmt" - "github.com/sergi/go-diff/diffmatchpatch" + "github.com/katbyte/sergi-go-diff/diffmatchpatch" ) const ( @@ -41,11 +41,11 @@ func main() { ## Found a bug or are you missing a feature in go-diff? -Please make sure to have the latest version of go-diff. If the problem still persists go through the [open issues](https://github.com/sergi/go-diff/issues) in the tracker first. If you cannot find your request just open up a [new issue](https://github.com/sergi/go-diff/issues/new). +Please make sure to have the latest version of go-diff. If the problem still persists go through the [open issues](https://github.com/katbyte/sergi-go-diff/issues) in the tracker first. If you cannot find your request just open up a [new issue](https://github.com/katbyte/sergi-go-diff/issues/new). ## How to contribute? -You want to contribute to go-diff? GREAT! If you are here because of a bug you want to fix or a feature you want to add, you can just read on. Otherwise we have a list of [open issues in the tracker](https://github.com/sergi/go-diff/issues). Just choose something you think you can work on and discuss your plans in the issue by commenting on it. +You want to contribute to go-diff? GREAT! If you are here because of a bug you want to fix or a feature you want to add, you can just read on. Otherwise we have a list of [open issues in the tracker](https://github.com/katbyte/sergi-go-diff/issues). Just choose something you think you can work on and discuss your plans in the issue by commenting on it. Please make sure that every behavioral change is accompanied by test cases. Additionally, every contribution must pass the `lint` and `test` Makefile targets which can be run using the following commands in the repository root directory. diff --git a/diffmatchpatch/diff.go b/diffmatchpatch/diff.go index 2a9f2dc..a6f6d1f 100644 --- a/diffmatchpatch/diff.go +++ b/diffmatchpatch/diff.go @@ -34,7 +34,7 @@ const ( DiffInsert Operation = 1 // DiffEqual item represents an equal diff. DiffEqual Operation = 0 - //IndexSeparator is used to seperate the array indexes in an index string + // IndexSeparator is used to seperate the array indexes in an index string IndexSeparator = "," ) @@ -1168,7 +1168,7 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string { // DiffText1 computes and returns the source text (all equalities and deletions). func (dmp *DiffMatchPatch) DiffText1(diffs []Diff) string { - //StringBuilder text = new StringBuilder() + // StringBuilder text = new StringBuilder() var text bytes.Buffer for _, aDiff := range diffs { @@ -1312,18 +1312,19 @@ func (dmp *DiffMatchPatch) DiffFromDelta(text1 string, delta string) (diffs []Di func (dmp *DiffMatchPatch) diffLinesToStrings(text1, text2 string) (string, string, []string) { // '\x00' is a valid character, but various debuggers don't like it. So we'll insert a junk entry to avoid generating a null character. lineArray := []string{""} // e.g. lineArray[4] == 'Hello\n' + lineHash := make(map[string]int) + lineHash[""] = 0 - //Each string has the index of lineArray which it points to - strIndexArray1 := dmp.diffLinesToStringsMunge(text1, &lineArray) - strIndexArray2 := dmp.diffLinesToStringsMunge(text2, &lineArray) + // Each string has the index of lineArray which it points to + strIndexArray1 := dmp.diffLinesToStringsMunge(text1, &lineArray, lineHash) + strIndexArray2 := dmp.diffLinesToStringsMunge(text2, &lineArray, lineHash) return intArrayToString(strIndexArray1), intArrayToString(strIndexArray2), lineArray } // diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []string. -func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string) []uint32 { +func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string, lineHash map[string]int) []uint32 { // Walk the text, pulling out a substring for each line. text.split('\n') would would temporarily double our memory footprint. Modifying text would create many large strings to garbage collect. - lineHash := map[string]int{} // e.g. lineHash['Hello\n'] == 4 lineStart := 0 lineEnd := -1 strs := []uint32{} diff --git a/go.mod b/go.mod index d46c77d..341a865 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/sergi/go-diff +module github.com/katbyte/sergi-go-diff require ( github.com/davecgh/go-spew v1.1.1 // indirect @@ -8,4 +8,4 @@ require ( gopkg.in/yaml.v2 v2.2.4 // indirect ) -go 1.12 +go 1.18