66package context
77
88import (
9+ "context"
910 "fmt"
1011 "io/ioutil"
1112 "net/url"
@@ -393,7 +394,7 @@ func RepoIDAssignment() func(ctx *Context) {
393394}
394395
395396// RepoAssignment returns a middleware to handle repository assignment
396- func RepoAssignment (ctx * Context ) {
397+ func RepoAssignment (ctx * Context ) ( cancel context. CancelFunc ) {
397398 var (
398399 owner * models.User
399400 err error
@@ -529,12 +530,12 @@ func RepoAssignment(ctx *Context) {
529530 ctx .Repo .GitRepo = gitRepo
530531
531532 // We opened it, we should close it
532- defer func () {
533+ cancel = func () {
533534 // If it's been set to nil then assume someone else has closed it.
534535 if ctx .Repo .GitRepo != nil {
535536 ctx .Repo .GitRepo .Close ()
536537 }
537- }()
538+ }
538539
539540 // Stop at this point when the repo is empty.
540541 if ctx .Repo .Repository .IsEmpty {
@@ -619,6 +620,7 @@ func RepoAssignment(ctx *Context) {
619620 ctx .Data ["GoDocDirectory" ] = prefix + "{/dir}"
620621 ctx .Data ["GoDocFile" ] = prefix + "{/dir}/{file}#L{line}"
621622 }
623+ return
622624}
623625
624626// RepoRefType type of repo reference
@@ -643,7 +645,7 @@ const (
643645
644646// RepoRef handles repository reference names when the ref name is not
645647// explicitly given
646- func RepoRef () func (* Context ) {
648+ func RepoRef () func (* Context ) context. CancelFunc {
647649 // since no ref name is explicitly specified, ok to just use branch
648650 return RepoRefByType (RepoRefBranch )
649651}
@@ -722,8 +724,8 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
722724
723725// RepoRefByType handles repository reference name for a specific type
724726// of repository reference
725- func RepoRefByType (refType RepoRefType ) func (* Context ) {
726- return func (ctx * Context ) {
727+ func RepoRefByType (refType RepoRefType ) func (* Context ) context. CancelFunc {
728+ return func (ctx * Context ) ( cancel context. CancelFunc ) {
727729 // Empty repository does not have reference information.
728730 if ctx .Repo .Repository .IsEmpty {
729731 return
@@ -742,12 +744,12 @@ func RepoRefByType(refType RepoRefType) func(*Context) {
742744 return
743745 }
744746 // We opened it, we should close it
745- defer func () {
747+ cancel = func () {
746748 // If it's been set to nil then assume someone else has closed it.
747749 if ctx .Repo .GitRepo != nil {
748750 ctx .Repo .GitRepo .Close ()
749751 }
750- }()
752+ }
751753 }
752754
753755 // Get default branch.
@@ -841,6 +843,7 @@ func RepoRefByType(refType RepoRefType) func(*Context) {
841843 return
842844 }
843845 ctx .Data ["CommitsCount" ] = ctx .Repo .CommitsCount
846+ return
844847 }
845848}
846849
0 commit comments