forgejo/routers/web/repo/treelist.go
forgejo-backport-action e286457990 [v11.0/forgejo] chore: branding import path (#7354)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/7337

- Massive replacement of changing `code.gitea.io/gitea` to `forgejo.org`.
- Resolves forgejo/discussions#258

Co-authored-by: Gusted <postmaster@gusted.xyz>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7354
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
2025-03-27 20:13:05 +00:00

54 lines
1,018 B
Go

// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repo
import (
"net/http"
"forgejo.org/modules/base"
"forgejo.org/modules/git"
"forgejo.org/services/context"
"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.ListEntriesRecursiveFast()
if err != nil {
ctx.ServerError("ListEntriesRecursiveFast", 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
}