Skip to content

Commit c07f823

Browse files
committed
fix lint
1 parent 8d4453e commit c07f823

2 files changed

Lines changed: 11 additions & 20 deletions

File tree

modules/git/catfile_batch_reader.go

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ type catFileBatchCommunicator struct {
2727
}
2828

2929
func (b *catFileBatchCommunicator) Close(err ...error) {
30-
if fn := b.closeFunc.Load(); fn != nil {
30+
if fn := b.closeFunc.Swap(nil); fn != nil {
3131
(*fn)(util.OptionalArg(err))
32-
b.closeFunc.Store(nil)
3332
}
3433
}
3534

3635
func (b *catFileBatchCommunicator) debugKill() (ret struct {
3736
beforeClose chan struct{}
3837
blockClose chan struct{}
3938
afterClose chan struct{}
40-
}) {
39+
},
40+
) {
4141
ret.beforeClose = make(chan struct{})
4242
ret.blockClose = make(chan struct{})
4343
ret.afterClose = make(chan struct{})
4444
oldCloseFunc := b.closeFunc.Load()
4545
b.closeFunc.Store(new(func(err error) {
46-
b.closeFunc.Store(oldCloseFunc)
46+
b.closeFunc.Store(nil)
4747
close(ret.beforeClose)
4848
<-ret.blockClose
4949
(*oldCloseFunc)(err)
@@ -53,28 +53,19 @@ func (b *catFileBatchCommunicator) debugKill() (ret struct {
5353
return ret
5454
}
5555

56-
// newCatFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
57-
func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Command) (ret *catFileBatchCommunicator) {
56+
// newCatFileBatch opens git cat-file --batch/--batch-check/--batch-command command and prepares the stdin/stdout pipes for communication.
57+
func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Command) *catFileBatchCommunicator {
5858
ctx, ctxCancel := context.WithCancelCause(ctx)
59-
60-
// We often want to feed the commits in order into cat-file --batch, followed by their trees and subtrees as necessary.
6159
stdinWriter, stdoutReader, stdPipeClose := cmdCatFile.MakeStdinStdoutPipe()
62-
closeFunc := func(err error) {
63-
ctxCancel(err)
64-
stdPipeClose()
65-
}
66-
return newCatFileBatchWithCloseFunc(ctx, repoPath, cmdCatFile, stdinWriter, stdoutReader, closeFunc)
67-
}
68-
69-
func newCatFileBatchWithCloseFunc(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Command,
70-
stdinWriter gitcmd.PipeWriter, stdoutReader gitcmd.PipeReader, closeFunc func(err error),
71-
) *catFileBatchCommunicator {
7260
ret := &catFileBatchCommunicator{
7361
debugGitCmd: cmdCatFile,
7462
reqWriter: stdinWriter,
7563
respReader: bufio.NewReaderSize(stdoutReader, 32*1024), // use a buffered reader for rich operations
7664
}
77-
ret.closeFunc.Store(&closeFunc)
65+
ret.closeFunc.Store(new(func(err error) {
66+
ctxCancel(err)
67+
stdPipeClose()
68+
}))
7869

7970
err := cmdCatFile.WithDir(repoPath).StartWithStderr(ctx)
8071
if err != nil {

modules/git/catfile_batch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func testCatFileBatch(t *testing.T) {
6565
}
6666
defer c.Close()
6767

68-
require.True(t, (errBeforePipeClose != nil) != (errAfterPipeClose != nil), "must set exactly one of the expected errors")
68+
require.NotEqual(t, errBeforePipeClose == nil, errAfterPipeClose == nil, "must set exactly one of the expected errors")
6969

7070
inceptor := c.debugKill()
7171
<-inceptor.beforeClose // wait for the command's Close to be called, the pipe is not closed yet

0 commit comments

Comments
 (0)