Skip to content

Commit e2cc853

Browse files
committed
refactor ref type
1 parent 98d7e04 commit e2cc853

File tree

5 files changed

+122
-81
lines changed

5 files changed

+122
-81
lines changed

modules/git/ref.go

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"regexp"
88
"strings"
99

10+
"code.gitea.io/gitea/modules/setting"
1011
"code.gitea.io/gitea/modules/util"
1112
)
1213

@@ -84,6 +85,20 @@ func RefNameFromCommit(shortName string) RefName {
8485
return RefName(shortName)
8586
}
8687

88+
func RefNameFromTypeAndShortName(tp RefType, shortName string) RefName {
89+
switch tp {
90+
case RefTypeBranch:
91+
return RefNameFromBranch(shortName)
92+
case RefTypeTag:
93+
return RefNameFromTag(shortName)
94+
case RefTypeCommit:
95+
return RefNameFromCommit(shortName)
96+
default:
97+
setting.PanicInDevOrTesting("Unknown RefType: %v", tp)
98+
return ""
99+
}
100+
}
101+
87102
func (ref RefName) String() string {
88103
return string(ref)
89104
}

routers/web/repo/find.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
func FindFiles(ctx *context.Context) {
2020
path := ctx.PathParam("*")
2121
ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(path)
22-
ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path)
22+
ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path) +
23+
"?ref_type=" + ctx.FormTrim("ref_type") + "&ref_name=" + ctx.FormTrim("ref_name")
2324
ctx.HTML(http.StatusOK, tplFindFiles)
2425
}

routers/web/web.go

+34-35
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models/db"
1212
"code.gitea.io/gitea/models/perm"
1313
"code.gitea.io/gitea/models/unit"
14+
"code.gitea.io/gitea/modules/git"
1415
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/metrics"
1617
"code.gitea.io/gitea/modules/public"
@@ -1156,11 +1157,9 @@ func registerRoutes(m *web.Router) {
11561157

11571158
m.Group("/{username}/{reponame}", func() {
11581159
m.Get("/find/*", repo.FindFiles)
1159-
m.Group("/tree-list", func() {
1160-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.TreeList)
1161-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.TreeList)
1162-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.TreeList)
1163-
})
1160+
m.Get("/find", repo.FindFiles)
1161+
m.Get("/tree-list/*", context.RepoRefByQueries(), repo.TreeList)
1162+
m.Get("/tree-list", context.RepoRefByQueries(), repo.TreeList)
11641163
m.Get("/compare", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
11651164
m.Combo("/compare/*", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists).
11661165
Get(repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
@@ -1313,9 +1312,9 @@ func registerRoutes(m *web.Router) {
13131312

13141313
m.Group("/branches", func() {
13151314
m.Group("/_new", func() {
1316-
m.Post("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.CreateBranch)
1317-
m.Post("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.CreateBranch)
1318-
m.Post("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.CreateBranch)
1315+
m.Post("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.CreateBranch)
1316+
m.Post("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.CreateBranch)
1317+
m.Post("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.CreateBranch)
13191318
}, web.Bind(forms.NewBranchForm{}))
13201319
m.Post("/delete", repo.DeleteBranchPost)
13211320
m.Post("/restore", repo.RestoreBranchPost)
@@ -1334,7 +1333,7 @@ func registerRoutes(m *web.Router) {
13341333
m.Get(".rss", feedEnabled, repo.TagsListFeedRSS)
13351334
m.Get(".atom", feedEnabled, repo.TagsListFeedAtom)
13361335
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
1337-
repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
1336+
repo.MustBeNotEmpty, context.RepoRefByType(git.RefTypeTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
13381337
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
13391338
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
13401339
}, optSignIn, context.RepoAssignment, reqRepoCodeReader)
@@ -1348,7 +1347,7 @@ func registerRoutes(m *web.Router) {
13481347
m.Get(".rss", feedEnabled, repo.ReleasesFeedRSS)
13491348
m.Get(".atom", feedEnabled, repo.ReleasesFeedAtom)
13501349
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
1351-
repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
1350+
repo.MustBeNotEmpty, context.RepoRefByType(git.RefTypeTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
13521351
m.Get("/releases/attachments/{uuid}", repo.MustBeNotEmpty, repo.GetAttachment)
13531352
m.Get("/releases/download/{vTag}/{fileName}", repo.MustBeNotEmpty, repo.RedirectDownload)
13541353
m.Group("/releases", func() {
@@ -1521,42 +1520,42 @@ func registerRoutes(m *web.Router) {
15211520
}, repo.MustBeNotEmpty, context.RepoRef())
15221521

15231522
m.Group("/media", func() {
1524-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownloadOrLFS)
1525-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownloadOrLFS)
1526-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.SingleDownloadOrLFS)
1523+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.SingleDownloadOrLFS)
1524+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.SingleDownloadOrLFS)
1525+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.SingleDownloadOrLFS)
15271526
m.Get("/blob/{sha}", repo.DownloadByIDOrLFS)
15281527
// "/*" route is deprecated, and kept for backward compatibility
1529-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.SingleDownloadOrLFS)
1528+
m.Get("/*", context.RepoRefByType(""), repo.SingleDownloadOrLFS)
15301529
}, repo.MustBeNotEmpty)
15311530

15321531
m.Group("/raw", func() {
1533-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownload)
1534-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownload)
1535-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.SingleDownload)
1532+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.SingleDownload)
1533+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.SingleDownload)
1534+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.SingleDownload)
15361535
m.Get("/blob/{sha}", repo.DownloadByID)
15371536
// "/*" route is deprecated, and kept for backward compatibility
1538-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.SingleDownload)
1537+
m.Get("/*", context.RepoRefByType(""), repo.SingleDownload)
15391538
}, repo.MustBeNotEmpty)
15401539

