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

Commit db6c41c

Browse files
authored
Merge pull request #1065 from vmarkovtsev/fix-unicode
Remove Unicode normalization in difftree
2 parents 4d8bd13 + c40fcef commit db6c41c

File tree

4 files changed

+62
-14
lines changed

4 files changed

+62
-14
lines changed

utils/merkletrie/difftree_test.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,29 @@ func (s *DiffTreeSuite) TestIssue275(c *C) {
475475
})
476476
}
477477

478+
func (s *DiffTreeSuite) TestIssue1057(c *C) {
479+
p1 := "TestAppWithUnicodéPath"
480+
p2 := "TestAppWithUnicodéPath"
481+
c.Assert(p1 == p2, Equals, false)
482+
do(c, []diffTreeTest{
483+
{
484+
fmt.Sprintf("(%s(x.go<1>))", p1),
485+
fmt.Sprintf("(%s(x.go<1>) %s(x.go<1>))", p1, p2),
486+
fmt.Sprintf("+%s/x.go", p2),
487+
},
488+
})
489+
// swap p1 with p2
490+
do(c, []diffTreeTest{
491+
{
492+
fmt.Sprintf("(%s(x.go<1>))", p2),
493+
fmt.Sprintf("(%s(x.go<1>) %s(x.go<1>))", p1, p2),
494+
fmt.Sprintf("+%s/x.go", p1),
495+
},
496+
})
497+
}
498+
478499
func (s *DiffTreeSuite) TestCancel(c *C) {
479-
t := diffTreeTest{"()", "(a<> b<1> c() d<> e<2> f())", "+a +b +d +e"}
500+
t := diffTreeTest{"()", "(a<> b<1> c() d<> e<2> f())", "+a +b +d +e"}
480501
comment := Commentf("\n%s", "test cancel:")
481502

482503
a, err := fsnoder.New(t.from)

utils/merkletrie/noder/path.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package noder
33
import (
44
"bytes"
55
"strings"
6-
7-
"golang.org/x/text/unicode/norm"
86
)
97

108
// Path values represent a noder and its ancestors. The root goes first
@@ -80,11 +78,9 @@ func (p Path) Compare(other Path) int {
8078
case i == len(p):
8179
return -1
8280
default:
83-
form := norm.Form(norm.NFC)
84-
this := form.String(p[i].Name())
85-
that := form.String(other[i].Name())
86-
87-
cmp := strings.Compare(this, that)
81+
// We do *not* normalize Unicode here. CGit doesn't.
82+
// https://github.com/src-d/go-git/issues/1057
83+
cmp := strings.Compare(p[i].Name(), other[i].Name())
8884
if cmp != 0 {
8985
return cmp
9086
}

utils/merkletrie/noder/path_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ func (s *PathSuite) TestCompareMixedDepths(c *C) {
156156
func (s *PathSuite) TestCompareNormalization(c *C) {
157157
p1 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKC).String("페")}})
158158
p2 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKD).String("페")}})
159-
c.Assert(p1.Compare(p2), Equals, 0)
160-
c.Assert(p2.Compare(p1), Equals, 0)
159+
c.Assert(p1.Compare(p2), Equals, 1)
160+
c.Assert(p2.Compare(p1), Equals, -1)
161+
p1 = Path([]Noder{&noderMock{name: "TestAppWithUnicodéPath"}})
162+
p2 = Path([]Noder{&noderMock{name: "TestAppWithUnicodéPath"}})
163+
c.Assert(p1.Compare(p2), Equals, -1)
164+
c.Assert(p2.Compare(p1), Equals, 1)
161165
}

worktree_test.go

+31-4
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,14 @@ func (s *WorktreeSuite) TestFilenameNormalization(c *C) {
365365

366366
w, err := server.Worktree()
367367
c.Assert(err, IsNil)
368-
util.WriteFile(w.Filesystem, filename, []byte("foo"), 0755)
369-
_, err = w.Add(filename)
368+
369+
writeFile := func(path string) {
370+
err := util.WriteFile(w.Filesystem, path, []byte("foo"), 0755)
371+
c.Assert(err, IsNil)
372+
}
373+
374+
writeFile(filename)
375+
origHash, err := w.Add(filename)
370376
c.Assert(err, IsNil)
371377
_, err = w.Commit("foo", &CommitOptions{Author: defaultSignature()})
372378
c.Assert(err, IsNil)
@@ -387,11 +393,32 @@ func (s *WorktreeSuite) TestFilenameNormalization(c *C) {
387393
c.Assert(err, IsNil)
388394

389395
modFilename := norm.Form(norm.NFKD).String(filename)
390-
util.WriteFile(w.Filesystem, modFilename, []byte("foo"), 0755)
396+
writeFile(modFilename)
397+
398+
_, err = w.Add(filename)
399+
c.Assert(err, IsNil)
400+
modHash, err := w.Add(modFilename)
401+
c.Assert(err, IsNil)
402+
// At this point we've got two files with the same content.
403+
// Hence their hashes must be the same.
404+
c.Assert(origHash == modHash, Equals, true)
391405

406+
status, err = w.Status()
407+
c.Assert(err, IsNil)
408+
// However, their names are different and the work tree is still dirty.
409+
c.Assert(status.IsClean(), Equals, false)
410+
411+
// Revert back the deletion of the first file.
412+
writeFile(filename)
392413
_, err = w.Add(filename)
393414
c.Assert(err, IsNil)
394-
_, err = w.Add(modFilename)
415+
416+
status, err = w.Status()
417+
c.Assert(err, IsNil)
418+
// Still dirty - the second file is added.
419+
c.Assert(status.IsClean(), Equals, false)
420+
421+
_, err = w.Remove(modFilename)
395422
c.Assert(err, IsNil)
396423

397424
status, err = w.Status()

0 commit comments

Comments
 (0)