Skip to content

sergi/go-diff/pull/125 - Fix: DiffLinesToChars hash error. #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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
Expand All @@ -22,7 +22,7 @@ package main
import (
"fmt"

"github.com/sergi/go-diff/diffmatchpatch"
"github.com/katbyte/sergi-go-diff/diffmatchpatch"
)

const (
Expand All @@ -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.

Expand Down
15 changes: 8 additions & 7 deletions diffmatchpatch/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ","
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,4 +8,4 @@ require (
gopkg.in/yaml.v2 v2.2.4 // indirect
)

go 1.12
go 1.18