Skip to content

Commit 63a9836

Browse files
committed
Fix bug
1 parent d323f5f commit 63a9836

File tree

1 file changed

+22
-45
lines changed

1 file changed

+22
-45
lines changed

modules/git/attribute/batch.go

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package attribute
66
import (
77
"bytes"
88
"context"
9-
"errors"
109
"fmt"
1110
"io"
1211
"os"
@@ -39,70 +38,48 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes ...string)
3938
if len(attributes) == 0 {
4039
attributes = LinguistAttributes
4140
}
41+
cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes)
42+
if err != nil {
43+
cancel()
44+
return nil, err
45+
}
46+
cmd.AddArguments("--stdin")
47+
4248
checker := &BatchChecker{
4349
Attributes: attributes,
4450
Repo: repo,
4551
Treeish: treeish,
4652
ctx: ctx,
47-
cancel: cancel,
53+
cancel: func() {
54+
cancel()
55+
cleanup()
56+
},
57+
cmd: cmd,
58+
env: envs,
4859
}
4960

50-
if err := checker.init(); err != nil {
51-
log.Error("Unable to open attribute checker for commit %s, error: %v", treeish, err)
52-
checker.Close()
61+
checker.stdinReader, checker.stdinWriter, err = os.Pipe()
62+
if err != nil {
63+
checker.cancel()
5364
return nil, err
5465
}
5566

67+
lw := new(nulSeparatedAttributeWriter)
68+
lw.attributes = make(chan attributeTriple, 5)
69+
lw.closed = make(chan struct{})
70+
checker.stdOut = lw
71+
5672
go func() {
5773
err := checker.run(ctx)
5874
if err != nil && !git.IsErrCanceledOrKilled(err) {
5975
log.Error("Attribute checker for commit %s exits with error: %v", treeish, err)
6076
}
61-
cancel()
77+
checker.cancel()
6278
}()
6379

6480
return checker, nil
6581
}
6682

67-
// init initializes the AttributeChecker
68-
func (c *BatchChecker) init() error {
69-
if len(c.Attributes) == 0 {
70-
lw := new(nulSeparatedAttributeWriter)
71-
lw.attributes = make(chan attributeTriple)
72-
lw.closed = make(chan struct{})
73-
74-
c.stdOut = lw
75-
c.stdOut.Close()
76-
return errors.New("no provided Attributes to check")
77-
}
78-
79-
cmd, envs, cancel, err := checkAttrCommand(c.Repo, c.Treeish, nil, c.Attributes)
80-
if err != nil {
81-
c.cancel()
82-
return err
83-
}
84-
c.cmd = cmd
85-
c.env = envs
86-
c.cancel = func() {
87-
cancel()
88-
c.cancel()
89-
}
90-
91-
c.cmd.AddArguments("--stdin")
92-
93-
c.stdinReader, c.stdinWriter, err = os.Pipe()
94-
if err != nil {
95-
c.cancel()
96-
return err
97-
}
98-
99-
lw := new(nulSeparatedAttributeWriter)
100-
lw.attributes = make(chan attributeTriple, 5)
101-
lw.closed = make(chan struct{})
102-
c.stdOut = lw
103-
return nil
104-
}
105-
10683
func (c *BatchChecker) run(ctx context.Context) error {
10784
defer func() {
10885
_ = c.stdinReader.Close()

0 commit comments

Comments
 (0)