1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-23 12:18:51 +02:00

more treeish files

This commit is contained in:
Jesse Duffield 2021-07-27 21:00:33 +10:00
parent ec82f8099c
commit 62393cf28a
3 changed files with 52 additions and 23 deletions

View File

@ -54,23 +54,33 @@ func TestBuildTreeFromFiles(t *testing.T) {
name: "paths that can be compressed", name: "paths that can be compressed",
files: []*models.File{ files: []*models.File{
{ {
Name: "dir1/a", Name: "dir1/dir3/a",
}, },
{ {
Name: "dir2/b", Name: "dir2/dir4/b",
}, },
}, },
expected: &FileNode{ expected: &FileNode{
Path: "", Path: "",
Children: []*FileNode{ Children: []*FileNode{
{ {
File: &models.File{Name: "dir1/a"}, Path: "dir1/dir3",
Path: "dir1/a", Children: []*FileNode{
{
File: &models.File{Name: "dir1/dir3/a"},
Path: "dir1/dir3/a",
},
},
CompressionLevel: 1, CompressionLevel: 1,
}, },
{ {
File: &models.File{Name: "dir2/b"}, Path: "dir2/dir4",
Path: "dir2/b", Children: []*FileNode{
{
File: &models.File{Name: "dir2/dir4/b"},
Path: "dir2/dir4/b",
},
},
CompressionLevel: 1, CompressionLevel: 1,
}, },
}, },
@ -201,12 +211,12 @@ func TestBuildFlatTreeFromFiles(t *testing.T) {
{ {
File: &models.File{Name: "dir1/a"}, File: &models.File{Name: "dir1/a"},
Path: "dir1/a", Path: "dir1/a",
CompressionLevel: 1, CompressionLevel: 0,
}, },
{ {
File: &models.File{Name: "dir2/b"}, File: &models.File{Name: "dir2/b"},
Path: "dir2/b", Path: "dir2/b",
CompressionLevel: 1, CompressionLevel: 0,
}, },
}, },
}, },
@ -351,23 +361,33 @@ func TestBuildTreeFromCommitFiles(t *testing.T) {
name: "paths that can be compressed", name: "paths that can be compressed",
files: []*models.CommitFile{ files: []*models.CommitFile{
{ {
Name: "dir1/a", Name: "dir1/dir3/a",
}, },
{ {
Name: "dir2/b", Name: "dir2/dir4/b",
}, },
}, },
expected: &CommitFileNode{ expected: &CommitFileNode{
Path: "", Path: "",
Children: []*CommitFileNode{ Children: []*CommitFileNode{
{ {
File: &models.CommitFile{Name: "dir1/a"}, Path: "dir1/dir3",
Path: "dir1/a", Children: []*CommitFileNode{
{
File: &models.CommitFile{Name: "dir1/dir3/a"},
Path: "dir1/dir3/a",
},
},
CompressionLevel: 1, CompressionLevel: 1,
}, },
{ {
File: &models.CommitFile{Name: "dir2/b"}, Path: "dir2/dir4",
Path: "dir2/b", Children: []*CommitFileNode{
{
File: &models.CommitFile{Name: "dir2/dir4/b"},
Path: "dir2/dir4/b",
},
},
CompressionLevel: 1, CompressionLevel: 1,
}, },
}, },
@ -464,12 +484,12 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) {
{ {
File: &models.CommitFile{Name: "dir1/a"}, File: &models.CommitFile{Name: "dir1/a"},
Path: "dir1/a", Path: "dir1/a",
CompressionLevel: 1, CompressionLevel: 0,
}, },
{ {
File: &models.CommitFile{Name: "dir2/b"}, File: &models.CommitFile{Name: "dir2/b"},
Path: "dir2/b", Path: "dir2/b",
CompressionLevel: 1, CompressionLevel: 0,
}, },
}, },
}, },

View File

@ -84,9 +84,13 @@ func TestCompress(t *testing.T) {
Path: "", Path: "",
Children: []*FileNode{ Children: []*FileNode{
{ {
Path: "dir1/file2", Path: "dir1",
Children: []*FileNode{
{
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
CompressionLevel: 1, Path: "dir1/file2",
},
},
}, },
{ {
Path: "dir2", Path: "dir2",
@ -102,9 +106,14 @@ func TestCompress(t *testing.T) {
}, },
}, },
{ {
Path: "dir3/dir3-1/file5", Path: "dir3/dir3-1",
CompressionLevel: 1,
Children: []*FileNode{
{
File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
CompressionLevel: 2, Path: "dir3/dir3-1/file5",
},
},
}, },
{ {
File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},

View File

@ -170,7 +170,7 @@ func compressAux(node INode) INode {
children := node.GetChildren() children := node.GetChildren()
for i := range children { for i := range children {
grandchildren := children[i].GetChildren() grandchildren := children[i].GetChildren()
for len(grandchildren) == 1 { for len(grandchildren) == 1 && !grandchildren[0].IsLeaf() {
grandchildren[0].SetCompressionLevel(children[i].GetCompressionLevel() + 1) grandchildren[0].SetCompressionLevel(children[i].GetCompressionLevel() + 1)
children[i] = grandchildren[0] children[i] = grandchildren[0]
grandchildren = children[i].GetChildren() grandchildren = children[i].GetChildren()