@@ -131,6 +131,9 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin
131
131
func renderViewPage (ctx * context.Context ) (* git.Repository , * git.TreeEntry ) {
132
132
wikiRepo , commit , err := findWikiRepoCommit (ctx )
133
133
if err != nil {
134
+ if wikiRepo != nil {
135
+ wikiRepo .Close ()
136
+ }
134
137
if ! git .IsErrNotExist (err ) {
135
138
ctx .ServerError ("GetBranchCommit" , err )
136
139
}
@@ -354,17 +357,14 @@ func Wiki(ctx *context.Context) {
354
357
}
355
358
356
359
wikiRepo , entry := renderViewPage (ctx )
357
- if ctx .Written () {
358
- if wikiRepo != nil {
359
- wikiRepo .Close ()
360
- }
361
- return
362
- }
363
360
defer func () {
364
361
if wikiRepo != nil {
365
362
wikiRepo .Close ()
366
363
}
367
364
}()
365
+ if ctx .Written () {
366
+ return
367
+ }
368
368
if entry == nil {
369
369
ctx .Data ["Title" ] = ctx .Tr ("repo.wiki" )
370
370
ctx .HTML (200 , tplWikiStart )
@@ -399,17 +399,15 @@ func WikiRevision(ctx *context.Context) {
399
399
}
400
400
401
401
wikiRepo , entry := renderRevisionPage (ctx )
402
- if ctx .Written () {
403
- if wikiRepo != nil {
404
- wikiRepo .Close ()
405
- }
406
- return
407
- }
408
402
defer func () {
409
403
if wikiRepo != nil {
410
404
wikiRepo .Close ()
411
405
}
412
406
}()
407
+
408
+ if ctx .Written () {
409
+ return
410
+ }
413
411
if entry == nil {
414
412
ctx .Data ["Title" ] = ctx .Tr ("repo.wiki" )
415
413
ctx .HTML (200 , tplWikiStart )
@@ -446,13 +444,14 @@ func WikiPages(ctx *context.Context) {
446
444
}
447
445
return
448
446
}
449
-
450
- entries , err := commit .ListEntries ()
451
- if err != nil {
447
+ defer func () {
452
448
if wikiRepo != nil {
453
449
wikiRepo .Close ()
454
450
}
451
+ }()
455
452
453
+ entries , err := commit .ListEntries ()
454
+ if err != nil {
456
455
ctx .ServerError ("ListEntries" , err )
457
456
return
458
457
}
@@ -463,10 +462,6 @@ func WikiPages(ctx *context.Context) {
463
462
}
464
463
c , err := wikiRepo .GetCommitByPath (entry .Name ())
465
464
if err != nil {
466
- if wikiRepo != nil {
467
- wikiRepo .Close ()
468
- }
469
-
470
465
ctx .ServerError ("GetCommit" , err )
471
466
return
472
467
}
@@ -475,10 +470,6 @@ func WikiPages(ctx *context.Context) {
475
470
if models .IsErrWikiInvalidFileName (err ) {
476
471
continue
477
472
}
478
- if wikiRepo != nil {
479
- wikiRepo .Close ()
480
- }
481
-
482
473
ctx .ServerError ("WikiFilenameToName" , err )
483
474
return
484
475
}
@@ -490,21 +481,25 @@ func WikiPages(ctx *context.Context) {
490
481
}
491
482
ctx .Data ["Pages" ] = pages
492
483
493
- defer func () {
494
- if wikiRepo != nil {
495
- wikiRepo .Close ()
496
- }
497
- }()
498
484
ctx .HTML (200 , tplWikiPages )
499
485
}
500
486
501
487
// WikiRaw outputs raw blob requested by user (image for example)
502
488
func WikiRaw (ctx * context.Context ) {
503
489
wikiRepo , commit , err := findWikiRepoCommit (ctx )
504
- if err != nil {
490
+ defer func () {
505
491
if wikiRepo != nil {
492
+ wikiRepo .Close ()
493
+ }
494
+ }()
495
+
496
+ if err != nil {
497
+ if git .IsErrNotExist (err ) {
498
+ ctx .NotFound ("findEntryForFile" , nil )
506
499
return
507
500
}
501
+ ctx .ServerError ("findEntryForfile" , err )
502
+ return
508
503
}
509
504
510
505
providedPath := ctx .Params ("*" )
@@ -520,9 +515,7 @@ func WikiRaw(ctx *context.Context) {
520
515
521
516
if entry == nil {
522
517
// Try to find a wiki page with that name
523
- if strings .HasSuffix (providedPath , ".md" ) {
524
- providedPath = providedPath [:len (providedPath )- 3 ]
525
- }
518
+ providedPath = strings .TrimSuffix (providedPath , ".md" )
526
519
527
520
wikiPath := wiki_service .NameToFilename (providedPath )
528
521
entry , err = findEntryForFile (commit , wikiPath )
0 commit comments