+28
-0
lines changedFilter options
+28
-0
lines changed Original file line number Diff line number Diff line change
@@ -5,8 +5,10 @@ package oscommands
5
5
6
6
import (
7
7
"os"
8
+
"os/exec"
8
9
"runtime"
9
10
"strings"
11
+
"syscall"
10
12
)
11
13
12
14
func GetPlatform() *Platform {
@@ -38,3 +40,11 @@ func getUserShell() string {
38
40
func (c *OSCommand) UpdateWindowTitle() error {
39
41
return nil
40
42
}
43
+
44
+
func TerminateProcessGracefully(cmd *exec.Cmd) error {
45
+
if cmd.Process == nil {
46
+
return nil
47
+
}
48
+
49
+
return cmd.Process.Signal(syscall.SIGTERM)
50
+
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package oscommands
3
3
import (
4
4
"fmt"
5
5
"os"
6
+
"os/exec"
6
7
"path/filepath"
7
8
)
8
9
@@ -22,3 +23,8 @@ func (c *OSCommand) UpdateWindowTitle() error {
22
23
argString := fmt.Sprint("title ", filepath.Base(path), " - Lazygit")
23
24
return c.Cmd.NewShell(argString, c.UserConfig().OS.ShellFunctionsFile).Run()
24
25
}
26
+
27
+
func TerminateProcessGracefully(cmd *exec.Cmd) error {
28
+
// Signals other than SIGKILL are not supported on Windows
29
+
return nil
30
+
}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (
9
9
"time"
10
10
11
11
"github.com/jesseduffield/gocui"
12
+
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
12
13
"github.com/jesseduffield/lazygit/pkg/utils"
13
14
"github.com/sasha-s/go-deadlock"
14
15
"github.com/sirupsen/logrus"
@@ -165,6 +166,17 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
165
166
// and the user is flicking through a bunch of items.
166
167
self.throttle = time.Since(startTime) < THROTTLE_TIME && timeToStart > COMMAND_START_THRESHOLD
167
168
169
+
// Kill the still-running command. The only reason to do this is to save CPU usage
170
+
// when flicking through several very long diffs when diff.algorithm = histogram is
171
+
// being used, in which case multiple git processes continue to calculate expensive
172
+
// diffs in the background even though they have been stopped already.
173
+
//
174
+
// Unfortunately this will do nothing on Windows, so Windows users will have to live
175
+
// with the higher CPU usage.
176
+
if err := oscommands.TerminateProcessGracefully(cmd); err != nil {
177
+
self.Log.Errorf("error when trying to terminate cmd task: %v; Command: %v %v", err, cmd.Path, cmd.Args)
178
+
}
179
+
168
180
// close the task's stdout pipe (or the pty if we're using one) to make the command terminate
169
181
onDone()
170
182
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4