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