Skip to content

Commit 817f6b1

Browse files
author
Juanjo Alvarez
committed
Don't abort on git.Blame errors
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 1bced9b commit 817f6b1

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

internal/function/blame.go

Lines changed: 12 additions & 4 deletions
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"
@@ -17,10 +20,11 @@ type BlameGenerator struct {
1720
curLine int
1821
curFile *object.File
1922
lines []*git.Line
23+
ctx *sql.Context
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(c *object.Commit, f *object.FileIter, ctx *sql.Context) (*BlameGenerator, error) {
27+
return &BlameGenerator{commit: c, fIter: f, curLine: -1, ctx: ctx}, nil
2428
}
2529

2630
func (g *BlameGenerator) loadNewFile() error {
@@ -32,7 +36,11 @@ 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("Error in BLAME for file %s: %s",
40+
g.curFile.Name, err.Error())
41+
logrus.Warn(msg)
42+
g.ctx.Warn(0, msg)
43+
return io.EOF
3644
}
3745

3846
if len(result.Lines) == 0 {
@@ -145,7 +153,7 @@ func (b *Blame) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
145153
return nil, err
146154
}
147155

148-
bg, err := NewBlameGenerator(commit, fIter)
156+
bg, err := NewBlameGenerator(commit, fIter, ctx)
149157
if err != nil {
150158
return nil, err
151159
}

0 commit comments

Comments
 (0)