@@ -27,19 +27,17 @@ type BatchChecker struct {
2727}
2828
2929// NewBatchChecker creates a check attribute reader for the current repository and provided commit ID
30- func NewBatchChecker (repo * git.Repository , treeish string , attributes ... string ) (* BatchChecker , error ) {
30+ func NewBatchChecker (repo * git.Repository , treeish string , attributes ... string ) (checker * BatchChecker , returnedErr error ) {
3131 ctx , cancel := context .WithCancel (repo .Ctx )
32- if len (attributes ) == 0 {
33- attributes = LinguistAttributes
34- }
3532 cmd , envs , cleanup , err := checkAttrCommand (repo , treeish , nil , attributes )
3633 if err != nil {
3734 cancel ()
3835 return nil , err
3936 }
37+
4038 cmd .AddArguments ("--stdin" )
4139
42- checker : = & BatchChecker {
40+ checker = & BatchChecker {
4341 attributesNum : len (attributes ),
4442 repo : repo ,
4543 ctx : ctx ,
@@ -49,16 +47,20 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes ...string)
4947 cleanup ()
5048 },
5149 }
50+ defer func () {
51+ if returnedErr != nil {
52+ checker .cancel ()
53+ }
54+ }()
5255
5356 stdinReader , stdinWriter , err := os .Pipe ()
5457 if err != nil {
55- checker .cancel ()
5658 return nil , err
5759 }
5860 checker .stdinWriter = stdinWriter
5961
6062 lw := new (nulSeparatedAttributeWriter )
61- lw .attributes = make (chan attributeTriple , 5 )
63+ lw .attributes = make (chan attributeTriple , len ( attributes ) )
6264 lw .closed = make (chan struct {})
6365 checker .stdOut = lw
6466
@@ -124,10 +126,7 @@ func (c *BatchChecker) CheckPath(path string) (rs Attributes, err error) {
124126 for i := 0 ; i < c .attributesNum ; i ++ {
125127 select {
126128 case <- time .After (5 * time .Second ):
127- // There is a strange "hang" problem in gitdiff.GetDiff -> CheckPath
128- // So add a timeout here to mitigate the problem, and output more logs for debug purpose
129- // In real world, if CheckPath runs long than seconds, it blocks the end user's operation,
130- // and at the moment the CheckPath result is not so important, so we can just ignore it.
129+ // there is no "hang" problem now. This code is just used to catch other potential problems.
131130 return nil , reportTimeout ()
132131 case attr , ok := <- c .stdOut .ReadAttribute ():
133132 if ! ok {
0 commit comments