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

Commit

Permalink
Merge pull request #1065 from vmarkovtsev/fix-unicode
Browse files Browse the repository at this point in the history
Remove Unicode normalization in difftree
  • Loading branch information
mcuadros committed Feb 14, 2019
2 parents 4d8bd13 + c40fcef commit db6c41c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 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)
}
35 changes: 31 additions & 4 deletions worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,14 @@ func (s *WorktreeSuite) TestFilenameNormalization(c *C) {

w, err := server.Worktree()
c.Assert(err, IsNil)
util.WriteFile(w.Filesystem, filename, []byte("foo"), 0755)
_, err = w.Add(filename)

writeFile := func(path string) {
err := util.WriteFile(w.Filesystem, path, []byte("foo"), 0755)
c.Assert(err, IsNil)
}

writeFile(filename)
origHash, err := w.Add(filename)
c.Assert(err, IsNil)
_, err = w.Commit("foo", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
Expand All @@ -387,11 +393,32 @@ func (s *WorktreeSuite) TestFilenameNormalization(c *C) {
c.Assert(err, IsNil)

modFilename := norm.Form(norm.NFKD).String(filename)
util.WriteFile(w.Filesystem, modFilename, []byte("foo"), 0755)
writeFile(modFilename)

_, err = w.Add(filename)
c.Assert(err, IsNil)
modHash, err := w.Add(modFilename)
c.Assert(err, IsNil)
// At this point we've got two files with the same content.
// Hence their hashes must be the same.
c.Assert(origHash == modHash, Equals, true)

status, err = w.Status()
c.Assert(err, IsNil)
// However, their names are different and the work tree is still dirty.
c.Assert(status.IsClean(), Equals, false)

// Revert back the deletion of the first file.
writeFile(filename)
_, err = w.Add(filename)
c.Assert(err, IsNil)
_, err = w.Add(modFilename)

status, err = w.Status()
c.Assert(err, IsNil)
// Still dirty - the second file is added.
c.Assert(status.IsClean(), Equals, false)

_, err = w.Remove(modFilename)
c.Assert(err, IsNil)

status, err = w.Status()
Expand Down

0 comments on commit db6c41c

Please sign in to comment.