mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
"code.gitea.io/gitea/modules/context"
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
"github.com/go-enry/go-enry/v2"
|
|
)
|
|
|
|
// TreeList get all files' entries of a repository
|
|
func TreeList(ctx *context.Context) {
|
|
tree, err := ctx.Repo.Commit.SubTree("/")
|
|
if err != nil {
|
|
ctx.ServerError("Repo.Commit.SubTree", err)
|
|
return
|
|
}
|
|
|
|
entries, err := tree.ListEntriesRecursive()
|
|
if err != nil {
|
|
ctx.ServerError("ListEntriesRecursive", err)
|
|
return
|
|
}
|
|
entries.CustomSort(base.NaturalSortLess)
|
|
|
|
files := make([]string, 0, len(entries))
|
|
for _, entry := range entries {
|
|
if !isExcludedEntry(entry) {
|
|
files = append(files, entry.Name())
|
|
}
|
|
}
|
|
ctx.JSON(http.StatusOK, files)
|
|
}
|
|
|
|
func isExcludedEntry(entry *git.TreeEntry) bool {
|
|
if entry.IsDir() {
|
|
return true
|
|
}
|
|
|
|
if entry.IsSubModule() {
|
|
return true
|
|
}
|
|
|
|
if enry.IsVendor(entry.Name()) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|