Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace use of bufio.Scanner #1512

Merged
merged 1 commit into from
Feb 22, 2024
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
9 changes: 5 additions & 4 deletions internal/git/diff.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package git

import (
"bufio"
"context"
"fmt"
"io"
"strconv"
"strings"

"github.com/bearer/bearer/internal/util/linescanner"
)

type ChunkRange struct {
Expand Down Expand Up @@ -46,7 +47,7 @@ func Diff(rootDir, baseRef string) ([]FilePatch, error) {
},
func(stdout io.Reader) error {
var err error
result, err = parseDiff(bufio.NewScanner(stdout))
result, err = parseDiff(linescanner.New(stdout))
if err != nil {
return err
}
Expand All @@ -58,7 +59,7 @@ func Diff(rootDir, baseRef string) ([]FilePatch, error) {
return result, err
}

func parseDiff(scanner *bufio.Scanner) ([]FilePatch, error) {
func parseDiff(scanner *linescanner.Scanner) ([]FilePatch, error) {
var result []FilePatch
var fromPath, toPath string
var chunks []Chunk
Expand Down Expand Up @@ -108,7 +109,7 @@ func parseDiff(scanner *bufio.Scanner) ([]FilePatch, error) {

flush()

return result, nil
return result, scanner.Err()
}

func parseDiffHeader(value string) (string, string, error) {
Expand Down
6 changes: 3 additions & 3 deletions internal/util/file/file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package file

import (
"bufio"
"fmt"
"io"
"os"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/go-enry/go-enry/v2"
"github.com/rs/zerolog/log"

"github.com/bearer/bearer/internal/util/linescanner"
"github.com/bearer/bearer/internal/util/regex"

ignore "github.com/sabhiram/go-gitignore"
Expand Down Expand Up @@ -326,7 +326,7 @@ func ReadFileSinkLines(

defer file.Close()

scanner := bufio.NewScanner(file)
scanner := linescanner.New(file)
lineCounter := 1
var extract []Line

Expand Down Expand Up @@ -370,7 +370,7 @@ func ReadFileSingleLine(filePath string, lineNumber int) (string, error) {
}
defer file.Close()

scanner := bufio.NewScanner(file)
scanner := linescanner.New(file)
lineCounter := 1
for scanner.Scan() {
if lineCounter == lineNumber {
Expand Down
Loading