Control: tags -1 patch

Patches attached, with a MR submitted at https://salsa.debian.org/go-team/packages/golang-github-sergi-go-diff/-/merge_requests/1
From 4252a5b69e8bdcfb8d312f059529563ac35bd589 Mon Sep 17 00:00:00 2001
From: Andrea Pappacoda <ta...@debian.org>
Date: Tue, 22 Jul 2025 17:29:53 +0200
Subject: [PATCH 1/5] New upstream version 1.4.0

---
 .travis.yml                       |  12 ++--
 diffmatchpatch/diff.go            |  58 +++++++++--------
 diffmatchpatch/diff_test.go       |  69 ++++++++++++++++----
 diffmatchpatch/index.go           |  32 ++++++++++
 diffmatchpatch/index_test.go      |  16 +++++
 diffmatchpatch/patch_test.go      |  25 ++++++++
 diffmatchpatch/stringutil.go      | 102 +++++++++++++++++++++++++++---
 diffmatchpatch/stringutil_test.go |  18 ++++++
 go.mod                            |   4 +-
 go.sum                            |   2 +
 10 files changed, 284 insertions(+), 54 deletions(-)
 create mode 100644 diffmatchpatch/index.go
 create mode 100644 diffmatchpatch/index_test.go

diff --git a/.travis.yml b/.travis.yml
index d8da7c5..9032a0f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,15 @@
 language: go
-
+arch: 
+  - amd64
+  - ppc64le
 os:
   - linux
   - osx
 
 go:
-  - 1.9.x
-  - 1.10.x
-  - 1.11.x
-  - 1.12.x
-  - 1.13.x
+  - 1.13
+  - 1.14
+  - 1.15
 
 sudo: false
 
diff --git a/diffmatchpatch/diff.go b/diffmatchpatch/diff.go
index 2a9f2dc..08c36e7 100644
--- a/diffmatchpatch/diff.go
+++ b/diffmatchpatch/diff.go
@@ -34,8 +34,6 @@ 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 = ","
 )
 
 // Diff represents one diff operation
