diff --git a/cmd/revgrep/main.go b/cmd/revgrep/main.go index f05d792..26048cd 100644 --- a/cmd/revgrep/main.go +++ b/cmd/revgrep/main.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/bradleyfalzon/revgrep" + "github.com/golangci/revgrep" ) func main() { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8bdbb19 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/golangci/revgrep + +go 1.13 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/revgrep.go b/revgrep.go index 3650d64..d0940d3 100644 --- a/revgrep.go +++ b/revgrep.go @@ -279,9 +279,21 @@ func (c Checker) linesChanged() map[string][]pos { return changes } - scanner := bufio.NewScanner(c.Patch) - for scanner.Scan() { - line := scanner.Text() // TODO scanner.Bytes() + scanner := bufio.NewReader(c.Patch) + var scanErr error + for { + lineB, isPrefix, err := scanner.ReadLine() + if isPrefix { + // If a single line overflowed the buffer, don't bother processing it as + // it's likey part of a file and not relevant to the patch. + continue + } + if err != nil { + scanErr = err + break + } + line := strings.TrimRight(string(lineB), "\n") + c.debugf(line) s.lineNo++ s.hunkPos++ @@ -313,8 +325,8 @@ func (c Checker) linesChanged() map[string][]pos { } } - if err := scanner.Err(); err != nil { - fmt.Fprintln(os.Stderr, "reading standard input:", err) + if scanErr != nil && scanErr != io.EOF { + fmt.Fprintln(os.Stderr, "reading standard input:", scanErr) } // record the last state changes[s.file] = s.changes