mirror of
https://github.com/go-gitea/gitea.git
synced 2025-01-04 09:17:43 +03:00
Add tree
This commit is contained in:
parent
64b4cf4f54
commit
b60ee86a24
@ -5,6 +5,8 @@ package repo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
@ -52,3 +54,27 @@ func isExcludedEntry(entry *git.TreeEntry) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func getPossibleBranches(dir string) []string {
|
||||
cnt := strings.Count(dir, "/")
|
||||
branches := make([]string, cnt, cnt)
|
||||
for i := 0; i < cnt; i++ {
|
||||
branches[i] = dir
|
||||
dir = path.Dir(dir)
|
||||
}
|
||||
return branches
|
||||
}
|
||||
|
||||
func guessRefInfoAndDir(ctx *context.Context, dir string) (git.RefName, string, error) {
|
||||
branches := getPossibleBranches(dir)
|
||||
}
|
||||
|
||||
func Tree(ctx *context.Context) {
|
||||
pathParam := ctx.PathParam("*")
|
||||
dir := path.Dir(pathParam)
|
||||
refName, realDir, err := guessRefInfoAndDir(ctx, dir)
|
||||
if err != nil {
|
||||
ctx.ServerError("guessRefInfoAndDir", err)
|
||||
return
|
||||
}
|
||||
}
|
10
routers/web/repo/tree_test.go
Normal file
10
routers/web/repo/tree_test.go
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package repo
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_getPossibleBranches(t *testing.T) {
|
||||
getPossibleBranches("")
|
||||
}
|
@ -1157,14 +1157,14 @@ func registerRoutes(m *web.Router) {
|
||||
|
||||
m.Group("/{username}/{reponame}", func() {
|
||||
m.Get("/find/*", repo.FindFiles)
|
||||
m.Group("/tree-list", func() {
|
||||
m.Group("/tree-list", func() { // for find files
|
||||
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.TreeList)
|
||||
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.TreeList)
|
||||
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.TreeList)
|
||||
})
|
||||
m.Group("/contents", func() {
|
||||
m.Get("", repo.GetContentsList)
|
||||
m.Get("/*", repo.GetContents)
|
||||
m.Group("/tree", func() {
|
||||
m.Get("", repo.Tree)
|
||||
m.Get("/*", repo.Tree)
|
||||
})
|
||||
m.Get("/compare", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
|
||||
m.Combo("/compare/*", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists).
|
||||
|
Loading…
Reference in New Issue
Block a user