@@ -27,7 +27,7 @@ type BlameReader struct {
27
27
cmd * exec.Cmd
28
28
pid int64
29
29
output io.ReadCloser
30
- scanner * bufio.Scanner
30
+ reader * bufio.Reader
31
31
lastSha * string
32
32
cancel context.CancelFunc
33
33
}
@@ -38,36 +38,58 @@ var shaLineRegex = regexp.MustCompile("^([a-z0-9]{40})")
38
38
func (r * BlameReader ) NextPart () (* BlamePart , error ) {
39
39
var blamePart * BlamePart
40
40
41
- scanner := r .scanner
41
+ reader := r .reader
42
42
43
43
if r .lastSha != nil {
44
44
blamePart = & BlamePart {* r .lastSha , make ([]string , 0 )}
45
45
}
46
46
47
- for scanner .Scan () {
48
- line := scanner .Text ()
47
+ var line []byte
48
+ var isPrefix bool
49
+ var err error
50
+
51
+ for err != io .EOF {
52
+ line , isPrefix , err = reader .ReadLine ()
53
+ if err != nil && err != io .EOF {
54
+ return blamePart , err
55
+ }
49
56
50
- // Skip empty lines
51
57
if len (line ) == 0 {
58
+ // isPrefix will be false
52
59
continue
53
60
}
54
61
55
- lines := shaLineRegex .FindStringSubmatch (line )
62
+ lines := shaLineRegex .FindSubmatch (line )
56
63
if lines != nil {
57
- sha1 := lines [1 ]
64
+ sha1 := string ( lines [1 ])
58
65
59
66
if blamePart == nil {
60
67
blamePart = & BlamePart {sha1 , make ([]string , 0 )}
61
68
}
62
69
63
70
if blamePart .Sha != sha1 {
64
71
r .lastSha = & sha1
72
+ // need to munch to end of line...
73
+ for isPrefix {
74
+ _ , isPrefix , err = reader .ReadLine ()
75
+ if err != nil && err != io .EOF {
76
+ return blamePart , err
77
+ }
78
+ }
65
79
return blamePart , nil
66
80
}
67
81
} else if line [0 ] == '\t' {
68
82
code := line [1 :]
69
83
70
- blamePart .Lines = append (blamePart .Lines , code )
84
+ blamePart .Lines = append (blamePart .Lines , string (code ))
85
+ }
86
+
87
+ // need to munch to end of line...
88
+ for isPrefix {
89
+ _ , isPrefix , err = reader .ReadLine ()
90
+ if err != nil && err != io .EOF {
91
+ return blamePart , err
92
+ }
71
93
}
72
94
}
73
95
@@ -121,13 +143,13 @@ func createBlameReader(ctx context.Context, dir string, command ...string) (*Bla
121
143
122
144
pid := process .GetManager ().Add (fmt .Sprintf ("GetBlame [repo_path: %s]" , dir ), cancel )
123
145
124
- scanner := bufio .NewScanner (stdout )
146
+ reader := bufio .NewReader (stdout )
125
147
126
148
return & BlameReader {
127
149
cmd ,
128
150
pid ,
129
151
stdout ,
130
- scanner ,
152
+ reader ,
131
153
nil ,
132
154
cancel ,
133
155
}, nil
0 commit comments