1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-24 08:52:21 +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",
files: []*models.File{
{
Name: "dir1/a",
Name: "dir1/dir3/a",
},
{
Name: "dir2/b",
Name: "dir2/dir4/b",
},
},
expected: &FileNode{
Path: "",
Children: []*FileNode{
{
File: &models.File{Name: "dir1/a"},
Path: "dir1/a",
Path: "dir1/dir3",
Children: []*FileNode{
{
File: &models.File{Name: "dir1/dir3/a"},
Path: "dir1/dir3/a",
},
},
CompressionLevel: 1,
},
{
File: &models.File{Name: "dir2/b"},
Path: "dir2/b",
Path: "dir2/dir4",
Children: []*FileNode{
{
File: &models.File{Name: "dir2/dir4/b"},
Path: "dir2/dir4/b",
},
},
CompressionLevel: 1,
},
},
@ -201,12 +211,12 @@ func TestBuildFlatTreeFromFiles(t *testing.T) {
{
File: &models.File{Name: "dir1/a"},
Path: "dir1/a",
CompressionLevel: 1,
CompressionLevel: 0,
},
{
File: &models.File{Name: "dir2/b"},
Path: "dir2/b",
CompressionLevel: 1,
CompressionLevel: 0,
},
},
},
@ -351,23 +361,33 @@ func TestBuildTreeFromCommitFiles(t *testing.T) {
name: "paths that can be compressed",
files: []*models.CommitFile{
{
Name: "dir1/a",
Name: "dir1/dir3/a",
},
{
Name: "dir2/b",
Name: "dir2/dir4/b",
},
},
expected: &CommitFileNode{
Path: "",
Children: []*CommitFileNode{
{
File: &models.CommitFile{Name: "dir1/a"},
Path: "dir1/a",
Path: "dir1/dir3",
Children: []*CommitFileNode{
{
File: &models.CommitFile{Name: "dir1/dir3/a"},
Path: "dir1/dir3/a",
},
},
CompressionLevel: 1,
},
{
File: &models.CommitFile{Name: "dir2/b"},
Path: "dir2/b",
Path: "dir2/dir4",
Children: []*CommitFileNode{
{
File: &models.CommitFile{Name: "dir2/dir4/b"},
Path: "dir2/dir4/b",
},
},
CompressionLevel: 1,
},
},
@ -464,12 +484,12 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) {
{
File: &models.CommitFile{Name: "dir1/a"},
Path: "dir1/a",
CompressionLevel: 1,
CompressionLevel: 0,
},
{
File: &models.CommitFile{Name: "dir2/b"},
Path: "dir2/b",
CompressionLevel: 1,
CompressionLevel: 0,
},
},
},

View File

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

View File

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