1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-01-04 09:17:43 +03:00
This commit is contained in:
Lunny Xiao 2024-12-16 09:36:07 -08:00
parent 64b4cf4f54
commit b60ee86a24
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 40 additions and 4 deletions

View File

@ -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
}
}

View 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("")
}

View File

@ -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).