@ -146,6 +146,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
// Get page list.
entries , err := commit . ListEntries ( )
if err != nil {
if wikiRepo != nil {
wikiRepo . Close ( )
}
ctx . ServerError ( "ListEntries" , err )
return nil , nil
}
@ -159,6 +162,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
if models . IsErrWikiInvalidFileName ( err ) {
continue
}
if wikiRepo != nil {
wikiRepo . Close ( )
}
ctx . ServerError ( "WikiFilenameToName" , err )
return nil , nil
} else if wikiName == "_Sidebar" || wikiName == "_Footer" {
@ -188,16 +194,25 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
ctx . Redirect ( ctx . Repo . RepoLink + "/wiki/_pages" )
}
if entry == nil || ctx . Written ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
return nil , nil
}
sidebarContent , _ , _ , _ := wikiContentsByName ( ctx , commit , "_Sidebar" )
if ctx . Written ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
return nil , nil
}
footerContent , _ , _ , _ := wikiContentsByName ( ctx , commit , "_Footer" )
if ctx . Written ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
return nil , nil
}
@ -218,6 +233,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
func renderRevisionPage ( ctx * context . Context ) ( * git . Repository , * git . TreeEntry ) {
wikiRepo , commit , err := findWikiRepoCommit ( ctx )
if err != nil {
if wikiRepo != nil {
wikiRepo . Close ( )
}
if ! git . IsErrNotExist ( err ) {
ctx . ServerError ( "GetBranchCommit" , err )
}
@ -241,6 +259,9 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
ctx . Redirect ( ctx . Repo . RepoLink + "/wiki/_pages" )
}
if entry == nil || ctx . Written ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
return nil , nil
}
@ -263,6 +284,9 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
// get Commit Count
commitsHistory , err := wikiRepo . CommitsByFileAndRangeNoFollow ( "master" , pageFilename , page )
if err != nil {
if wikiRepo != nil {
wikiRepo . Close ( )
}
ctx . ServerError ( "CommitsByFileAndRangeNoFollow" , err )
return nil , nil
}
@ -279,13 +303,21 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
}
func renderEditPage ( ctx * context . Context ) {
_ , commit , err := findWikiRepoCommit ( ctx )
wikiRepo , commit , err := findWikiRepoCommit ( ctx )
if err != nil {
if wikiRepo != nil {
wikiRepo . Close ( )
}
if ! git . IsErrNotExist ( err ) {
ctx . ServerError ( "GetBranchCommit" , err )
}
return
}
defer func ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
} ( )
// get requested pagename
pageName := models . NormalizeWikiName ( ctx . Params ( ":page" ) )
@ -327,8 +359,16 @@ func Wiki(ctx *context.Context) {
wikiRepo , entry := renderViewPage ( ctx )
if ctx . Written ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
return
}
defer func ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
} ( )
if entry == nil {
ctx . Data [ "Title" ] = ctx . Tr ( "repo.wiki" )
ctx . HTML ( 200 , tplWikiStart )
@ -364,8 +404,16 @@ func WikiRevision(ctx *context.Context) {
wikiRepo , entry := renderRevisionPage ( ctx )
if ctx . Written ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
return
}
defer func ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
} ( )
if entry == nil {
ctx . Data [ "Title" ] = ctx . Tr ( "repo.wiki" )
ctx . HTML ( 200 , tplWikiStart )
@ -397,11 +445,18 @@ func WikiPages(ctx *context.Context) {
wikiRepo , commit , err := findWikiRepoCommit ( ctx )
if err != nil {
if wikiRepo != nil {
wikiRepo . Close ( )
}
return
}
entries , err := commit . ListEntries ( )
if err != nil {
if wikiRepo != nil {
wikiRepo . Close ( )
}
ctx . ServerError ( "ListEntries" , err )
return
}
@ -412,6 +467,10 @@ func WikiPages(ctx *context.Context) {
}
c , err := wikiRepo . GetCommitByPath ( entry . Name ( ) )
if err != nil {
if wikiRepo != nil {
wikiRepo . Close ( )
}
ctx . ServerError ( "GetCommit" , err )
return
}
@ -420,6 +479,10 @@ func WikiPages(ctx *context.Context) {
if models . IsErrWikiInvalidFileName ( err ) {
continue
}
if wikiRepo != nil {
wikiRepo . Close ( )
}
ctx . ServerError ( "WikiFilenameToName" , err )
return
}
@ -431,6 +494,11 @@ func WikiPages(ctx *context.Context) {
}
ctx . Data [ "Pages" ] = pages
defer func ( ) {
if wikiRepo != nil {
wikiRepo . Close ( )
}
} ( )
ctx . HTML ( 200 , tplWikiPages )
}