6
6
package context
7
7
8
8
import (
9
+ "context"
9
10
"fmt"
10
11
"io/ioutil"
11
12
"net/url"
@@ -393,7 +394,7 @@ func RepoIDAssignment() func(ctx *Context) {
393
394
}
394
395
395
396
// RepoAssignment returns a middleware to handle repository assignment
396
- func RepoAssignment (ctx * Context ) {
397
+ func RepoAssignment (ctx * Context ) ( cancel context. CancelFunc ) {
397
398
var (
398
399
owner * models.User
399
400
err error
@@ -529,12 +530,12 @@ func RepoAssignment(ctx *Context) {
529
530
ctx .Repo .GitRepo = gitRepo
530
531
531
532
// We opened it, we should close it
532
- defer func () {
533
+ cancel = func () {
533
534
// If it's been set to nil then assume someone else has closed it.
534
535
if ctx .Repo .GitRepo != nil {
535
536
ctx .Repo .GitRepo .Close ()
536
537
}
537
- }()
538
+ }
538
539
539
540
// Stop at this point when the repo is empty.
540
541
if ctx .Repo .Repository .IsEmpty {
@@ -619,6 +620,7 @@ func RepoAssignment(ctx *Context) {
619
620
ctx .Data ["GoDocDirectory" ] = prefix + "{/dir}"
620
621
ctx .Data ["GoDocFile" ] = prefix + "{/dir}/{file}#L{line}"
621
622
}
623
+ return
622
624
}
623
625
624
626
// RepoRefType type of repo reference
@@ -643,7 +645,7 @@ const (
643
645
644
646
// RepoRef handles repository reference names when the ref name is not
645
647
// explicitly given
646
- func RepoRef () func (* Context ) {
648
+ func RepoRef () func (* Context ) context. CancelFunc {
647
649
// since no ref name is explicitly specified, ok to just use branch
648
650
return RepoRefByType (RepoRefBranch )
649
651
}
@@ -722,8 +724,8 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
722
724
723
725
// RepoRefByType handles repository reference name for a specific type
724
726
// 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 ) {
727
729
// Empty repository does not have reference information.
728
730
if ctx .Repo .Repository .IsEmpty {
729
731
return
@@ -742,12 +744,12 @@ func RepoRefByType(refType RepoRefType) func(*Context) {
742
744
return
743
745
}
744
746
// We opened it, we should close it
745
- defer func () {
747
+ cancel = func () {
746
748
// If it's been set to nil then assume someone else has closed it.
747
749
if ctx .Repo .GitRepo != nil {
748
750
ctx .Repo .GitRepo .Close ()
749
751
}
750
- }()
752
+ }
751
753
}
752
754
753
755
// Get default branch.
@@ -841,6 +843,7 @@ func RepoRefByType(refType RepoRefType) func(*Context) {
841
843
return
842
844
}
843
845
ctx .Data ["CommitsCount" ] = ctx .Repo .CommitsCount
846
+ return
844
847
}
845
848
}
846
849
0 commit comments