15411540
m.Group("/render", func() {
1542-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RenderFile)
1543-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RenderFile)
1544-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RenderFile)
1541+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.RenderFile)
1542+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.RenderFile)
1543+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.RenderFile)
15451544
m.Get("/blob/{sha}", repo.RenderFile)
15461545
}, repo.MustBeNotEmpty)
15471546

15481547
m.Group("/commits", func() {
1549-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RefCommits)
1550-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RefCommits)
1551-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RefCommits)
1548+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.RefCommits)
1549+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.RefCommits)
1550+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.RefCommits)
15521551
// "/*" route is deprecated, and kept for backward compatibility
1553-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.RefCommits)
1552+
m.Get("/*", context.RepoRefByType(""), repo.RefCommits)
15541553
}, repo.MustBeNotEmpty)
15551554

15561555
m.Group("/blame", func() {
1557-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RefBlame)
1558-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RefBlame)
1559-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RefBlame)
1556+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.RefBlame)
1557+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.RefBlame)
1558+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.RefBlame)
15601559
}, repo.MustBeNotEmpty)
15611560

15621561
m.Get("/blob_excerpt/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
@@ -1568,20 +1567,20 @@ func registerRoutes(m *web.Router) {
15681567
m.Get("/cherry-pick/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, repo.CherryPick)
15691568
}, repo.MustBeNotEmpty, context.RepoRef())
15701569

1571-
m.Get("/rss/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
1572-
m.Get("/atom/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
1570+
m.Get("/rss/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)
1571+
m.Get("/atom/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)
15731572

15741573
m.Group("/src", func() {
15751574
m.Get("", func(ctx *context.Context) { ctx.Redirect(ctx.Repo.RepoLink) }) // there is no "{owner}/{repo}/src" page, so redirect to "{owner}/{repo}" to avoid 404
1576-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.Home)
1577-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.Home)
1578-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.Home)
1579-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.Home) // "/*" route is deprecated, and kept for backward compatibility
1575+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.Home)
1576+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.Home)
1577+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.Home)
1578+
m.Get("/*", context.RepoRefByType(""), repo.Home) // "/*" route is deprecated, and kept for backward compatibility
15801579
}, repo.SetEditorconfigIfExists)
15811580

15821581
m.Get("/forks", context.RepoRef(), repo.Forks)
15831582
m.Get("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}", repo.MustBeNotEmpty, repo.RawDiff)
1584-
m.Post("/lastcommit/*", context.RepoRefByType(context.RepoRefCommit), repo.LastCommit)
1583+
m.Post("/lastcommit/*", context.RepoRefByType(git.RefTypeCommit), repo.LastCommit)
15851584
}, optSignIn, context.RepoAssignment, reqRepoCodeReader)
15861585
// end "/{username}/{reponame}": repo code
15871586

services/context/repo.go

+70-44
Original file line numberDiff line numberDiff line change
@@ -677,24 +677,13 @@ func RepoAssignment(ctx *Context) {
677677
}
678678
}
679679

680-
// RepoRefType type of repo reference
681-
type RepoRefType int
682-
683-
const (
684-
// RepoRefUnknown is for legacy support, makes the code to "guess" the ref type
685-
RepoRefUnknown RepoRefType = iota
686-
RepoRefBranch
687-
RepoRefTag
688-
RepoRefCommit
689-
)
690-
691680
const headRefName = "HEAD"
692681

693682
// RepoRef handles repository reference names when the ref name is not
694683
// explicitly given
695684
func RepoRef() func(*Context) {
696685
// since no ref name is explicitly specified, ok to just use branch
697-
return RepoRefByType(RepoRefBranch)
686+
return RepoRefByType(git.RefTypeBranch)
698687
}
699688

