Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Remove Unicode normalization in difftree
Browse files Browse the repository at this point in the history
Fixes #1057

Signed-off-by: Vadim Markovtsev <vadim@sourced.tech>
  • Loading branch information
vmarkovtsev committed Feb 11, 2019
1 parent cd64b4d commit 39caac2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
23 changes: 22 additions & 1 deletion utils/merkletrie/difftree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,29 @@ func (s *DiffTreeSuite) TestIssue275(c *C) {
})
}

func (s *DiffTreeSuite) TestIssue1057(c *C) {
p1 := "TestAppWithUnicodéPath"
p2 := "TestAppWithUnicodéPath"
c.Assert(p1 == p2, Equals, false)
do(c, []diffTreeTest{
{
fmt.Sprintf("(%s(x.go<1>))", p1),
fmt.Sprintf("(%s(x.go<1>) %s(x.go<1>))", p1, p2),
fmt.Sprintf("+%s/x.go", p2),
},
})
// swap p1 with p2
do(c, []diffTreeTest{
{
fmt.Sprintf("(%s(x.go<1>))", p2),
fmt.Sprintf("(%s(x.go<1>) %s(x.go<1>))", p1, p2),
fmt.Sprintf("+%s/x.go", p1),
},
})
}

func (s *DiffTreeSuite) TestCancel(c *C) {
t := diffTreeTest{"()", "(a<> b<1> c() d<> e<2> f())", "+a +b +d +e"}
t := diffTreeTest{"()", "(a<> b<1> c() d<> e<2> f())", "+a +b +d +e"}
comment := Commentf("\n%s", "test cancel:")

a, err := fsnoder.New(t.from)
Expand Down
10 changes: 3 additions & 7 deletions utils/merkletrie/noder/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package noder
import (
"bytes"
"strings"

"golang.org/x/text/unicode/norm"
)

// Path values represent a noder and its ancestors. The root goes first
Expand Down Expand Up @@ -80,11 +78,9 @@ func (p Path) Compare(other Path) int {
case i == len(p):
return -1
default:
form := norm.Form(norm.NFC)
this := form.String(p[i].Name())
that := form.String(other[i].Name())

cmp := strings.Compare(this, that)
// We do *not* normalize Unicode here. CGit doesn't.
// https://github.com/src-d/go-git/issues/1057
cmp := strings.Compare(p[i].Name(), other[i].Name())
if cmp != 0 {
return cmp
}
Expand Down
8 changes: 6 additions & 2 deletions utils/merkletrie/noder/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ func (s *PathSuite) TestCompareMixedDepths(c *C) {
func (s *PathSuite) TestCompareNormalization(c *C) {
p1 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKC).String("페")}})
p2 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKD).String("페")}})
c.Assert(p1.Compare(p2), Equals, 0)
c.Assert(p2.Compare(p1), Equals, 0)
c.Assert(p1.Compare(p2), Equals, 1)
c.Assert(p2.Compare(p1), Equals, -1)
p1 = Path([]Noder{&noderMock{name: "TestAppWithUnicodéPath"}})
p2 = Path([]Noder{&noderMock{name: "TestAppWithUnicodéPath"}})
c.Assert(p1.Compare(p2), Equals, -1)
c.Assert(p2.Compare(p1), Equals, 1)
}

0 comments on commit 39caac2

Please sign in to comment.