@@ -58,12 +58,14 @@ func Branches(ctx *context.Context) {
58
58
page = 1
59
59
}
60
60
61
- pageSize := ctx .QueryInt ("limit" )
62
- if pageSize <= 0 || pageSize > git .BranchesRangeSize {
63
- pageSize = git .BranchesRangeSize
61
+ limit := ctx .QueryInt ("limit" )
62
+ if limit <= 0 || limit > git .BranchesRangeSize {
63
+ limit = git .BranchesRangeSize
64
64
}
65
65
66
- branches , branchesCount := loadBranches (ctx , page , pageSize )
66
+ skip := (page - 1 ) * limit
67
+ log .Info ("Branches: skip: %d limit: %d" , skip , limit )
68
+ branches , branchesCount := loadBranches (ctx , skip , limit )
67
69
if ctx .Written () {
68
70
return
69
71
}
@@ -80,6 +82,7 @@ func DeleteBranchPost(ctx *context.Context) {
80
82
defer redirect (ctx )
81
83
branchName := ctx .Query ("name" )
82
84
if branchName == ctx .Repo .Repository .DefaultBranch {
85
+ log .Warn ("DeleteBranch: Can't delete default branch '%s'" , branchName )
83
86
ctx .Flash .Error (ctx .Tr ("repo.branch.default_deletion_failed" , branchName ))
84
87
return
85
88
}
@@ -92,16 +95,19 @@ func DeleteBranchPost(ctx *context.Context) {
92
95
}
93
96
94
97
if isProtected {
98
+ log .Warn ("DeleteBranch: Can't delete protected branch '%s'" , branchName )
95
99
ctx .Flash .Error (ctx .Tr ("repo.branch.protected_deletion_failed" , branchName ))
96
100
return
97
101
}
98
102
99
- if ! ctx .Repo .GitRepo .IsBranchExist (branchName ) || branchName == ctx .Repo .Repository .DefaultBranch {
103
+ if ! ctx .Repo .GitRepo .IsBranchExist (branchName ) {
104
+ log .Warn ("DeleteBranch: Can't delete non existing branch '%s'" , branchName )
100
105
ctx .Flash .Error (ctx .Tr ("repo.branch.deletion_failed" , branchName ))
101
106
return
102
107
}
103
108
104
109
if err := deleteBranch (ctx , branchName ); err != nil {
110
+ log .Error ("DeleteBranch: %v" , err )
105
111
ctx .Flash .Error (ctx .Tr ("repo.branch.deletion_failed" , branchName ))
106
112
return
107
113
}
@@ -129,10 +135,11 @@ func RestoreBranchPost(ctx *context.Context) {
129
135
Env : models .PushingEnvironment (ctx .User , ctx .Repo .Repository ),
130
136
}); err != nil {
131
137
if strings .Contains (err .Error (), "already exists" ) {
138
+ log .Warn ("RestoreBranch: Can't restore branch '%s', since one with same name already exist" , deletedBranch .Name )
132
139
ctx .Flash .Error (ctx .Tr ("repo.branch.already_exists" , deletedBranch .Name ))
133
140
return
134
141
}
135
- log .Error ("CreateBranch: %v" , err )
142
+ log .Error ("RestoreBranch: CreateBranch: %v" , err )
136
143
ctx .Flash .Error (ctx .Tr ("repo.branch.restore_failed" , deletedBranch .Name ))
137
144
return
138
145
}
@@ -148,7 +155,7 @@ func RestoreBranchPost(ctx *context.Context) {
148
155
RepoUserName : ctx .Repo .Owner .Name ,
149
156
RepoName : ctx .Repo .Repository .Name ,
150
157
}); err != nil {
151
- log .Error ("Update: %v" , err )
158
+ log .Error ("RestoreBranch: Update: %v" , err )
152
159
}
153
160
154
161
ctx .Flash .Success (ctx .Tr ("repo.branch.restore_success" , deletedBranch .Name ))
@@ -197,17 +204,17 @@ func deleteBranch(ctx *context.Context, branchName string) error {
197
204
198
205
// loadBranches loads branches from the repository limited by page & pageSize.
199
206
// NOTE: May write to context on error.
200
- func loadBranches (ctx * context.Context , page , pageSize int ) ([]* Branch , int ) {
207
+ func loadBranches (ctx * context.Context , skip , limit int ) ([]* Branch , int ) {
201
208
defaultBranch , err := repo_module .GetBranch (ctx .Repo .Repository , ctx .Repo .Repository .DefaultBranch )
202
209
if err != nil {
210
+ log .Error ("loadBranches: get default branch: %v" , err )
203
211
ctx .ServerError ("GetDefaultBranch" , err )
204
212
return nil , 0
205
213
}
206
214
207
- skip , _ := models.ListOptions {Page : page , PageSize : pageSize }.GetStartEnd ()
208
-
209
- rawBranches , totalNumOfBranches , err := repo_module .GetBranches (ctx .Repo .Repository , skip , pageSize )
215
+ rawBranches , totalNumOfBranches , err := repo_module .GetBranches (ctx .Repo .Repository , skip , limit )
210
216
if err != nil {
217
+ log .Error ("GetBranches: %v" , err )
211
218
ctx .ServerError ("GetBranches" , err )
212
219
return nil , 0
213
220
}
@@ -226,7 +233,7 @@ func loadBranches(ctx *context.Context, page, pageSize int) ([]*Branch, int) {
226
233
227
234
var branches []* Branch
228
235
for i := range rawBranches {
229
- if strings . EqualFold ( rawBranches [i ].Name , ctx . Repo . Repository . DefaultBranch ) {
236
+ if rawBranches [i ].Name == defaultBranch . Name {
230
237
// Skip default branch
231
238
continue
232
239
}
@@ -240,6 +247,7 @@ func loadBranches(ctx *context.Context, page, pageSize int) ([]*Branch, int) {
240
247
}
241
248
242
249
// Always add the default branch
250
+ log .Info ("loadOneBranch: load default: '%s'" , defaultBranch .Name )
243
251
branches = append (branches , loadOneBranch (ctx , defaultBranch , protectedBranches , repoIDToRepo , repoIDToGitRepo ))
244
252
245
253
if ctx .Repo .CanWrite (models .UnitTypeCode ) {
@@ -257,6 +265,7 @@ func loadBranches(ctx *context.Context, page, pageSize int) ([]*Branch, int) {
257
265
func loadOneBranch (ctx * context.Context , rawBranch * git.Branch , protectedBranches []* models.ProtectedBranch ,
258
266
repoIDToRepo map [int64 ]* models.Repository ,
259
267
repoIDToGitRepo map [int64 ]* git.Repository ) * Branch {
268
+ log .Info ("loadOneBranch: '%s'" , rawBranch .Name )
260
269
261
270
commit , err := rawBranch .GetCommit ()
262
271
if err != nil {
0 commit comments