Skip to content

Commit

Permalink
fix: replace use of bufio.Scanner (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
didroe authored Feb 22, 2024
1 parent c43608e commit f6c002f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit f6c002f

Please sign in to comment.