Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added BLAME function.
## Fixed
- Removed redundant commit information from BLAME results.
- Don't abort, just warn, on git.Blame errors.

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

Expand Down
19 changes: 15 additions & 4 deletions internal/function/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package function

import (
"fmt"
"io"

"github.com/sirupsen/logrus"

"github.com/src-d/gitbase"
"github.com/src-d/go-mysql-server/sql"
Expand All @@ -12,15 +15,16 @@ import (
)

type BlameGenerator struct {
ctx *sql.Context
commit *object.Commit
fIter *object.FileIter
curLine int
curFile *object.File
lines []*git.Line
}

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

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

result, err := git.Blame(g.commit, g.curFile.Name)
if err != nil {
return err
msg := fmt.Sprintf(
"Error in BLAME for file %s: %s",
g.curFile.Name,
err.Error(),
)
logrus.Warn(msg)
g.ctx.Warn(0, msg)
return io.EOF
}

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

bg, err := NewBlameGenerator(commit, fIter)
bg, err := NewBlameGenerator(ctx, commit, fIter)
if err != nil {
return nil, err
}
Expand Down