Skip to content

Commit

Permalink
remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 15, 2025
1 parent 2d644fb commit bb82979
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
13 changes: 1 addition & 12 deletions routers/web/repo/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,7 @@ func RefBlame(ctx *context.Context) {
return
}

showFileViewTreeSidebar := true
if ctx.Doer != nil {
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar, "true")
if err != nil {
log.Error("GetUserSetting: %v", err)
} else {
showFileViewTreeSidebar, _ = strconv.ParseBool(v)
}
}
ctx.Data["RepoPreferences"] = &preferencesForm{
ShowFileViewTreeSidebar: showFileViewTreeSidebar,
}
prepareHomeTreeSideBarSwitch(ctx)

branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
treeLink := branchLink
Expand Down
28 changes: 16 additions & 12 deletions routers/web/repo/view_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ func handleRepoHomeFeed(ctx *context.Context) bool {
return false
}

func prepareHomeTreeSideBarSwitch(ctx *context.Context) {
showFileViewTreeSidebar := true
if ctx.Doer != nil {
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar, "true")
if err != nil {
log.Error("GetUserSetting: %v", err)
} else {
showFileViewTreeSidebar, _ = strconv.ParseBool(v)
}
}
ctx.Data["RepoPreferences"] = &preferencesForm{
ShowFileViewTreeSidebar: showFileViewTreeSidebar,
}
}

// Home render repository home page
func Home(ctx *context.Context) {
if handleRepoHomeFeed(ctx) {
Expand All @@ -325,18 +340,7 @@ func Home(ctx *context.Context) {
return
}

showFileViewTreeSidebar := true
if ctx.Doer != nil {
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar, "true")
if err != nil {
log.Error("GetUserSetting: %v", err)
} else {
showFileViewTreeSidebar, _ = strconv.ParseBool(v)
}
}
ctx.Data["RepoPreferences"] = &preferencesForm{
ShowFileViewTreeSidebar: showFileViewTreeSidebar,
}
prepareHomeTreeSideBarSwitch(ctx)

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

0 comments on commit bb82979

Please sign in to comment.