Skip to content

Commit b0e1124

Browse files
committed
rename c to ctx and remove unused code
1 parent 2575f1e commit b0e1124

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

routers/repo/branch.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ type Branch struct {
2525
IsProtected bool
2626
}
2727

28-
func loadBranches(c *context.Context) []*Branch {
29-
rawBranches, err := c.Repo.Repository.GetBranches()
28+
func loadBranches(ctx *context.Context) []*Branch {
29+
rawBranches, err := ctx.Repo.Repository.GetBranches()
3030
if err != nil {
31-
c.Handle(500, "GetBranches", err)
31+
ctx.Handle(500, "GetBranches", err)
3232
return nil
3333
}
3434

35-
protectBranches, err := c.Repo.Repository.GetProtectedBranches()
35+
protectBranches, err := ctx.Repo.Repository.GetProtectedBranches()
3636
if err != nil {
37-
c.Handle(500, "GetProtectBranchesByRepoID", err)
37+
ctx.Handle(500, "GetProtectedBranches", err)
3838
return nil
3939
}
4040

4141
branches := make([]*Branch, len(rawBranches))
4242
for i := range rawBranches {
4343
commit, err := rawBranches[i].GetCommit()
4444
if err != nil {
45-
c.Handle(500, "GetCommit", err)
45+
ctx.Handle(500, "GetCommit", err)
4646
return nil
4747
}
4848

@@ -59,17 +59,17 @@ func loadBranches(c *context.Context) []*Branch {
5959
}
6060
}
6161

62-
c.Data["AllowPullRequest"] = c.Repo.Repository.AllowsPulls()
62+
ctx.Data["AllowPullRequest"] = ctx.Repo.Repository.AllowsPulls()
6363
return branches
6464
}
6565

6666
// Branches render repository branch page
67-
func Branches(c *context.Context) {
68-
c.Data["Title"] = c.Tr("repo.git_branches")
69-
c.Data["PageIsBranchesOverview"] = true
67+
func Branches(ctx *context.Context) {
68+
ctx.Data["Title"] = ctx.Tr("repo.git_branches")
69+
ctx.Data["PageIsBranchesOverview"] = true
7070

71-
branches := loadBranches(c)
72-
if c.Written() {
71+
branches := loadBranches(ctx)
72+
if ctx.Written() {
7373
return
7474
}
7575

@@ -78,64 +78,64 @@ func Branches(c *context.Context) {
7878
staleBranches := make([]*Branch, 0, 3)
7979
for i := range branches {
8080
switch {
81-
case branches[i].Name == c.Repo.BranchName:
82-
c.Data["DefaultBranch"] = branches[i]
81+
case branches[i].Name == ctx.Repo.BranchName:
82+
ctx.Data["DefaultBranch"] = branches[i]
8383
case branches[i].Commit.Committer.When.Add(30 * 24 * time.Hour).After(now): // 30 days
8484
activeBranches = append(activeBranches, branches[i])
8585
case branches[i].Commit.Committer.When.Add(3 * 30 * 24 * time.Hour).Before(now): // 90 days
8686
staleBranches = append(staleBranches, branches[i])
8787
}
8888
}
8989

90-
c.Data["ActiveBranches"] = activeBranches
91-
c.Data["StaleBranches"] = staleBranches
92-
c.HTML(200, tplBranchOverview)
90+
ctx.Data["ActiveBranches"] = activeBranches
91+
ctx.Data["StaleBranches"] = staleBranches
92+
ctx.HTML(200, tplBranchOverview)
9393
}
9494

9595
// AllBranches all branches UI
96-
func AllBranches(c *context.Context) {
97-
c.Data["Title"] = c.Tr("repo.git_branches")
98-
c.Data["PageIsBranchesAll"] = true
96+
func AllBranches(ctx *context.Context) {
97+
ctx.Data["Title"] = ctx.Tr("repo.git_branches")
98+
ctx.Data["PageIsBranchesAll"] = true
9999

100-
branches := loadBranches(c)
101-
if c.Written() {
100+
branches := loadBranches(ctx)
101+
if ctx.Written() {
102102
return
103103
}
104-
c.Data["Branches"] = branches
104+
ctx.Data["Branches"] = branches
105105

106-
c.HTML(200, tplBranchAll)
106+
ctx.HTML(200, tplBranchAll)
107107
}
108108

109109
// DeleteBranchPost executes branch deletation operation
110-
func DeleteBranchPost(c *context.Context) {
111-
branchName := c.Params("*")
112-
commitID := c.Query("commit")
110+
func DeleteBranchPost(ctx *context.Context) {
111+
branchName := ctx.Params("*")
112+
commitID := ctx.Query("commit")
113113

114114
defer func() {
115-
redirectTo := c.Query("redirect_to")
115+
redirectTo := ctx.Query("redirect_to")
116116
if len(redirectTo) == 0 {
117-
redirectTo = c.Repo.RepoLink
117+
redirectTo = ctx.Repo.RepoLink
118118
}
119-
c.Redirect(redirectTo)
119+
ctx.Redirect(redirectTo)
120120
}()
121121

122-
if !c.Repo.GitRepo.IsBranchExist(branchName) {
122+
if !ctx.Repo.GitRepo.IsBranchExist(branchName) {
123123
return
124124
}
125125
if len(commitID) > 0 {
126-
branchCommitID, err := c.Repo.GitRepo.GetBranchCommitID(branchName)
126+
branchCommitID, err := ctx.Repo.GitRepo.GetBranchCommitID(branchName)
127127
if err != nil {
128128
log.Error(2, "GetBranchCommitID: %v", err)
129129
return
130130
}
131131

132132
if branchCommitID != commitID {
133-
c.Flash.Error(c.Tr("repo.pulls.delete_branch_has_new_commits"))
133+
ctx.Flash.Error(ctx.Tr("repo.pulls.delete_branch_has_new_commits"))
134134
return
135135
}
136136
}
137137

138-
if err := c.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
138+
if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
139139
Force: true,
140140
}); err != nil {
141141
log.Error(2, "DeleteBranch '%s': %v", branchName, err)

routers/routes/routes.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,7 @@ func RegisterRoutes(m *macaron.Macaron) {
583583
m.Get("", repo.Branches)
584584
m.Get("/all", repo.AllBranches)
585585
m.Post("/delete/*", reqSignIn, reqRepoWriter, repo.DeleteBranchPost)
586-
}, repo.MustBeNotBare, func(c *context.Context) {
587-
c.Data["PageIsViewFiles"] = true
588-
}, context.CheckUnit(models.UnitTypeCode))
586+
}, repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode))
589587

590588
m.Group("/wiki", func() {
591589
m.Get("/?:page", repo.Uncyclo)

0 commit comments

Comments
 (0)