Skip to content

Commit 774281f

Browse files
committed
Standardize on int64 for line numbers
This matches the type used for positions in text fragments.
1 parent 7bd4e0b commit 774281f

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

gitdiff/apply.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,15 @@ func applyTextLine(dst io.Writer, src string, line Line) (err error) {
166166
// the line at limit and the line number. If the error is nil or io.EOF, the
167167
// line number equals limit. A negative limit checks that the source has no
168168
// more lines to read.
169-
func copyLines(dst io.Writer, src LineReader, limit int64) (string, int, error) {
170-
// TODO(bkeyes): fix int vs int64 for limit and return value
169+
func copyLines(dst io.Writer, src LineReader, limit int64) (string, int64, error) {
171170
for {
172171
line, n, err := src.ReadLine()
173172
switch {
174173
case limit < 0 && err == io.EOF && line == "":
175-
return "", int(limit), nil
176-
case int64(n) == limit:
174+
return "", limit, nil
175+
case n == limit:
177176
return line, n, err
178-
case int64(n) > limit:
177+
case n > limit:
179178
if limit < 0 {
180179
return "", n, conflictError("cannot create new file from non-empty src")
181180
}

gitdiff/io.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ type readStringReader interface {
3535
// numbers may be incorrect if calls to ReadLine are mixed with calls to other
3636
// read methods.
3737
type LineReader interface {
38-
// TODO(bkeyes): consider making lineno int64 to match fragment types
39-
ReadLine() (string, int, error)
38+
ReadLine() (string, int64, error)
4039
}
4140

4241
// NewLineReader returns a LineReader starting at a specific line and using the
4342
// newline character, \n, as a line separator. If r is a StringReader, it is
4443
// used directly. Otherwise, it is wrapped in a way that may read extra data
4544
// from the underlying input.
46-
func NewLineReader(r io.Reader, lineno int) LineReader {
45+
func NewLineReader(r io.Reader, lineno int64) LineReader {
4746
sr, ok := r.(readStringReader)
4847
if !ok {
4948
sr = bufio.NewReader(r)
@@ -53,10 +52,10 @@ func NewLineReader(r io.Reader, lineno int) LineReader {
5352

5453
type lineReader struct {
5554
r readStringReader
56-
n int
55+
n int64
5756
}
5857

59-
func (lr *lineReader) ReadLine() (line string, lineno int, err error) {
58+
func (lr *lineReader) ReadLine() (line string, lineno int64, err error) {
6059
lineno = lr.n
6160
line, err = lr.r.ReadString('\n')
6261
if err == nil {

gitdiff/io_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestLineReader(t *testing.T) {
3434
if d != line.Data {
3535
t.Errorf("incorrect line data: expected %q, actual %q", line.Data, d)
3636
}
37-
if n != i {
37+
if n != int64(i) {
3838
t.Errorf("incorrect line number: expected %d, actual %d", i, n)
3939
}
4040
}

0 commit comments

Comments
 (0)