diff --git a/routers/web/repo/find.go b/routers/web/repo/find.go index 2a505971b8975..3a3a7610e772b 100644 --- a/routers/web/repo/find.go +++ b/routers/web/repo/find.go @@ -5,9 +5,7 @@ package repo import ( "net/http" - "net/url" - "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/context" @@ -20,8 +18,7 @@ const ( // FindFiles render the page to find repository files func FindFiles(ctx *context.Context) { path := ctx.PathParam("*") - ref := git.RefNameFromUserInput(ctx.FormTrim("ref"), git.RefTypeBranch, git.RefTypeTag, git.RefTypeCommit) - ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + ref.RefWebLinkPath() + "/" + util.PathEscapeSegments(path) - ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path) + "?ref=" + url.QueryEscape(ctx.FormTrim("ref")) + ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(path) + ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path) ctx.HTML(http.StatusOK, tplFindFiles) } diff --git a/routers/web/repo/treelist.go b/routers/web/repo/treelist.go index 6c3e0d83751fa..d11af4669f90c 100644 --- a/routers/web/repo/treelist.go +++ b/routers/web/repo/treelist.go @@ -15,12 +15,7 @@ import ( // TreeList get all files' entries of a repository func TreeList(ctx *context.Context) { - _, commit, err := ctx.Repo.GetRefCommit(ctx.FormString("ref"), git.RefTypeBranch, git.RefTypeTag, git.RefTypeCommit) - if err != nil { - ctx.ServerError("GetRefCommit", err) - return - } - tree, err := commit.SubTree("/") + tree, err := ctx.Repo.Commit.SubTree("/") if err != nil { ctx.ServerError("Repo.Commit.SubTree", err) return diff --git a/routers/web/web.go b/routers/web/web.go index 687664e81aeb7..e62cdec984508 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1157,8 +1157,11 @@ func registerRoutes(m *web.Router) { m.Group("/{username}/{reponame}", func() { m.Get("/find/*", repo.FindFiles) - m.Get("/find", repo.FindFiles) - m.Get("/tree-list", repo.TreeList) + m.Group("/tree-list", func() { + m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.TreeList) + m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.TreeList) + m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.TreeList) + }) m.Get("/compare", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff) m.Combo("/compare/*", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists). Get(repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff). diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 0a49687093ae1..86ad1629085a1 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -62,8 +62,7 @@ {{if $isTreePathRoot}} - {{/* FIXME: it should still use RefTypeNameSubURL, otherwise the link is ugly */}} - {{ctx.Locale.Tr "repo.find_file.go_to_file"}} + {{ctx.Locale.Tr "repo.find_file.go_to_file"}} {{end}} {{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}}