Skip to content

Commit 4eac502

Browse files
committed
Some improvements
1 parent 1e765c5 commit 4eac502

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

routers/web/repo/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func Tree(ctx *context.Context) {
9898
var results []*files_service.TreeViewNode
9999
var err error
100100
if !recursive {
101-
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.TreePath, ctx.Repo.RefFullName, false)
101+
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.TreePath, ctx.Repo.RefFullName)
102102
} else {
103103
results, err = files_service.GetTreeInformation(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.TreePath, ctx.Repo.RefFullName)
104104
}

services/repository/files/tree.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ Example 3: (path: d3/d3d1)
235235
"path": "d3/d3d1/d3d1f2"
236236
}]
237237
*/
238-
func GetTreeList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, treePath string, ref git.RefName, recursive bool) ([]*TreeViewNode, error) {
238+
func GetTreeList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, treePath string, ref git.RefName) ([]*TreeViewNode, error) {
239239
if repo.IsEmpty {
240240
return nil, nil
241241
}
@@ -244,7 +244,7 @@ func GetTreeList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
244244
}
245245

246246
// Check that the path given in opts.treePath is valid (not a git path)
247-
cleanTreePath := CleanUploadFileName(treePath)
247+
cleanTreePath := util.PathJoinRel(treePath)
248248
if cleanTreePath == "" && treePath != "" {
249249
return nil, ErrFilenameInvalid{
250250
Path: treePath,
@@ -273,12 +273,8 @@ func GetTreeList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
273273
if err != nil {
274274
return nil, err
275275
}
276-
var entries git.Entries
277-
if recursive {
278-
entries, err = gitTree.ListEntriesRecursiveFast()
279-
} else {
280-
entries, err = gitTree.ListEntries()
281-
}
276+
277+
entries, err := gitTree.ListEntries()
282278
if err != nil {
283279
return nil, err
284280
}
@@ -440,7 +436,7 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, gitRep
440436
}
441437

442438
// Check that the path given in opts.treePath is valid (not a git path)
443-
cleanTreePath := CleanUploadFileName(treePath)
439+
cleanTreePath := util.PathJoinRel(treePath)
444440
if cleanTreePath == "" && treePath != "" {
445441
return nil, ErrFilenameInvalid{
446442
Path: treePath,

services/repository/files/tree_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func Test_GetTreeList(t *testing.T) {
6363

6464
refName := git.RefNameFromBranch(ctx1.Repo.Repository.DefaultBranch)
6565

66-
treeList, err := GetTreeList(ctx1, ctx1.Repo.Repository, ctx1.Repo.GitRepo, "", refName, true)
66+
treeList, err := GetTreeList(ctx1, ctx1.Repo.Repository, ctx1.Repo.GitRepo, "", refName)
6767
assert.NoError(t, err)
6868
assert.Len(t, treeList, 1)
6969
assert.EqualValues(t, "README.md", treeList[0].Name)
@@ -80,19 +80,14 @@ func Test_GetTreeList(t *testing.T) {
8080

8181
refName = git.RefNameFromBranch(ctx2.Repo.Repository.DefaultBranch)
8282

83-
treeList, err = GetTreeList(ctx2, ctx2.Repo.Repository, ctx2.Repo.GitRepo, "", refName, true)
83+
treeList, err = GetTreeList(ctx2, ctx2.Repo.Repository, ctx2.Repo.GitRepo, "", refName)
8484
assert.NoError(t, err)
8585
assert.Len(t, treeList, 2)
8686

8787
assert.EqualValues(t, "doc", treeList[0].Name)
8888
assert.EqualValues(t, "doc", treeList[0].Path)
8989
assert.EqualValues(t, "tree", treeList[0].Type)
90-
assert.Len(t, treeList[0].Children, 1)
91-
92-
assert.EqualValues(t, "doc.md", treeList[0].Children[0].Name)
93-
assert.EqualValues(t, "doc/doc.md", treeList[0].Children[0].Path)
94-
assert.EqualValues(t, "blob", treeList[0].Children[0].Type)
95-
assert.Empty(t, treeList[0].Children[0].Children)
90+
assert.Empty(t, treeList[0].Children)
9691

9792
assert.EqualValues(t, "README.md", treeList[1].Name)
9893
assert.EqualValues(t, "README.md", treeList[1].Path)

0 commit comments

Comments
 (0)