@@ -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
}
@@ -377,17 +389,14 @@ func Wiki(ctx *context.Context) {
377
389
}
378
390
379
391
wikiRepo , entry := renderViewPage (ctx )
380
- if ctx .Written () {
381
- if wikiRepo != nil {
382
- wikiRepo .Close ()
383
- }
384
- return
385
- }
386
392
defer func () {
387
393
if wikiRepo != nil {
388
394
wikiRepo .Close ()
389
395
}
390
396
}()
397
+ if ctx .Written () {
398
+ return
399
+ }
391
400
if entry == nil {
392
401
ctx .Data ["Title" ] = ctx .Tr ("repo.wiki" )
393
402
ctx .HTML (http .StatusOK , tplWikiStart )
@@ -422,17 +431,15 @@ func WikiRevision(ctx *context.Context) {
422
431
}
423
432
424
433
wikiRepo , entry := renderRevisionPage (ctx )
425
- if ctx .Written () {
426
- if wikiRepo != nil {
427
- wikiRepo .Close ()
428
- }
429
- return
430
- }
431
434
defer func () {
432
435
if wikiRepo != nil {
433
436
wikiRepo .Close ()
434
437
}
435
438
}()
439
+
440
+ if ctx .Written () {
441
+ return
442
+ }
436
443
if entry == nil {
437
444
ctx .Data ["Title" ] = ctx .Tr ("repo.wiki" )
438
445
ctx .HTML (http .StatusOK , tplWikiStart )
@@ -469,13 +476,14 @@ func WikiPages(ctx *context.Context) {
469
476
}
470
477
return
471
478
}
472
-
473
- entries , err := commit .ListEntries ()
474
- if err != nil {
479
+ defer func () {
475
480
if wikiRepo != nil {
476
481
wikiRepo .Close ()
477
482
}
483
+ }()
478
484
485
+ entries , err := commit .ListEntries ()
486
+ if err != nil {
479
487
ctx .ServerError ("ListEntries" , err )
480
488
return
481
489
}
@@ -486,10 +494,6 @@ func WikiPages(ctx *context.Context) {
486
494
}
487
495
c , err := wikiRepo .GetCommitByPath (entry .Name ())
488
496
if err != nil {
489
- if wikiRepo != nil {
490
- wikiRepo .Close ()
491
- }
492
-
493
497
ctx .ServerError ("GetCommit" , err )
494
498
return
495
499
}
@@ -498,10 +502,6 @@ func WikiPages(ctx *context.Context) {
498
502
if models .IsErrWikiInvalidFileName (err ) {
499
503
continue
500
504
}
501
- if wikiRepo != nil {
502
- wikiRepo .Close ()
503
- }
504
-
505
505
ctx .ServerError ("WikiFilenameToName" , err )
506
506
return
507
507
}
@@ -513,21 +513,25 @@ func WikiPages(ctx *context.Context) {
513
513
}
514
514
ctx .Data ["Pages" ] = pages
515
515
516
- defer func () {
517
- if wikiRepo != nil {
518
- wikiRepo .Close ()
519
- }
520
- }()
521
516
ctx .HTML (http .StatusOK , tplWikiPages )
522
517
}
523
518
524
519
// WikiRaw outputs raw blob requested by user (image for example)
525
520
func WikiRaw (ctx * context.Context ) {
526
521
wikiRepo , commit , err := findWikiRepoCommit (ctx )
527
- if err != nil {
522
+ defer func () {
528
523
if wikiRepo != nil {
524
+ wikiRepo .Close ()
525
+ }
526
+ }()
527
+
528
+ if err != nil {
529
+ if git .IsErrNotExist (err ) {
530
+ ctx .NotFound ("findEntryForFile" , nil )
529
531
return
530
532
}
533
+ ctx .ServerError ("findEntryForfile" , err )
534
+ return
531
535
}
532
536
533
537
providedPath := ctx .Params ("*" )
@@ -543,9 +547,7 @@ func WikiRaw(ctx *context.Context) {
543
547
544
548
if entry == nil {
545
549
// Try to find a wiki page with that name
546
- if strings .HasSuffix (providedPath , ".md" ) {
547
- providedPath = providedPath [:len (providedPath )- 3 ]
548
- }
550
+ providedPath = strings .TrimSuffix (providedPath , ".md" )
549
551
550
552
wikiPath := wiki_service .NameToFilename (providedPath )
551
553
entry , err = findEntryForFile (commit , wikiPath )
0 commit comments