Skip to content

Commit 0a2e317

Browse files
authored
Merge branch 'main' into support-everyone-access
2 parents 958d497 + 348b707 commit 0a2e317

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

routers/web/repo/render.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import (
2121

2222
// RenderFile renders a file by repos path
2323
func RenderFile(ctx *context.Context) {
24-
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
24+
var blob *git.Blob
25+
var err error
26+
if ctx.Repo.TreePath != "" {
27+
blob, err = ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
28+
} else {
29+
blob, err = ctx.Repo.GitRepo.GetBlob(ctx.PathParam("sha"))
30+
}
2531
if err != nil {
2632
if git.IsErrNotExist(err) {
2733
ctx.NotFound("GetBlobByPath", err)

routers/web/web.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ func registerRoutes(m *web.Router) {
15311531
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownloadOrLFS)
15321532
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownloadOrLFS)
15331533
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.SingleDownloadOrLFS)
1534-
m.Get("/blob/{sha}", context.RepoRefByType(context.RepoRefBlob), repo.DownloadByIDOrLFS)
1534+
m.Get("/blob/{sha}", repo.DownloadByIDOrLFS)
15351535
// "/*" route is deprecated, and kept for backward compatibility
15361536
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.SingleDownloadOrLFS)
15371537
}, repo.MustBeNotEmpty)
@@ -1540,7 +1540,7 @@ func registerRoutes(m *web.Router) {
15401540
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownload)
15411541
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownload)
15421542
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.SingleDownload)
1543-
m.Get("/blob/{sha}", context.RepoRefByType(context.RepoRefBlob), repo.DownloadByID)
1543+
m.Get("/blob/{sha}", repo.DownloadByID)
15441544
// "/*" route is deprecated, and kept for backward compatibility
15451545
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.SingleDownload)
15461546
}, repo.MustBeNotEmpty)
@@ -1549,7 +1549,7 @@ func registerRoutes(m *web.Router) {
15491549
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RenderFile)
15501550
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RenderFile)
15511551
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RenderFile)
1552-
m.Get("/blob/{sha}", context.RepoRefByType(context.RepoRefBlob), repo.RenderFile)
1552+
m.Get("/blob/{sha}", repo.RenderFile)
15531553
}, repo.MustBeNotEmpty)
15541554

15551555
m.Group("/commits", func() {

services/context/repo.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ const (
686686
RepoRefBranch
687687
RepoRefTag
688688
RepoRefCommit
689-
RepoRefBlob
690689
)
691690

692691
const headRefName = "HEAD"
@@ -725,9 +724,6 @@ func getRefNameLegacy(ctx *Base, repo *Repository, reqPath, extraRef string) (st
725724
repo.TreePath = strings.Join(reqRefPathParts[1:], "/")
726725
return reqRefPathParts[0], RepoRefCommit
727726
}
728-
if refName := getRefName(ctx, repo, reqPath, RepoRefBlob); refName != "" {
729-
return refName, RepoRefBlob
730-
}
731727
// FIXME: the old code falls back to default branch if "ref" doesn't exist, there could be an edge case:
732728
// "README?ref=no-such" would read the README file from the default branch, but the user might expect a 404
733729
repo.TreePath = reqPath
@@ -785,12 +781,6 @@ func getRefName(ctx *Base, repo *Repository, path string, pathType RepoRefType)
785781
repo.TreePath = strings.Join(parts[1:], "/")
786782
return commit.ID.String()
787783
}
788-
case RepoRefBlob:
789-
_, err := repo.GitRepo.GetBlob(path)
790-
if err != nil {
791-
return ""
792-
}
793-
return path
794784
default:
795785
panic(fmt.Sprintf("Unrecognized path type: %v", pathType))
796786
}

0 commit comments

Comments
 (0)