A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/jesseduffield/lazygit/commit/b1382da9ec37011f186fa2adfde75ac1ee42b37c below:

Fix delay with flicking through files or commits when git diff is ver… · jesseduffield/lazygit@b1382da · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+56

-18

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+56

-18

lines changed Original file line number Diff line number Diff line change

@@ -1,7 +1,6 @@

1 1

package oscommands

2 2 3 3

import (

4 -

"fmt"

5 4

"io"

6 5

"os"

7 6

"os/exec"

@@ -329,15 +328,3 @@ func GetLazygitPath() string {

329 328

}

330 329

return `"` + filepath.ToSlash(ex) + `"`

331 330

}

332 - 333 -

func (c *OSCommand) UpdateWindowTitle() error {

334 -

if c.Platform.OS != "windows" {

335 -

return nil

336 -

}

337 -

path, getWdErr := os.Getwd()

338 -

if getWdErr != nil {

339 -

return getWdErr

340 -

}

341 -

argString := fmt.Sprint("title ", filepath.Base(path), " - Lazygit")

342 -

return c.Cmd.NewShell(argString, c.UserConfig().OS.ShellFunctionsFile).Run()

343 -

}

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 {

@@ -34,3 +36,15 @@ func getUserShell() string {

34 36 35 37

return "bash"

36 38

}

39 + 40 +

func (c *OSCommand) UpdateWindowTitle() error {

41 +

return nil

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

@@ -1,9 +1,30 @@

1 1

package oscommands

2 2 3 +

import (

4 +

"fmt"

5 +

"os"

6 +

"os/exec"

7 +

"path/filepath"

8 +

)

9 + 3 10

func GetPlatform() *Platform {

4 11

return &Platform{

5 12

OS: "windows",

6 13

Shell: "cmd",

7 14

ShellArg: "/c",

8 15

}

9 16

}

17 + 18 +

func (c *OSCommand) UpdateWindowTitle() error {

19 +

path, getWdErr := os.Getwd()

20 +

if getWdErr != nil {

21 +

return getWdErr

22 +

}

23 +

argString := fmt.Sprint("title ", filepath.Base(path), " - Lazygit")

24 +

return c.Cmd.NewShell(argString, c.UserConfig().OS.ShellFunctionsFile).Run()

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

}

@@ -291,11 +303,15 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p

291 303 292 304

refreshViewIfStale()

293 305 294 -

if err := cmd.Wait(); err != nil {

295 -

select {

296 -

case <-opts.Stop:

297 -

// it's fine if we've killed this program ourselves

298 -

default:

306 +

select {

307 +

case <-opts.Stop:

308 +

// If we stopped the task, don't block waiting for it; this could cause a delay if

309 +

// the process takes a while until it actually terminates. We still want to call

310 +

// Wait to reclaim any resources, but do it on a background goroutine, and ignore

311 +

// any errors.

312 +

go func() { _ = cmd.Wait() }()

313 +

default:

314 +

if err := cmd.Wait(); err != nil {

299 315

self.Log.Errorf("Unexpected error when running cmd task: %v; Failed command: %v %v", err, cmd.Path, cmd.Args)

300 316

}

301 317

}

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