From a7969aef2c0d597ca97f060836233f21b2b68bc6 Mon Sep 17 00:00:00 2001 From: Andrew Savinykh <658865+AndrewSav@users.noreply.github.com> Date: Sat, 22 Jul 2023 09:13:54 +1000 Subject: Fix rendering to main view on windows --- pkg/tasks/tasks.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go index 33c46380f..8fcebf4b4 100644 --- a/pkg/tasks/tasks.go +++ b/pkg/tasks/tasks.go @@ -164,6 +164,20 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p scanner := bufio.NewScanner(r) scanner.Split(bufio.ScanLines) + data := make(chan []byte) + + // We're reading from the scanner in a separate goroutine because on windows + // if running git through a shim, we sometimes kill the parent process without + // killing its children, meaning the scanner blocks forever. This solution + // leaves us with a dead goroutine, but it's better than blocking all + // rendering to main views. + go utils.Safe(func() { + for scanner.Scan() { + data <- scanner.Bytes() + } + close(data) + }) + loaded := false go utils.Safe(func() { @@ -203,13 +217,15 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p break outer case linesToRead := <-self.readLines: for i := 0; i < linesToRead.Total; i++ { + var ok bool + var line []byte select { case <-opts.Stop: break outer - default: + case line, ok = <-data: + break } - ok := scanner.Scan() loadingMutex.Lock() if !loaded { self.beforeStart() @@ -226,7 +242,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p self.onEndOfInput() break outer } - writeToView(append(scanner.Bytes(), '\n')) + writeToView(append(line, '\n')) if i+1 == linesToRead.InitialRefreshAfter { // We have read enough lines to fill the view, so do a first refresh -- cgit v1.2.3