Skip to content

Commit bb82979

Browse files
committed
remove duplicated code
1 parent 2d644fb commit bb82979

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

routers/web/repo/blame.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,7 @@ func RefBlame(ctx *context.Context) {
4646
return
4747
}
4848

49-
showFileViewTreeSidebar := true
50-
if ctx.Doer != nil {
51-
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar, "true")
52-
if err != nil {
53-
log.Error("GetUserSetting: %v", err)
54-
} else {
55-
showFileViewTreeSidebar, _ = strconv.ParseBool(v)
56-
}
57-
}
58-
ctx.Data["RepoPreferences"] = &preferencesForm{
59-
ShowFileViewTreeSidebar: showFileViewTreeSidebar,
60-
}
49+
prepareHomeTreeSideBarSwitch(ctx)
6150

6251
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
6352
treeLink := branchLink

routers/web/repo/view_home.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,21 @@ func handleRepoHomeFeed(ctx *context.Context) bool {
312312
return false
313313
}
314314

315+
func prepareHomeTreeSideBarSwitch(ctx *context.Context) {
316+
showFileViewTreeSidebar := true
317+
if ctx.Doer != nil {
318+
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar, "true")
319+
if err != nil {
320+
log.Error("GetUserSetting: %v", err)
321+
} else {
322+
showFileViewTreeSidebar, _ = strconv.ParseBool(v)
323+
}
324+
}
325+
ctx.Data["RepoPreferences"] = &preferencesForm{
326+
ShowFileViewTreeSidebar: showFileViewTreeSidebar,
327+
}
328+
}
329+
315330
// Home render repository home page
316331
func Home(ctx *context.Context) {
317332
if handleRepoHomeFeed(ctx) {
@@ -325,18 +340,7 @@ func Home(ctx *context.Context) {
325340
return
326341
}
327342

328-
showFileViewTreeSidebar := true
329-
if ctx.Doer != nil {
330-
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar, "true")
331-
if err != nil {
332-
log.Error("GetUserSetting: %v", err)
333-
} else {
334-
showFileViewTreeSidebar, _ = strconv.ParseBool(v)
335-
}
336-
}
337-
ctx.Data["RepoPreferences"] = &preferencesForm{
338-
ShowFileViewTreeSidebar: showFileViewTreeSidebar,
339-
}
343+
prepareHomeTreeSideBarSwitch(ctx)
340344

341345
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
342346
if len(ctx.Repo.Repository.Description) > 0 {

0 commit comments

Comments
 (0)