Skip to content

Commit 99c4b1c

Browse files
committed
fine tune
1 parent b0e814b commit 99c4b1c

File tree

6 files changed

+22
-35
lines changed

6 files changed

+22
-35
lines changed

modules/fileicon/material.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package fileicon
55

66
import (
77
"html/template"
8-
"path"
98
"strings"
109
"sync"
1110

@@ -134,7 +133,7 @@ func (m *MaterialIconProvider) FindIconName(entry *EntryInfo) string {
134133
return "folder-git"
135134
}
136135

137-
fileNameLower := strings.ToLower(path.Base(entry.BaseName))
136+
fileNameLower := strings.ToLower(entry.BaseName)
138137
if entry.EntryMode.IsDir() {
139138
if s, ok := m.rules.FolderNames[fileNameLower]; ok {
140139
return s

modules/git/tree_entry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func EntryFollowLinks(commit *Commit, firstFullPath string, firstTreeEntry *Tree
7272
}
7373
}
7474
if treeEntry.IsLink() {
75-
return res, util.ErrorWrap(util.ErrUnprocessableContent, "%q has too many links", fullPath)
75+
return res, util.ErrorWrap(util.ErrUnprocessableContent, "%q has too many links", firstFullPath)
7676
}
7777
return res, nil
7878
}

modules/git/tree_entry_gogit.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ func (te *TreeEntry) Size() int64 {
5151
return te.size
5252
}
5353

54-
func (te *TreeEntry) FullPath() string {
55-
return te.Name()
56-
}
57-
5854
// IsSubModule if the entry is a submodule
5955
func (te *TreeEntry) IsSubModule() bool {
6056
return te.gogitTreeEntry.Mode == filemode.Submodule

routers/web/repo/treelist.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package repo
66
import (
77
"html/template"
88
"net/http"
9+
"path"
910
"strings"
1011

1112
pull_model "code.gitea.io/gitea/models/pull"
@@ -111,7 +112,7 @@ func transformDiffTreeForWeb(renderedIconPool *fileicon.RenderedIconPool, diffTr
111112
item := &WebDiffFileItem{FullName: file.HeadPath, DiffStatus: file.Status}
112113
item.IsViewed = filesViewedState[item.FullName] == pull_model.Viewed
113114
item.NameHash = git.HashFilePathForWebUI(item.FullName)
114-
item.FileIcon = fileicon.RenderEntryIconHTML(renderedIconPool, &fileicon.EntryInfo{BaseName: file.HeadPath, EntryMode: file.HeadMode})
115+
item.FileIcon = fileicon.RenderEntryIconHTML(renderedIconPool, &fileicon.EntryInfo{BaseName: path.Base(file.HeadPath), EntryMode: file.HeadMode})
115116

116117
switch file.HeadMode {
117118
case git.EntryModeTree:

routers/web/repo/view_home.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,23 +386,16 @@ func redirectSrcToRaw(ctx *context.Context) bool {
386386
return false
387387
}
388388

389-
func redirectFollowSymlink(ctx *context.Context) bool {
390-
if ctx.Repo.TreePath != "" && ctx.FormBool("follow_symlink") {
391-
// Redirect to the symlink target path
392-
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
393-
if err != nil {
394-
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
395-
return true
396-
}
397-
if entry.IsLink() {
398-
res, err := git.EntryFollowLinks(ctx.Repo.Commit, ctx.Repo.TreePath, entry)
399-
if err != nil {
400-
return false // don't handle the links we cannot resolve
401-
}
389+
func redirectFollowSymlink(ctx *context.Context, treePathEntry *git.TreeEntry) bool {
390+
if ctx.Repo.TreePath == "" || !ctx.FormBool("follow_symlink") {
391+
return false
392+
}
393+
if treePathEntry.IsLink() {
394+
if res, err := git.EntryFollowLinks(ctx.Repo.Commit, ctx.Repo.TreePath, treePathEntry); err == nil {
402395
redirect := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(res.TargetFullPath) + "?" + ctx.Req.URL.RawQuery
403396
ctx.Redirect(redirect)
404397
return true
405-
}
398+
} // else: don't handle the links we cannot resolve, so ignore the error
406399
}
407400
return false
408401
}
@@ -412,9 +405,6 @@ func Home(ctx *context.Context) {
412405
if handleRepoHomeFeed(ctx) {
413406
return
414407
}
415-
if redirectFollowSymlink(ctx) {
416-
return
417-
}
418408
if redirectSrcToRaw(ctx) {
419409
return
420410
}
@@ -449,6 +439,10 @@ func Home(ctx *context.Context) {
449439
return
450440
}
451441

442+
if redirectFollowSymlink(ctx, entry) {
443+
return
444+
}
445+
452446
// prepare the tree path
453447
var treeNames, paths []string
454448
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()

routers/web/repo/view_readme.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,24 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil
144144
}
145145

146146
readmeFullPath := path.Join(ctx.Repo.TreePath, subfolder, readmeFile.Name())
147-
target := readmeFile
147+
readmeTargetEntry := readmeFile
148148
if readmeFile.IsLink() {
149-
res, _ := git.EntryFollowLinks(ctx.Repo.Commit, readmeFullPath, readmeFile)
150-
if res != nil {
151-
target = res.TargetEntry
149+
if res, err := git.EntryFollowLinks(ctx.Repo.Commit, readmeFullPath, readmeFile); err == nil {
150+
readmeTargetEntry = res.TargetEntry
152151
} else {
153-
target = nil
152+
readmeTargetEntry = nil // if we cannot resolve the symlink, we cannot render the readme, ignore the error
154153
}
155154
}
156-
if target == nil {
157-
// if findReadmeFile() failed and/or gave us a broken symlink (which it shouldn't)
158-
// simply skip rendering the README
159-
return
155+
if readmeTargetEntry == nil {
156+
return // if no valid README entry found, skip rendering the README
160157
}
161158

162159
ctx.Data["RawFileLink"] = ""
163160
ctx.Data["ReadmeInList"] = path.Join(subfolder, readmeFile.Name()) // the relative path to the readme file to the current tree path
164161
ctx.Data["ReadmeExist"] = true
165162
ctx.Data["FileIsSymlink"] = readmeFile.IsLink()
166163

167-
buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, target.Blob())
164+
buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, readmeTargetEntry.Blob())
168165
if err != nil {
169166
ctx.ServerError("getFileReader", err)
170167
return

0 commit comments

Comments
 (0)