diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-05-20 17:38:31 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-01 08:31:18 +0200 |
commit | 2c9bca8b579fb2c3f541361ae40713a41d2ba13c (patch) | |
tree | 19416542a6599983a7843e4899736e7a62a1d193 /pkg | |
parent | 880528b2e45b25afe31d1f598de3961577df0e39 (diff) |
Return errors from blameDeletedLines instead of just logging them
I guess when I originally wrote this code I just didn't know how to do that...
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/controllers/helpers/fixup_helper.go | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index ef4bb315e..f57e8f2f9 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -5,13 +5,13 @@ import ( "fmt" "regexp" "strings" - "sync" "github.com/jesseduffield/generics/set" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" + "golang.org/x/sync/errgroup" ) type FixupHelper struct { @@ -56,7 +56,10 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error { return errors.New(self.c.Tr.NoDeletedLinesInDiff) } - hashes := self.blameDeletedLines(deletedLineHunks) + hashes, err := self.blameDeletedLines(deletedLineHunks) + if err != nil { + return err + } if len(hashes) == 0 { // This should never happen @@ -185,29 +188,29 @@ func parseDiff(diff string) ([]*hunk, []*hunk) { } // returns the list of commit hashes that introduced the lines which have now been deleted -func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) []string { - var wg sync.WaitGroup +func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string, error) { + errg := errgroup.Group{} hashChan := make(chan string) for _, h := range deletedLineHunks { - wg.Add(1) - go func(h *hunk) { - defer wg.Done() - + errg.Go(func() error { blameOutput, err := self.c.Git().Blame.BlameLineRange(h.filename, "HEAD", h.startLineIdx, h.numLines) if err != nil { - self.c.Log.Errorf("Error blaming file '%s': %v", h.filename, err) - return + return err } blameLines := strings.Split(strings.TrimSuffix(blameOutput, "\n"), "\n") for _, line := range blameLines { hashChan <- strings.Split(line, " ")[0] } - }(h) + return nil + }) } go func() { - wg.Wait() + // We don't care about the error here, we'll check it later (in the + // return statement below). Here we only wait for all the goroutines to + // finish so that we can close the channel. + _ = errg.Wait() close(hashChan) }() @@ -216,5 +219,5 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) []string { result.Add(hash) } - return result.ToSlice() + return result.ToSlice(), errg.Wait() } |