700689
func getRefNameFromPath(repo *Repository, path string, isExist func(string) bool) string {
@@ -710,29 +699,29 @@ func getRefNameFromPath(repo *Repository, path string, isExist func(string) bool
710699
return ""
711700
}
712701

713-
func getRefNameLegacy(ctx *Base, repo *Repository, reqPath, extraRef string) (string, RepoRefType) {
702+
func getRefNameLegacy(ctx *Base, repo *Repository, reqPath, extraRef string) (string, git.RefType) {
714703
reqRefPath := path.Join(extraRef, reqPath)
715704
reqRefPathParts := strings.Split(reqRefPath, "/")
716-
if refName := getRefName(ctx, repo, reqRefPath, RepoRefBranch); refName != "" {
717-
return refName, RepoRefBranch
705+
if refName := getRefName(ctx, repo, reqRefPath, git.RefTypeBranch); refName != "" {
706+
return refName, git.RefTypeBranch
718707
}
719-
if refName := getRefName(ctx, repo, reqRefPath, RepoRefTag); refName != "" {
720-
return refName, RepoRefTag
708+
if refName := getRefName(ctx, repo, reqRefPath, git.RefTypeTag); refName != "" {
709+
return refName, git.RefTypeTag
721710
}
722711
if git.IsStringLikelyCommitID(git.ObjectFormatFromName(repo.Repository.ObjectFormatName), reqRefPathParts[0]) {
723712
// FIXME: this logic is different from other types. Ideally, it should also try to GetCommit to check if it exists
724713
repo.TreePath = strings.Join(reqRefPathParts[1:], "/")
725-
return reqRefPathParts[0], RepoRefCommit
714+
return reqRefPathParts[0], git.RefTypeCommit
726715
}
727716
// FIXME: the old code falls back to default branch if "ref" doesn't exist, there could be an edge case:
728717
// "README?ref=no-such" would read the README file from the default branch, but the user might expect a 404
729718
repo.TreePath = reqPath
730-
return repo.Repository.DefaultBranch, RepoRefBranch
719+
return repo.Repository.DefaultBranch, git.RefTypeBranch
731720
}
732721

733-
func getRefName(ctx *Base, repo *Repository, path string, pathType RepoRefType) string {
734-
switch pathType {
735-
case RepoRefBranch:
722+
func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) string {
723+
switch refType {
724+
case git.RefTypeBranch:
736725
ref := getRefNameFromPath(repo, path, repo.GitRepo.IsBranchExist)
737726
if len(ref) == 0 {
738727
// check if ref is HEAD
@@ -762,9 +751,9 @@ func getRefName(ctx *Base, repo *Repository, path string, pathType RepoRefType)
762751
}
763752

764753
return ref
765-
case RepoRefTag:
754+
case git.RefTypeTag:
766755
return getRefNameFromPath(repo, path, repo.GitRepo.IsTagExist)
767-
case RepoRefCommit:
756+
case git.RefTypeCommit:
768757
parts := strings.Split(path, "/")
769758
if git.IsStringLikelyCommitID(repo.GetObjectFormat(), parts[0], 7) {
770759
// FIXME: this logic is different from other types. Ideally, it should also try to GetCommit to check if it exists
@@ -782,7 +771,7 @@ func getRefName(ctx *Base, repo *Repository, path string, pathType RepoRefType)
782771
return commit.ID.String()
783772
}
784773
default:
785-
panic(fmt.Sprintf("Unrecognized path type: %v", pathType))
774+
panic(fmt.Sprintf("Unrecognized ref type: %v", refType))
786775
}
787776
return ""
788777
}
@@ -791,23 +780,9 @@ type RepoRefByTypeOptions struct {
791780
IgnoreNotExistErr bool
792781
}
793782

794-
func repoRefFullName(shortName string, typ RepoRefType) git.RefName {
795-
switch typ {
796-
case RepoRefBranch:
797-
return git.RefNameFromBranch(shortName)
798-
case RepoRefTag:
799-
return git.RefNameFromTag(shortName)
800-
case RepoRefCommit:
801-
return git.RefNameFromCommit(shortName)
802-
default:
803-
setting.PanicInDevOrTesting("Unknown RepoRefType: %v", typ)
804-
return git.RefNameFromBranch("main") // just a dummy result, it shouldn't happen
805-
}
806-
}
807-
808783
// RepoRefByType handles repository reference name for a specific type
809784
// of repository reference
810-
func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func(*Context) {
785+
func RepoRefByType(detectRefType git.RefType, opts ...RepoRefByTypeOptions) func(*Context) {
811786
opt := util.OptionalArg(opts)
812787
return func(ctx *Context) {
813788
var err error
@@ -861,13 +836,13 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
861836
}
862837
ctx.Repo.IsViewBranch = true
863838
} else { // there is a path in request
864-
guessLegacyPath := refType == RepoRefUnknown
839+
guessLegacyPath := refType == ""
865840
if guessLegacyPath {
866841
refShortName, refType = getRefNameLegacy(ctx.Base, ctx.Repo, reqPath, "")
867842
} else {
868843
refShortName = getRefName(ctx.Base, ctx.Repo, reqPath, refType)
869844
}
870-
ctx.Repo.RefFullName = repoRefFullName(refShortName, refType)
845+
ctx.Repo.RefFullName = git.RefNameFromTypeAndShortName(refType, refShortName)
871846
isRenamedBranch, has := ctx.Data["IsRenamedBranch"].(bool)
872847
if isRenamedBranch && has {
873848
renamedBranchName := ctx.Data["RenamedBranchName"].(string)
@@ -877,7 +852,7 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
877852
return
878853
}
879854

880-
if refType == RepoRefBranch && ctx.Repo.GitRepo.IsBranchExist(refShortName) {
855+
if refType == git.RefTypeBranch && ctx.Repo.GitRepo.IsBranchExist(refShortName) {
881856
ctx.Repo.IsViewBranch = true
882857
ctx.Repo.BranchName = refShortName
883858
ctx.Repo.RefFullName = git.RefNameFromBranch(refShortName)
@@ -888,7 +863,7 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
888863
return
889864
}
890865
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
891-
} else if refType == RepoRefTag && ctx.Repo.GitRepo.IsTagExist(refShortName) {
866+
} else if refType == git.RefTypeTag && ctx.Repo.GitRepo.IsTagExist(refShortName) {
892867
ctx.Repo.IsViewTag = true
893868
ctx.Repo.RefFullName = git.RefNameFromTag(refShortName)
894869
ctx.Repo.TagName = refShortName
@@ -964,6 +939,57 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
964939
}
965940
}
966941

942+
func RepoRefByQueries() func(ctx *Context) {
943+
return func(ctx *Context) {
944+
if ctx.Repo.Repository.IsEmpty {
945+
// assume the user is viewing the (non-existent) default branch
946+
ctx.Repo.IsViewBranch = true
947+
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
948+
ctx.Repo.RefFullName = git.RefNameFromBranch(ctx.Repo.BranchName)
949+
return
950+
}
951+
952+
var err error
953+
if ctx.Repo.GitRepo == nil {
954+
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
955+
if err != nil {
956+
ctx.ServerError(fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err)
957+
return
958+
}
959+
}
960+
961+
ctx.Repo.RefFullName = git.RefNameFromTypeAndShortName(git.RefType(ctx.FormTrim("ref_type")), ctx.FormTrim("ref_name"))
962+
if ctx.Repo.RefFullName == "" {
963+
ctx.Error(http.StatusBadRequest, "invalid ref type or name")
964+
return
965+
}
966+
967+
switch ctx.Repo.RefFullName.RefType() {
968+
case git.RefTypeBranch:
969+
ctx.Repo.IsViewBranch = true
970+
ctx.Repo.BranchName = ctx.Repo.RefFullName.ShortName()
971+
case git.RefTypeTag:
972+
ctx.Repo.IsViewTag = true
973+
ctx.Repo.TagName = ctx.Repo.RefFullName.ShortName()
974+
case git.RefTypeCommit:
975+
ctx.Repo.IsViewCommit = true
976+
ctx.Repo.CommitID = ctx.Repo.RefFullName.ShortName()
977+
}
978+
979+
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(ctx.Repo.RefFullName.String())
980+
if err != nil {
981+
if git.IsErrNotExist(err) {
982+
ctx.NotFound("GetCommit", err)
983+
} else {
984+
ctx.ServerError("GetCommit", err)
985+
}
986+
return
987+
}
988+
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
989+
ctx.Repo.TreePath = ctx.PathParam("*")
990+
}
991+
}
992+
967993
// GitHookService checks if repository Git hooks service has been enabled.
968994
func GitHookService() func(ctx *Context) {
969995
return func(ctx *Context) {

templates/repo/home.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
<!-- Show go to file if on home page -->
6464
{{if $isTreePathRoot}}
65-
<a href="{{.Repository.Link}}/find/{{.RefTypeNameSubURL}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
65+
<a href="{{.Repository.Link}}/find/{{.TreePath}}?ref_type={{.RefFullName.RefType}}&ref_name={{.RefFullName.ShortName}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
6666
{{end}}
6767

6868
{{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}}

0 commit comments

Comments
 (0)