mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-08 20:43:24 +02:00
Fix bug
This commit is contained in:
3 files changed
+23
-12
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -126,7 +127,7 @@ type TreeEntry struct {
|
||||
Name string `json:"name"`
|
||||
IsFile bool `json:"isFile"`
|
||||
Path string `json:"path"`
|
||||
Children []*TreeEntry `json:"children"`
|
||||
Children []*TreeEntry `json:"children, omitempty"`
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -253,9 +254,12 @@ func GetTreeList(ctx context.Context, repo *repo_model.Repository, treePath stri
|
||||
for _, tree := range treeList {
|
||||
if !tree.IsFile {
|
||||
tree.Children = mapTree[tree.Path]
|
||||
sortTreeEntries(tree.Children)
|
||||
}
|
||||
}
|
||||
|
||||
sortTreeEntries(treeList)
|
||||
|
||||
return treeList, nil
|
||||
}
|
||||
|
||||
@@ -471,5 +475,17 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa
|
||||
Path: path.Join(dir, entry.Name()),
|
||||
})
|
||||
}
|
||||
sortTreeEntries(treeList)
|
||||
sortTreeEntries(parentEntry.Children)
|
||||
return treeList, nil
|
||||
}
|
||||
|
||||
// sortTreeEntries list directory first and with alpha sequence
|
||||
func sortTreeEntries(entries []*TreeEntry) {
|
||||
sort.Slice(entries, func(i, j int) bool {
|
||||
if entries[i].IsFile != entries[j].IsFile {
|
||||
return !entries[i].IsFile
|
||||
}
|
||||
return entries[i].Name < entries[j].Name
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user