@@ -135,6 +135,9 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin
135
135
func renderViewPage (ctx * context.Context ) (* git.Repository , * git.TreeEntry ) {
136
136
wikiRepo , commit , err := findWikiRepoCommit (ctx )
137
137
if err != nil {
138
+ if wikiRepo != nil {
139
+ wikiRepo .Close ()
140
+ }
138
141
if ! git .IsErrNotExist (err ) {
139
142
ctx .ServerError ("GetBranchCommit" , err )
140
143
}
@@ -222,13 +225,19 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
222
225
223
226
var buf strings.Builder
224
227
if err := markdown .Render (rctx , bytes .NewReader (data ), & buf ); err != nil {
228
+ if wikiRepo != nil {
229
+ wikiRepo .Close ()
230
+ }
225
231
ctx .ServerError ("Render" , err )
226
232
return nil , nil
227
233
}
228
234
ctx .Data ["content" ] = buf .String ()
229
235
230
236
buf .Reset ()
231
237
if err := markdown .Render (rctx , bytes .NewReader (sidebarContent ), & buf ); err != nil {
238
+ if wikiRepo != nil {
239
+ wikiRepo .Close ()
240
+ }
232
241
ctx .ServerError ("Render" , err )
233
242
return nil , nil
234
243
}
@@ -237,6 +246,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
237
246
238
247
buf .Reset ()
239
248
if err := markdown .Render (rctx , bytes .NewReader (footerContent ), & buf ); err != nil {
249
+ if wikiRepo != nil {
250
+ wikiRepo .Close ()
251
+ }
240
252
ctx .ServerError ("Render" , err )
241
253
return nil , nil
242
254
}
@@ -380,17 +392,14 @@ func Wiki(ctx *context.Context) {
380
392
}
381
393
382
394
wikiRepo , entry := renderViewPage (ctx )
383
- if ctx .Written () {
384
- if wikiRepo != nil {
385
- wikiRepo .Close ()
386
- }
387
- return
388
- }
389
395
defer func () {
390
396
if wikiRepo != nil {
391
397
wikiRepo .Close ()
392
398
}
393
399
}()
400
+ if ctx .Written () {
401
+ return
402
+ }
394
403
if entry == nil {
395
404
ctx .Data ["Title" ] = ctx .Tr ("repo.wiki" )
396
405
ctx .HTML (http .StatusOK , tplWikiStart )
@@ -425,17 +434,15 @@ func WikiRevision(ctx *context.Context) {
425
434
}
426
435
427
436
wikiRepo , entry := renderRevisionPage (ctx )
428
- if ctx .Written () {
429
- if wikiRepo != nil {
430
- wikiRepo .Close ()
431
- }
432
- return
433
- }
434
437
defer func () {
435
438
if wikiRepo != nil {
436
439
wikiRepo .Close ()
437
440
}
438
441
}()
442
+
443
+ if ctx .Written () {
444
+ return
445
+ }
439
446
if entry == nil {
440
447
ctx .Data ["Title" ] = ctx .Tr ("repo.wiki" )
441
448
ctx .HTML (http .StatusOK , tplWikiStart )
@@ -472,13 +479,14 @@ func WikiPages(ctx *context.Context) {
472
479
}
473
480
return
474
481
}
475
-
476
- entries , err := commit .ListEntries ()
477
- if err != nil {
482
+ defer func () {
478
483
if wikiRepo != nil {
479
484
wikiRepo .Close ()
480
485
}
486
+ }()
481
487
488
+ entries , err := commit .ListEntries ()
489
+ if err != nil {
482
490
ctx .ServerError ("ListEntries" , err )
483
491
return
484
492
}
@@ -489,10 +497,6 @@ func WikiPages(ctx *context.Context) {
489
497
}
490
498
c , err := wikiRepo .GetCommitByPath (entry .Name ())
491
499
if err != nil {
492
- if wikiRepo != nil {
493
- wikiRepo .Close ()
494
- }
495
-
496
500
ctx .ServerError ("GetCommit" , err )
497
501
return
498
502
}
@@ -501,10 +505,6 @@ func WikiPages(ctx *context.Context) {
501
505
if models .IsErrWikiInvalidFileName (err ) {
502
506
continue
503
507
}
504
- if wikiRepo != nil {
505
- wikiRepo .Close ()
506
- }
507
-
508
508
ctx .ServerError ("WikiFilenameToName" , err )
509
509
return
510
510
}
@@ -516,21 +516,25 @@ func WikiPages(ctx *context.Context) {
516
516
}
517
517
ctx .Data ["Pages" ] = pages
518
518
519
- defer func () {
520
- if wikiRepo != nil {
521
- wikiRepo .Close ()
522
- }
523
- }()
524
519
ctx .HTML (http .StatusOK , tplWikiPages )
525
520
}
526
521
527
522
// WikiRaw outputs raw blob requested by user (image for example)
528
523
func WikiRaw (ctx * context.Context ) {
529
524
wikiRepo , commit , err := findWikiRepoCommit (ctx )
530
- if err != nil {
525
+ defer func () {
531
526
if wikiRepo != nil {
527
+ wikiRepo .Close ()
528
+ }
529
+ }()
530
+
531
+ if err != nil {
532
+ if git .IsErrNotExist (err ) {
533
+ ctx .NotFound ("findEntryForFile" , nil )
532
534
return
533
535
}
536
+ ctx .ServerError ("findEntryForfile" , err )
537
+ return
534
538
}
535
539
536
540
providedPath := ctx .Params ("*" )
@@ -546,9 +550,7 @@ func WikiRaw(ctx *context.Context) {
546
550
547
551
if entry == nil {
548
552
// Try to find a wiki page with that name
549
- if strings .HasSuffix (providedPath , ".md" ) {
550
- providedPath = providedPath [:len (providedPath )- 3 ]
551
- }
553
+ providedPath = strings .TrimSuffix (providedPath , ".md" )
552
554
553
555
wikiPath := wiki_service .NameToFilename (providedPath )
554
556
entry , err = findEntryForFile (commit , wikiPath )
0 commit comments