Skip to content

Commit b1dde04

Browse files
committed
clean up
1 parent 4eac502 commit b1dde04

File tree

3 files changed

+26
-49
lines changed

3 files changed

+26
-49
lines changed

routers/web/repo/blame.go

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,63 +41,39 @@ type blameRow struct {
4141

4242
// RefBlame render blame page
4343
func RefBlame(ctx *context.Context) {
44-
fileName := ctx.Repo.TreePath
45-
if len(fileName) == 0 {
44+
ctx.Data["PageIsViewCode"] = true
45+
ctx.Data["IsBlame"] = true
46+
47+
// Get current entry user currently looking at.
48+
if ctx.Repo.TreePath == "" {
4649
ctx.NotFound(nil)
4750
return
4851
}
49-
50-
prepareHomeTreeSideBarSwitch(ctx)
51-
52-
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
53-
treeLink := branchLink
54-
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL()
55-
56-
if len(ctx.Repo.TreePath) > 0 {
57-
treeLink += "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
58-
}
59-
60-
var treeNames []string
61-
paths := make([]string, 0, 5)
62-
if len(ctx.Repo.TreePath) > 0 {
63-
treeNames = strings.Split(ctx.Repo.TreePath, "/")
64-
for i := range treeNames {
65-
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
66-
}
67-
68-
ctx.Data["HasParentPath"] = true
69-
if len(paths)-2 >= 0 {
70-
ctx.Data["ParentPath"] = "/" + paths[len(paths)-1]
71-
}
72-
}
73-
74-
// Get current entry user currently looking at.
7552
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
7653
if err != nil {
7754
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
7855
return
7956
}
8057

81-
blob := entry.Blob()
58+
treeNames := strings.Split(ctx.Repo.TreePath, "/")
59+
var paths []string
60+
for i := range treeNames {
61+
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
62+
}
8263

8364
ctx.Data["Paths"] = paths
84-
ctx.Data["TreeLink"] = treeLink
8565
ctx.Data["TreeNames"] = treeNames
86-
ctx.Data["BranchLink"] = branchLink
87-
88-
ctx.Data["RawFileLink"] = rawLink + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
89-
ctx.Data["PageIsViewCode"] = true
90-
91-
ctx.Data["IsBlame"] = true
66+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
67+
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
9268

69+
blob := entry.Blob()
9370
fileSize := blob.Size()
9471
ctx.Data["FileSize"] = fileSize
9572
ctx.Data["FileName"] = blob.Name()
9673

97-
var tplName templates.TplName
98-
if ctx.FormBool("only_content") {
99-
tplName = tplRepoViewContent
100-
} else {
74+
tplName := tplRepoViewContent
75+
if !ctx.FormBool("only_content") {
76+
prepareHomeTreeSideBarSwitch(ctx)
10177
tplName = tplRepoView
10278
}
10379

@@ -114,8 +90,7 @@ func RefBlame(ctx *context.Context) {
11490
}
11591

11692
bypassBlameIgnore, _ := strconv.ParseBool(ctx.FormString("bypass-blame-ignore"))
117-
118-
result, err := performBlame(ctx, ctx.Repo.Repository, ctx.Repo.Commit, fileName, bypassBlameIgnore)
93+
result, err := performBlame(ctx, ctx.Repo.Repository, ctx.Repo.Commit, ctx.Repo.TreePath, bypassBlameIgnore)
11994
if err != nil {
12095
ctx.NotFound(err)
12196
return
File renamed without changes.

templates/repo/view_content.tmpl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
{{template "repo/sub_menu" .}}
44
<div class="repo-button-row">
55
<div class="repo-button-row-left">
6-
{{if not $isTreePathRoot}}
7-
<button class="show-tree-sidebar-button ui compact basic button icon not-mobile {{if .RepoPreferences.ShowFileViewTreeSidebar}}tw-hidden{{end}}" title="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
8-
{{svg "octicon-sidebar-collapse"}}
9-
</button>
10-
{{end}}
11-
{{template "repo/home_branch_dropdown" (dict "ctxData" .)}}
12-
{{if and .CanCompareOrPull .RefFullName.IsBranch (not .Repository.IsArchived)}}
6+
{{if not $isTreePathRoot}}
7+
<button class="show-tree-sidebar-button ui compact basic button icon not-mobile {{if .RepoPreferences.ShowFileViewTreeSidebar}}tw-hidden{{end}}" title="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
8+
{{svg "octicon-sidebar-collapse"}}
9+
</button>
10+
{{end}}
11+
12+
{{template "repo/home_branch_dropdown" (dict "ctxData" .)}}
13+
14+
{{if and .CanCompareOrPull .RefFullName.IsBranch (not .Repository.IsArchived)}}
1315
{{$cmpBranch := ""}}
1416
{{if ne .Repository.ID .BaseRepo.ID}}
1517
{{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}}

0 commit comments

Comments
 (0)