Skip to content

Use bufio.Reader to handle large git histories #4

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

Merged
merged 3 commits into from
Feb 8, 2021
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
2 changes: 1 addition & 1 deletion cmd/revgrep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/bradleyfalzon/revgrep"
"github.com/golangci/revgrep"
)

func main() {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/golangci/revgrep

go 1.13
Empty file added go.sum
Empty file.
22 changes: 17 additions & 5 deletions revgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down Expand Up @@ -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
Expand Down