Skip to content

Commit 754ede2

Browse files
authored
Don't abort on git.Blame errors (#968)
Don't abort on git.Blame errors
2 parents 1bced9b + 9ff7004 commit 754ede2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Added BLAME function.
1111
## Fixed
1212
- Removed redundant commit information from BLAME results.
13+
- Don't abort, just warn, on git.Blame errors.
1314

1415
## [0.24.0-rc2] - 2019-10-02
1516

Diff for: internal/function/blame.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package function
22

33
import (
44
"fmt"
5+
"io"
6+
7+
"github.com/sirupsen/logrus"
58

69
"github.com/src-d/gitbase"
710
"github.com/src-d/go-mysql-server/sql"
@@ -12,15 +15,16 @@ import (
1215
)
1316

1417
type BlameGenerator struct {
18+
ctx *sql.Context
1519
commit *object.Commit
1620
fIter *object.FileIter
1721
curLine int
1822
curFile *object.File
1923
lines []*git.Line
2024
}
2125

22-
func NewBlameGenerator(c *object.Commit, f *object.FileIter) (*BlameGenerator, error) {
23-
return &BlameGenerator{commit: c, fIter: f, curLine: -1}, nil
26+
func NewBlameGenerator(ctx *sql.Context, c *object.Commit, f *object.FileIter) (*BlameGenerator, error) {
27+
return &BlameGenerator{ctx: ctx, commit: c, fIter: f, curLine: -1}, nil
2428
}
2529

2630
func (g *BlameGenerator) loadNewFile() error {
@@ -32,7 +36,14 @@ func (g *BlameGenerator) loadNewFile() error {
3236

3337
result, err := git.Blame(g.commit, g.curFile.Name)
3438
if err != nil {
35-
return err
39+
msg := fmt.Sprintf(
40+
"Error in BLAME for file %s: %s",
41+
g.curFile.Name,
42+
err.Error(),
43+
)
44+
logrus.Warn(msg)
45+
g.ctx.Warn(0, msg)
46+
return io.EOF
3647
}
3748

3849
if len(result.Lines) == 0 {
@@ -145,7 +156,7 @@ func (b *Blame) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
145156
return nil, err
146157
}
147158

148-
bg, err := NewBlameGenerator(commit, fIter)
159+
bg, err := NewBlameGenerator(ctx, commit, fIter)
149160
if err != nil {
150161
return nil, err
151162
}

0 commit comments

Comments
 (0)