@@ -406,14 +404,11 @@ func (dmp *DiffMatchPatch) DiffLinesToRunes(text1, text2 string) ([]rune, []rune
 func (dmp *DiffMatchPatch) DiffCharsToLines(diffs []Diff, lineArray []string) []Diff {
 	hydrated := make([]Diff, 0, len(diffs))
 	for _, aDiff := range diffs {
-		chars := strings.Split(aDiff.Text, IndexSeparator)
-		text := make([]string, len(chars))
+		runes := []rune(aDiff.Text)
+		text := make([]string, len(runes))
 
-		for i, r := range chars {
-			i1, err := strconv.Atoi(r)
-			if err == nil {
-				text[i] = lineArray[i1]
-			}
+		for i, r := range runes {
+			text[i] = lineArray[runeToInt(r)]
 		}
 
 		aDiff.Text = strings.Join(text, "")
@@ -1151,13 +1146,28 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
 
 		switch diff.Type {
 		case DiffInsert:
-			_, _ = buff.WriteString("\x1b[32m")
-			_, _ = buff.WriteString(text)
-			_, _ = buff.WriteString("\x1b[0m")
+			lines := strings.Split(text, "\n")
+			for i, line := range lines {
+				_, _ = buff.WriteString("\x1b[32m")
+				_, _ = buff.WriteString(line)
+				if i < len(lines)-1 {
+					_, _ = buff.WriteString("\x1b[0m\n")
+				} else {
+					_, _ = buff.WriteString("\x1b[0m")
+				}
+			}
+
 		case DiffDelete:
-			_, _ = buff.WriteString("\x1b[31m")
-			_, _ = buff.WriteString(text)
-			_, _ = buff.WriteString("\x1b[0m")
+			lines := strings.Split(text, "\n")
+			for i, line := range lines {
+				_, _ = buff.WriteString("\x1b[31m")
+				_, _ = buff.WriteString(line)
+				if i < len(lines)-1 {
+					_, _ = buff.WriteString("\x1b[0m\n")
+				} else {
+					_, _ = buff.WriteString("\x1b[0m")
+				}
+			}
 		case DiffEqual:
 			_, _ = buff.WriteString(text)
 		}
@@ -1310,23 +1320,21 @@ func (dmp *DiffMatchPatch) DiffFromDelta(text1 string, delta string) (diffs []Di
 
 // diffLinesToStrings splits two texts into a list of strings. Each string represents one line.
 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)
 	//Each string has the index of lineArray which it points to
-	strIndexArray1 := dmp.diffLinesToStringsMunge(text1, &lineArray)
-	strIndexArray2 := dmp.diffLinesToStringsMunge(text2, &lineArray)
+	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 {
-	// 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
+// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []index.
+func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string, lineHash map[string]int) []index {
 	lineStart := 0
 	lineEnd := -1
-	strs := []uint32{}
+	strs := []index{}
 
 	for lineEnd < len(text)-1 {
 		lineEnd = indexOf(text, "\n", lineStart)
@@ -1340,11 +1348,11 @@ func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]str
 		lineValue, ok := lineHash[line]
 
 		if ok {
-			strs = append(strs, uint32(lineValue))
+			strs = append(strs, index(lineValue))
 		} else {
 			*lineArray = append(*lineArray, line)
 			lineHash[line] = len(*lineArray) - 1
-			strs = append(strs, uint32(len(*lineArray)-1))
+			strs = append(strs, index(len(*lineArray)-1))
 		}
 	}
 
diff --git a/diffmatchpatch/diff_test.go b/diffmatchpatch/diff_test.go
index acb97e3..2c43864 100644
--- a/diffmatchpatch/diff_test.go
+++ b/diffmatchpatch/diff_test.go
@@ -314,10 +314,12 @@ func TestDiffLinesToChars(t *testing.T) {
 	dmp := New()
 
 	for i, tc := range []TestCase{
-		{"", "alpha\r\nbeta\r\n\r\n\r\n", "", "1,2,3,3", []string{"", "alpha\r\n", "beta\r\n", "\r\n"}},
-		{"a", "b", "1", "2", []string{"", "a", "b"}},
+		{"", "alpha\r\nbeta\r\n\r\n\r\n", "", "\x01\x02\x03\x03", []string{"", "alpha\r\n", "beta\r\n", "\r\n"}},
+		{"a", "b", "\x01", "\x02", []string{"", "a", "b"}},
 		// Omit final newline.
-		{"alpha\nbeta\nalpha", "", "1,2,3", "", []string{"", "alpha\n", "beta\n", "alpha"}},
+		{"alpha\nbeta\nalpha", "", "\x01\x02\x03", "", []string{"", "alpha\n", "beta\n", "alpha"}},
+		// Same lines in Text1 and Text2
+		{"abc\ndefg\n12345\n", "abc\ndef\n12345\n678", "\x01\x02\x03", "\x01\x04\x03\x05", []string{"", "abc\n", "defg\n", "12345\n", "def\n", "678"}},
 	} {
 		actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(tc.Text1, tc.Text2)
 		assert.Equal(t, tc.ExpectedChars1, actualChars1, fmt.Sprintf("Test case #%d, %#v", i, tc))
@@ -330,14 +332,14 @@ func TestDiffLinesToChars(t *testing.T) {
 	lineList := []string{
 		"", // Account for the initial empty element of the lines array.
 	}
-	var charList []string
+	var charList []index
 	for x := 1; x < n+1; x++ {
 		lineList = append(lineList, strconv.Itoa(x)+"\n")
-		charList = append(charList, strconv.Itoa(x))
+		charList = append(charList, index(x))
 	}
 	lines := strings.Join(lineList, "")
-	chars := strings.Join(charList[:], ",")
-	assert.Equal(t, n, len(strings.Split(chars, ",")))
+	chars := indexesToString(charList)
+	assert.Equal(t, n, len(charList))
 
 	actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(lines, "")
 	assert.Equal(t, chars, actualChars1)
@@ -358,8 +360,8 @@ func TestDiffCharsToLines(t *testing.T) {
 	for i, tc := range []TestCase{
 		{
 			Diffs: []Diff{
-				{DiffEqual, "1,2,1"},
-				{DiffInsert, "2,1,2"},
+				{DiffEqual, "\x01\x02\x01"},
+				{DiffInsert, "\x02\x01\x02"},
 			},
 			Lines: []string{"", "alpha\n", "beta\n"},
 
@@ -378,13 +380,13 @@ func TestDiffCharsToLines(t *testing.T) {
 	lineList := []string{
 		"", // Account for the initial empty element of the lines array.
 	}
-	charList := []string{}
+	charList := []index{}
 	for x := 1; x <= n; x++ {
 		lineList = append(lineList, strconv.Itoa(x)+"\n")
-		charList = append(charList, strconv.Itoa(x))
+		charList = append(charList, index(x))
 	}
 	assert.Equal(t, n, len(charList))
-	chars := strings.Join(charList[:], ",")
+	chars := indexesToString(charList)
 
 	actual := dmp.DiffCharsToLines([]Diff{Diff{DiffDelete, chars}}, lineList)
 	assert.Equal(t, []Diff{Diff{DiffDelete, strings.Join(lineList, "")}}, actual)
@@ -1031,6 +1033,17 @@ func TestDiffPrettyText(t *testing.T) {
 
 			Expected: "a\n\x1b[31m<B>b</B>\x1b[0m\x1b[32mc&d\x1b[0m",
 		},
+		{
+			Diffs: []Diff{
+				{Type: DiffEqual, Text: "a\n"},
+				{Type: DiffDelete, Text: "b\nc\n"},
+				{Type: DiffEqual, Text: "def"},
+				{Type: DiffInsert, Text: "\ng\nh"},
+				{Type: DiffEqual, Text: "\ni"},
+			},
+
+			Expected: "a\n\x1b[31mb\x1b[0m\n\x1b[31mc\x1b[0m\n\x1b[31m\x1b[0mdef\x1b[32m\x1b[0m\n\x1b[32mg\x1b[0m\n\x1b[32mh\x1b[0m\ni",
+		},
 	} {
 		actual := dmp.DiffPrettyText(tc.Diffs)
 		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
@@ -1466,6 +1479,38 @@ func TestMassiveRuneDiffConversion(t *testing.T) {
 	assert.NotEmpty(t, diffs)
 }
 
+func TestDiffPartialLineIndex(t *testing.T) {
+	dmp := New()
+	t1, t2, tt := dmp.DiffLinesToChars(
+		`line 1
+line 2
+line 3
+line 4
+line 5
+line 6
+line 7
+line 8
+line 9
+line 10 text1`,
+		`line 1
+line 2
+line 3
+line 4
+line 5
+line 6
+line 7
+line 8
+line 9
+line 10 text2`)
+	diffs := dmp.DiffMain(t1, t2, false)
+	diffs = dmp.DiffCharsToLines(diffs, tt)
+	assert.Equal(t, []Diff{
+		Diff{DiffEqual, "line 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\n"},
+		Diff{DiffDelete, "line 10 text1"},
+		Diff{DiffInsert, "line 10 text2"},
+	}, diffs)
+}
+
 func BenchmarkDiffMain(bench *testing.B) {
 	s1 := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
 	s2 := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"
diff --git a/diffmatchpatch/index.go b/diffmatchpatch/index.go
new file mode 100644
index 0000000..965a1c6
--- /dev/null
+++ b/diffmatchpatch/index.go
@@ -0,0 +1,32 @@
+package diffmatchpatch
+
+type index uint32
+
+const runeSkipStart = 0xd800
+const runeSkipEnd = 0xdfff + 1
+const runeMax = 0x110000 // next invalid code point
+
+func stringToIndex(text string) []index {
+	runes := []rune(text)
+	indexes := make([]index, len(runes))
+	for i, r := range runes {
+		if r < runeSkipEnd {
+			indexes[i] = index(r)
+		} else {
+			indexes[i] = index(r) - (runeSkipEnd - runeSkipStart)
+		}
+	}
+	return indexes
+}
+
+func indexesToString(indexes []index) string {
+	runes := make([]rune, len(indexes))
+	for i, index := range indexes {
+		if index < runeSkipStart {
+			runes[i] = rune(index)
+		} else {
+			runes[i] = rune(index + (runeSkipEnd - runeSkipStart))
+		}
+	}
+	return string(runes)
+}
diff --git a/diffmatchpatch/index_test.go b/diffmatchpatch/index_test.go
new file mode 100644
index 0000000..6f1d982
--- /dev/null
+++ b/diffmatchpatch/index_test.go
@@ -0,0 +1,16 @@
+package diffmatchpatch
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestIndexConversion(t *testing.T) {
+	n := runeMax - (runeSkipEnd - runeSkipStart)
+	indexes := make([]index, n)
+	for i := 0; i < n; i++ {
+		indexes[i] = index(i)
+	}
+	indexes2 := stringToIndex(indexesToString(indexes))
+	assert.EqualValues(t, indexes, indexes2)
+}
diff --git a/diffmatchpatch/patch_test.go b/diffmatchpatch/patch_test.go
index b019f88..c564f8c 100644
--- a/diffmatchpatch/patch_test.go
+++ b/diffmatchpatch/patch_test.go
@@ -337,3 +337,28 @@ func TestPatchApply(t *testing.T) {
 		assert.Equal(t, tc.ExpectedApplies, actualApplies, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
 	}
 }
+
+func TestPatchMakeOutOfRangePanic(t *testing.T) {
+	text1 := `
+  1111111111111 000000
+  ------------- ------
+  xxxxxxxxxxxxx ------
+  xxxxxxxxxxxxx ------
+  xxxxxxxxxxxxx xxxxxx
+  xxxxxxxxxxxxx ......
+  xxxxxxxxxxxxx 111111
+  xxxxxxxxxxxxx ??????
+  xxxxxxxxxxxxx 333333
+  xxxxxxxxxxxxx 555555
+  xxxxxxxxxx xxxxx
+  xxxxxxxxxx xxxxx
+  xxxxxxxxxx xxxxx
+  xxxxxxxxxx xxxxx
+`
+	text2 := `
+  2222222222222 000000
+  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
+	dmp := New()
+	patches := dmp.PatchMake(text1, text2)
+	assert.Equal(t, 6, len(patches), "TestPatchMakeOutOfRangePanic")
+}
diff --git a/diffmatchpatch/stringutil.go b/diffmatchpatch/stringutil.go
index 44c4359..573b6bf 100644
--- a/diffmatchpatch/stringutil.go
+++ b/diffmatchpatch/stringutil.go
@@ -9,11 +9,16 @@
 package diffmatchpatch
 
 import (
-	"strconv"
+	"fmt"
 	"strings"
 	"unicode/utf8"
 )
 
+const UNICODE_INVALID_RANGE_START = 0xD800
+const UNICODE_INVALID_RANGE_END = 0xDFFF
+const UNICODE_INVALID_RANGE_DELTA = UNICODE_INVALID_RANGE_END - UNICODE_INVALID_RANGE_START + 1
+const UNICODE_RANGE_MAX = 0x10FFFF
+
 // unescaper unescapes selected chars for compatibility with JavaScript's encodeURI.
 // In speed critical applications this could be dropped since the receiving application will certainly decode these fine. Note that this function is case-sensitive.  Thus "%3F" would not be unescaped.  But this is ok because it is only called with the output of HttpUtility.UrlEncode which returns lowercase hex. Example: "%3f" -> "?", "%24" -> "$", etc.
 var unescaper = strings.NewReplacer(
@@ -88,19 +93,98 @@ func runesIndex(r1, r2 []rune) int {
 	return -1
 }
 
-func intArrayToString(ns []uint32) string {
+func intArrayToString(ns []index) string {
 	if len(ns) == 0 {
 		return ""
 	}
 
-	indexSeparator := IndexSeparator[0]
-
-	// Appr. 3 chars per num plus the comma.
-	b := []byte{}
+	b := []rune{}
 	for _, n := range ns {
-		b = strconv.AppendInt(b, int64(n), 10)
-		b = append(b, indexSeparator)
+		b = append(b, intToRune(uint32(n)))
 	}
-	b = b[:len(b)-1]
 	return string(b)
 }
+
+// These constants define the number of bits representable
+// in 1,2,3,4 byte utf8 sequences, respectively.
+const ONE_BYTE_BITS = 7
+const TWO_BYTE_BITS = 11
+const THREE_BYTE_BITS = 16
+const FOUR_BYTE_BITS = 21
+
+// Helper for getting a sequence of bits from an integer.
+func getBits(i uint32, cnt byte, from byte) byte {
+	return byte((i >> from) & ((1 << cnt) - 1))
+}
+
+// Converts an integer in the range 0~1112060 into a rune.
+// Based on the ranges table in https://en.wikipedia.org/wiki/UTF-8
+func intToRune(i uint32) rune {
+	if i < (1 << ONE_BYTE_BITS) {
+		return rune(i)
+	}
+
+	if i < (1 << TWO_BYTE_BITS) {
+		r, size := utf8.DecodeRune([]byte{0b11000000 | getBits(i, 5, 6), 0b10000000 | getBits(i, 6, 0)})
+		if size != 2 || r == utf8.RuneError {
+			panic(fmt.Sprintf("Error encoding an int %d with size 2, got rune %v and size %d", size, r, i))
+		}
+		return r
+	}
+
+	// Last -3 here needed because for some reason 3rd to last codepoint 65533 in this range
+	// was returning utf8.RuneError during encoding.
+	if i < ((1 << THREE_BYTE_BITS) - UNICODE_INVALID_RANGE_DELTA - 3) {
+		if i >= UNICODE_INVALID_RANGE_START {
+			i += UNICODE_INVALID_RANGE_DELTA
+		}
+
+		r, size := utf8.DecodeRune([]byte{0b11100000 | getBits(i, 4, 12), 0b10000000 | getBits(i, 6, 6), 0b10000000 | getBits(i, 6, 0)})
+		if size != 3 || r == utf8.RuneError {
+			panic(fmt.Sprintf("Error encoding an int %d with size 3, got rune %v and size %d", size, r, i))
+		}
+		return r
+	}
+
+	if i < (1<<FOUR_BYTE_BITS - UNICODE_INVALID_RANGE_DELTA - 3) {
+		i += UNICODE_INVALID_RANGE_DELTA + 3
+		r, size := utf8.DecodeRune([]byte{0b11110000 | getBits(i, 3, 18), 0b10000000 | getBits(i, 6, 12), 0b10000000 | getBits(i, 6, 6), 0b10000000 | getBits(i, 6, 0)})
+		if size != 4 || r == utf8.RuneError {
+			panic(fmt.Sprintf("Error encoding an int %d with size 4, got rune %v and size %d", size, r, i))
+		}
+		return r
+	}
+	panic(fmt.Sprintf("The integer %d is too large for runeToInt()", i))
+}
+
+// Converts a rune generated by intToRune back to an integer
+func runeToInt(r rune) uint32 {
+	i := uint32(r)
+	if i < (1 << ONE_BYTE_BITS) {
+		return i
+	}
+
+	bytes := []byte{0, 0, 0, 0}
+
+	size := utf8.EncodeRune(bytes, r)
+
+	if size == 2 {
+		return uint32(bytes[0]&0b11111)<<6 | uint32(bytes[1]&0b111111)
+	}
+
+	if size == 3 {
+		result := uint32(bytes[0]&0b1111)<<12 | uint32(bytes[1]&0b111111)<<6 | uint32(bytes[2]&0b111111)
+		if result >= UNICODE_INVALID_RANGE_END {
+			return result - UNICODE_INVALID_RANGE_DELTA
+		}
+
+		return result
+	}
+
+	if size == 4 {
+		result := uint32(bytes[0]&0b111)<<18 | uint32(bytes[1]&0b111111)<<12 | uint32(bytes[2]&0b111111)<<6 | uint32(bytes[3]&0b111111)
+		return result - UNICODE_INVALID_RANGE_DELTA - 3
+	}
+
+	panic(fmt.Sprintf("Unexpected state decoding rune=%v size=%d", r, size))
+}
diff --git a/diffmatchpatch/stringutil_test.go b/diffmatchpatch/stringutil_test.go
index ab2bc10..73ab6ca 100644
--- a/diffmatchpatch/stringutil_test.go
+++ b/diffmatchpatch/stringutil_test.go
@@ -114,3 +114,21 @@ func TestLastIndexOf(t *testing.T) {
 		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
 	}
 }
+
+// Exhaustive check for all ints from 0 to 1112060 for correctness of implementation
+// of `intToRune() -> runeToInt()`.
+// This test is slow and runs longer than 5 seconds but it does provide a safety
+// guarantee that these 2 functions are correct for the ranges we support.
+func TestRuneToInt(t *testing.T) {
+
+	for i := uint32(0); i <= UNICODE_RANGE_MAX-UNICODE_INVALID_RANGE_DELTA-3; i += 1 {
+		r := intToRune(i)
+		ic := runeToInt(r)
+
+		assert.Equal(t, i, ic, fmt.Sprintf("intToRune(%d)=%d and runeToInt(%d)=%d", i, r, r, ic))
+	}
+
+	assert.Panics(t, func() {
+		intToRune(UNICODE_RANGE_MAX - UNICODE_INVALID_RANGE_DELTA - 2)
+	})
+}
diff --git a/go.mod b/go.mod
index d46c77d..c7886ce 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ require (
 	github.com/kr/pretty v0.1.0 // indirect
 	github.com/stretchr/testify v1.4.0
 	gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
-	gopkg.in/yaml.v2 v2.2.4 // indirect
+	gopkg.in/yaml.v2 v2.4.0 // indirect
 )
 
-go 1.12
+go 1.13
diff --git a/go.sum b/go.sum
index 4b80e08..8dd9f36 100644
--- a/go.sum
+++ b/go.sum
@@ -19,3 +19,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
-- 
2.47.2

From e0cfdb7b89fff311a396a560f85cb07460efe288 Mon Sep 17 00:00:00 2001
From: Andrea Pappacoda <ta...@debian.org>
Date: Tue, 22 Jul 2025 17:30:37 +0200
Subject: [PATCH 2/5] d/patches: drop upstreamed patches

---
 ...d-diff-output-with-CRLF-line-endings.patch | 339 ------------------
 debian/patches/series                         |   1 -
 2 files changed, 340 deletions(-)
 delete mode 100644 debian/patches/0001-Fix-invalid-diff-output-with-CRLF-line-endings.patch
 delete mode 100644 debian/patches/series

diff --git a/debian/patches/0001-Fix-invalid-diff-output-with-CRLF-line-endings.patch b/debian/patches/0001-Fix-invalid-diff-output-with-CRLF-line-endings.patch
deleted file mode 100644
index 0b72ba3..0000000
--- a/debian/patches/0001-Fix-invalid-diff-output-with-CRLF-line-endings.patch
+++ /dev/null
@@ -1,339 +0,0 @@
-From: Shoshin Nikita <shoshin_nik...@fastmail.com>
-Date: Wed, 7 Apr 2021 15:26:09 +0300
-Subject: Fix invalid diff output with CRLF line endings
-
-Origin: upstream, https://github.com/sergi/go-diff/pull/120
----
- diffmatchpatch/diff.go       | 127 ++++++++++++++++++++++++-------------------
- diffmatchpatch/diff_test.go  |  67 ++++++++++++++++-------
- diffmatchpatch/stringutil.go |  18 ------
- 3 files changed, 118 insertions(+), 94 deletions(-)
-
-diff --git a/diffmatchpatch/diff.go b/diffmatchpatch/diff.go
-index 2a9f2dc..b975bb8 100644
---- a/diffmatchpatch/diff.go
-+++ b/diffmatchpatch/diff.go
-@@ -34,8 +34,6 @@ 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 = ","
- )
- 
- // Diff represents one diff operation
-@@ -195,7 +193,7 @@ func (dmp *DiffMatchPatch) diffCompute(text1, text2 []rune, checklines bool, dea
- // diffLineMode does a quick line-level diff on both []runes, then rediff the parts for greater accuracy. This speedup can produce non-minimal diffs.
- func (dmp *DiffMatchPatch) diffLineMode(text1, text2 []rune, deadline time.Time) []Diff {
- 	// Scan the text on a line-by-line basis first.
--	text1, text2, linearray := dmp.DiffLinesToRunes(string(text1), string(text2))
-+	text1, text2, linearray := dmp.diffLinesToRunes(text1, text2)
- 
- 	diffs := dmp.diffMainRunes(text1, text2, false, deadline)
- 
-@@ -392,28 +390,88 @@ func (dmp *DiffMatchPatch) diffBisectSplit(runes1, runes2 []rune, x, y int,
- // DiffLinesToChars splits two texts into a list of strings, and educes the texts to a string of hashes where each Unicode character represents one line.
- // It's slightly faster to call DiffLinesToRunes first, followed by DiffMainRunes.
- func (dmp *DiffMatchPatch) DiffLinesToChars(text1, text2 string) (string, string, []string) {
--	chars1, chars2, lineArray := dmp.diffLinesToStrings(text1, text2)
--	return chars1, chars2, lineArray
-+	chars1, chars2, lineArray := dmp.DiffLinesToRunes(text1, text2)
-+	return string(chars1), string(chars2), lineArray
- }
- 
--// DiffLinesToRunes splits two texts into a list of runes.
-+// DiffLinesToRunes splits two texts into a list of runes. Each rune represents one line.
- func (dmp *DiffMatchPatch) DiffLinesToRunes(text1, text2 string) ([]rune, []rune, []string) {
--	chars1, chars2, lineArray := dmp.diffLinesToStrings(text1, text2)
--	return []rune(chars1), []rune(chars2), lineArray
-+	// '\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 := map[string]int{} // e.g. lineHash['Hello\n'] == 4
-+
-+	chars1 := dmp.diffLinesToRunesMunge(text1, &lineArray, lineHash)
-+	chars2 := dmp.diffLinesToRunesMunge(text2, &lineArray, lineHash)
-+
-+	return chars1, chars2, lineArray
-+}
-+
-+func (dmp *DiffMatchPatch) diffLinesToRunes(text1, text2 []rune) ([]rune, []rune, []string) {
-+	return dmp.DiffLinesToRunes(string(text1), string(text2))
-+}
-+
-+// diffLinesToRunesMunge splits a text into an array of strings, and reduces the texts to a []rune where each Unicode character represents one line.
-+// We use strings instead of []runes as input mainly because you can't use []rune as a map key.
-+func (dmp *DiffMatchPatch) diffLinesToRunesMunge(text string, lineArray *[]string, lineHash map[string]int) []rune {
-+	// 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.
-+	lineStart := 0
-+	lineEnd := -1
-+	runes := []rune{}
-+
-+	for lineEnd < len(text)-1 {
-+		lineEnd = indexOf(text, "\n", lineStart)
-+
-+		if lineEnd == -1 {
-+			lineEnd = len(text) - 1
-+		}
-+
-+		line := text[lineStart : lineEnd+1]
-+		lineStart = lineEnd + 1
-+		lineValue, ok := lineHash[line]
-+		if !ok {
-+			checkLineArray(lineArray)
-+
-+			*lineArray = append(*lineArray, line)
-+			lineValue = len(*lineArray) - 1
-+			lineHash[line] = lineValue
-+		}
-+		runes = append(runes, rune(lineValue))
-+	}
-+
-+	return runes
-+}
-+
-+// checkLineArray checks the size of the slice and ensures that the index of the next element
-+// will be the valid rune.
-+func checkLineArray(a *[]string) {
-+	// Runes in this range are invalid, utf8.ValidRune() returns false.
-+	const (
-+		surrogateMin = 0xD800
-+		surrogateMax = 0xDFFF
-+	)
-+
-+	// Check the index of the next element
-+	switch len(*a) {
-+	case surrogateMin:
-+		// Skip invalid runes.
-+		padding := [surrogateMax - surrogateMin + 1]string{}
-+		*a = append(*a, padding[:]...)
-+
-+	case utf8.MaxRune + 1:
-+		// We can't do anything about it.
-+		panic(fmt.Sprintf("rune can't be more than %d", utf8.MaxRune))
-+	}
- }
- 
- // DiffCharsToLines rehydrates the text in a diff from a string of line hashes to real lines of text.
- func (dmp *DiffMatchPatch) DiffCharsToLines(diffs []Diff, lineArray []string) []Diff {
- 	hydrated := make([]Diff, 0, len(diffs))
- 	for _, aDiff := range diffs {
--		chars := strings.Split(aDiff.Text, IndexSeparator)
-+		chars := aDiff.Text
- 		text := make([]string, len(chars))
- 
- 		for i, r := range chars {
--			i1, err := strconv.Atoi(r)
--			if err == nil {
--				text[i] = lineArray[i1]
--			}
-+			text[i] = lineArray[r]
- 		}
- 
- 		aDiff.Text = strings.Join(text, "")
-@@ -1307,46 +1365,3 @@ func (dmp *DiffMatchPatch) DiffFromDelta(text1 string, delta string) (diffs []Di
- 
- 	return diffs, nil
- }
--
--// diffLinesToStrings splits two texts into a list of strings. Each string represents one line.
--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'
--
--	//Each string has the index of lineArray which it points to
--	strIndexArray1 := dmp.diffLinesToStringsMunge(text1, &lineArray)
--	strIndexArray2 := dmp.diffLinesToStringsMunge(text2, &lineArray)
--
--	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 {
--	// 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{}
--
--	for lineEnd < len(text)-1 {
--		lineEnd = indexOf(text, "\n", lineStart)
--
--		if lineEnd == -1 {
--			lineEnd = len(text) - 1
--		}
--
--		line := text[lineStart : lineEnd+1]
--		lineStart = lineEnd + 1
--		lineValue, ok := lineHash[line]
--
--		if ok {
--			strs = append(strs, uint32(lineValue))
--		} else {
--			*lineArray = append(*lineArray, line)
--			lineHash[line] = len(*lineArray) - 1
--			strs = append(strs, uint32(len(*lineArray)-1))
--		}
--	}
--
--	return strs
--}
-diff --git a/diffmatchpatch/diff_test.go b/diffmatchpatch/diff_test.go
-index acb97e3..be84a14 100644
---- a/diffmatchpatch/diff_test.go
-+++ b/diffmatchpatch/diff_test.go
-@@ -314,10 +314,10 @@ func TestDiffLinesToChars(t *testing.T) {
- 	dmp := New()
- 
- 	for i, tc := range []TestCase{
--		{"", "alpha\r\nbeta\r\n\r\n\r\n", "", "1,2,3,3", []string{"", "alpha\r\n", "beta\r\n", "\r\n"}},
--		{"a", "b", "1", "2", []string{"", "a", "b"}},
-+		{"", "alpha\r\nbeta\r\n\r\n\r\n", "", "\u0001\u0002\u0003\u0003", []string{"", "alpha\r\n", "beta\r\n", "\r\n"}},
-+		{"a", "b", "\u0001", "\u0002", []string{"", "a", "b"}},
- 		// Omit final newline.
--		{"alpha\nbeta\nalpha", "", "1,2,3", "", []string{"", "alpha\n", "beta\n", "alpha"}},
-+		{"alpha\nbeta\nalpha", "", "\u0001\u0002\u0003", "", []string{"", "alpha\n", "beta\n", "alpha"}},
- 	} {
- 		actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(tc.Text1, tc.Text2)
- 		assert.Equal(t, tc.ExpectedChars1, actualChars1, fmt.Sprintf("Test case #%d, %#v", i, tc))
-@@ -330,14 +330,14 @@ func TestDiffLinesToChars(t *testing.T) {
- 	lineList := []string{
- 		"", // Account for the initial empty element of the lines array.
- 	}
--	var charList []string
-+	var charList []rune
- 	for x := 1; x < n+1; x++ {
- 		lineList = append(lineList, strconv.Itoa(x)+"\n")
--		charList = append(charList, strconv.Itoa(x))
-+		charList = append(charList, rune(x))
- 	}
- 	lines := strings.Join(lineList, "")
--	chars := strings.Join(charList[:], ",")
--	assert.Equal(t, n, len(strings.Split(chars, ",")))
-+	chars := string(charList)
-+	assert.Equal(t, n, utf8.RuneCountInString(chars))
- 
- 	actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(lines, "")
- 	assert.Equal(t, chars, actualChars1)
-@@ -358,8 +358,8 @@ func TestDiffCharsToLines(t *testing.T) {
- 	for i, tc := range []TestCase{
- 		{
- 			Diffs: []Diff{
--				{DiffEqual, "1,2,1"},
--				{DiffInsert, "2,1,2"},
-+				{DiffEqual, "\u0001\u0002\u0001"},
-+				{DiffInsert, "\u0002\u0001\u0002"},
- 			},
- 			Lines: []string{"", "alpha\n", "beta\n"},
- 
-@@ -378,15 +378,14 @@ func TestDiffCharsToLines(t *testing.T) {
- 	lineList := []string{
- 		"", // Account for the initial empty element of the lines array.
- 	}
--	charList := []string{}
-+	charList := []rune{}
- 	for x := 1; x <= n; x++ {
- 		lineList = append(lineList, strconv.Itoa(x)+"\n")
--		charList = append(charList, strconv.Itoa(x))
-+		charList = append(charList, rune(x))
- 	}
- 	assert.Equal(t, n, len(charList))
--	chars := strings.Join(charList[:], ",")
- 
--	actual := dmp.DiffCharsToLines([]Diff{Diff{DiffDelete, chars}}, lineList)
-+	actual := dmp.DiffCharsToLines([]Diff{Diff{DiffDelete, string(charList)}}, lineList)
- 	assert.Equal(t, []Diff{Diff{DiffDelete, strings.Join(lineList, "")}}, actual)
- }
- 
-@@ -1419,16 +1418,12 @@ func TestDiffMainWithTimeout(t *testing.T) {
- }
- 
- func TestDiffMainWithCheckLines(t *testing.T) {
-+	// Test cases must be at least 100 chars long to pass the cutoff.
- 	type TestCase struct {
- 		Text1 string
- 		Text2 string
- 	}
--
--	dmp := New()
--	dmp.DiffTimeout = 0
--
--	// Test cases must be at least 100 chars long to pass the cutoff.
--	for i, tc := range []TestCase{
-+	tests := []TestCase{
- 		{
- 			"1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n",
- 			"abcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\n",
-@@ -1441,7 +1436,39 @@ func TestDiffMainWithCheckLines(t *testing.T) {
- 			"1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n",
- 			"abcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n",
- 		},
--	} {
-+	}
-+	// Add test case for the issue #115
-+	func() {
-+		const before = `package main
-+
-+import (
-+	"fmt"
-+)
-+
-+/*
-+func upload(c echo.Context) error {
-+	if err := r.ParseForm(); err != nil {
-+		fmt.Fprintf(w, "ParseForm() err: %v", err)
-+		return
-+	}
-+	fmt.Fprintf(w, "POST request successful")
-+	path_ver := r.FormValue("path_ver")
-+	ukclin_ver := r.FormValue("ukclin_ver")
-+
-+	fmt.Fprintf(w, "Name = %s\n", path_ver)
-+	fmt.Fprintf(w, "Address = %s\n", ukclin_ver)
-+}
-+*/
-+`
-+		after := strings.ReplaceAll(before, "\n", "\r\n")
-+
-+		tests = append(tests, TestCase{Text1: before, Text2: after})
-+	}()
-+
-+	dmp := New()
-+	dmp.DiffTimeout = 0
-+
-+	for i, tc := range tests {
- 		resultWithoutCheckLines := dmp.DiffMain(tc.Text1, tc.Text2, false)
- 		resultWithCheckLines := dmp.DiffMain(tc.Text1, tc.Text2, true)
- 
-diff --git a/diffmatchpatch/stringutil.go b/diffmatchpatch/stringutil.go
-index 44c4359..265f29c 100644
---- a/diffmatchpatch/stringutil.go
-+++ b/diffmatchpatch/stringutil.go
-@@ -9,7 +9,6 @@
- package diffmatchpatch
- 
- import (
--	"strconv"
- 	"strings"
- 	"unicode/utf8"
- )
-@@ -87,20 +86,3 @@ func runesIndex(r1, r2 []rune) int {
- 	}
- 	return -1
- }
--
--func intArrayToString(ns []uint32) string {
--	if len(ns) == 0 {
--		return ""
--	}
--
--	indexSeparator := IndexSeparator[0]
--
--	// Appr. 3 chars per num plus the comma.
--	b := []byte{}
--	for _, n := range ns {
--		b = strconv.AppendInt(b, int64(n), 10)
--		b = append(b, indexSeparator)
--	}
--	b = b[:len(b)-1]
--	return string(b)
--}
diff --git a/debian/patches/series b/debian/patches/series
deleted file mode 100644
index f030977..0000000
--- a/debian/patches/series
+++ /dev/null
@@ -1 +0,0 @@
-0001-Fix-invalid-diff-output-with-CRLF-line-endings.patch
-- 
2.47.2

From 387d23a5c355d4281ffa202d451d052feaf6cd82 Mon Sep 17 00:00:00 2001
From: Andrea Pappacoda <ta...@debian.org>
Date: Tue, 22 Jul 2025 17:33:30 +0200
Subject: [PATCH 3/5] d/control: update standards version

Gbp-Dch: Ignore
---
 debian/control | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/debian/control b/debian/control
index 83d7bc7..936fa49 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,7 @@ Build-Depends: debhelper-compat (= 13),
                dh-golang,
                golang-any,
                golang-github-stretchr-testify-dev,
-Standards-Version: 4.6.1
+Standards-Version: 4.7.2
 Vcs-Browser: https://salsa.debian.org/go-team/packages/golang-github-sergi-go-diff
 Vcs-Git: https://salsa.debian.org/go-team/packages/golang-github-sergi-go-diff.git
 Homepage: https://github.com/sergi/go-diff
-- 
2.47.2

From ceaf490d919d0efa91eaad9d8b499d903151c81f Mon Sep 17 00:00:00 2001
From: Andrea Pappacoda <ta...@debian.org>
Date: Tue, 22 Jul 2025 17:36:07 +0200
Subject: [PATCH 4/5] d/control: use dh-sequence-golang

---
 debian/control | 2 +-
 debian/rules   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/debian/control b/debian/control
index 936fa49..3918498 100644
--- a/debian/control
+++ b/debian/control
@@ -6,7 +6,7 @@ Section: golang
 Testsuite: autopkgtest-pkg-go
 Priority: optional
 Build-Depends: debhelper-compat (= 13),
-               dh-golang,
+               dh-sequence-golang,
                golang-any,
                golang-github-stretchr-testify-dev,
 Standards-Version: 4.7.2
diff --git a/debian/rules b/debian/rules
index 8cce5e0..623d0d9 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,4 +1,4 @@
 #!/usr/bin/make -f
 
 %:
-	dh $@ --buildsystem=golang --with=golang
+	dh $@ --buildsystem=golang
-- 
2.47.2

From 3ee8f9a37b2f2ff97ca5ab29109bc4a0a93d3e7c Mon Sep 17 00:00:00 2001
From: Andrea Pappacoda <ta...@debian.org>
Date: Tue, 22 Jul 2025 17:41:53 +0200
Subject: [PATCH 5/5] Update changelog for 1.4.0-1 release

---
 debian/changelog | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 6bd9220..95b3ee8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+golang-github-sergi-go-diff (1.4.0-1) experimental; urgency=low
+
+  * Team upload.
+  * New upstream version 1.4.0
+    - Closes: #1109727
+  * d/control: use dh-sequence-golang
+  * d/patches: drop upstreamed patches
+
+ -- Andrea Pappacoda <ta...@debian.org>  Tue, 22 Jul 2025 17:41:18 +0200
+
 golang-github-sergi-go-diff (1.2.0-2) unstable; urgency=medium
 
   * Team upload.
-- 
2.47.2

Reply via email to