change ChildrenList to contain pointers
commit 4d87fa095dee5d08c861f58322c2de88875dddb9 · parent 3cadbec721
· browse this tree
Calvin Behling, 2022-11-18 20:19:15 UTC
diff --git a/index.go b/index.go index 25c554c..6d3463d 100644 --- a/index.go +++ b/index.go @@ -32,10 +32,11 @@ func (dirent *DirEnt) fill(pathSegs []string, hunk Hunk) { next.fill(pathSegs[1:], hunk) } else { l := len(dirent.ChildrenList) - dirent.ChildrenList = append(dirent.ChildrenList, DirEnt{ + child := DirEnt{ Name: pathSegs[0], - }) - dirent.Children[pathSegs[0]] = &dirent.ChildrenList[l] + } + dirent.ChildrenList = append(dirent.ChildrenList, &child) + dirent.Children[pathSegs[0]] = &child dirent.ChildrenList[l].fill(pathSegs[1:], hunk) } } diff --git a/index_test.go b/index_test.go index e5c9c35..787b591 100644 --- a/index_test.go +++ b/index_test.go @@ -63,7 +63,7 @@ func TestIndexingTree(t *testing.T) { assertHunkReachable(t, doc, hunk) }) } - assertChildren(t, *doc.DirEnt) + assertChildren(t, doc.DirEnt) } func assertHunkReachable(t *testing.T, doc *Document, hunk DocHunk) { @@ -78,7 +78,7 @@ func assertHunkReachable(t *testing.T, doc *Document, hunk DocHunk) { qt.Assert(t, &hunk.Hunk, qt.DeepEquals, dir.Hunk) } -func assertChildren(t *testing.T, dir DirEnt) { +func assertChildren(t *testing.T, dir *DirEnt) { cm := make(map[string]struct{}) for _, child := range dir.ChildrenList { { @@ -111,7 +111,7 @@ func keys(dirs map[string]*DirEnt) []string { return names } -func names(dirs []DirEnt) []string { +func names(dirs []*DirEnt) []string { names := make([]string, 0, len(dirs)) for _, d := range dirs { names = append(names, d.Name) diff --git a/testexec/testexec.go b/testexec/testexec.go index 1981444..10f3f3f 100644 --- a/testexec/testexec.go +++ b/testexec/testexec.go @@ -309,7 +309,7 @@ func (tcfg Tester) test(t *testing.T, data testmark.DirEnt, allowExec, allowScri if alreadyFailed { t.Skipf("parent commands failed, so while more commands are specified, testing them is not meaningful") } - tcfg.test(t, child, allowExec, allowScript, dir) + tcfg.test(t, *child, allowExec, allowScript, dir) }) } } diff --git a/testexec/testexec_test.go b/testexec/testexec_test.go index 0701f4a..6968087 100644 --- a/testexec/testexec_test.go +++ b/testexec/testexec_test.go @@ -21,7 +21,7 @@ func Test(t *testing.T) { test := testexec.Tester{ Patches: &patches, } - test.TestScript(t, dir) + test.TestScript(t, *dir) }) } patches.WriteFileWithPatches(doc, filename) diff --git a/testmark.go b/testmark.go index 7b87315..4113279 100644 --- a/testmark.go +++ b/testmark.go @@ -72,5 +72,5 @@ type DirEnt struct { // Children, recursively. Children map[string]*DirEnt - ChildrenList []DirEnt + ChildrenList []*DirEnt }