Select the types of activity you want to include in your feed.
Add internal function to unwrap LineReaders
When applying, we need to copy all data after the last fragment line. This function provides a way to get back the possibly-buffered io.Reader that backs the LineReader.
···2233import (
44 "bufio"
55+ "fmt"
56 "io"
67)
78···1617 ReadString(delim byte) (string, error)
1718}
18192020+type readStringReader interface {
2121+ io.Reader
2222+ StringReader
2323+}
2424+1925// LineReader is the interface that wraps the ReadLine method.
2026//
2127// ReadLine reads the next full line in the input, returing the the data
···3137 ReadLine() (string, int, error)
3238}
33393434-// NewLineReader returns a LineReader for a reader starting at a specific line
3535-// using the newline character, \n, as a line separator. If r is a
3636-// StringReader, it is used directly. Otherwise, it is wrapped in a way that
3737-// may read extra data from the underlying input.
4040+// NewLineReader returns a LineReader starting at a specific line and using the
4141+// newline character, \n, as a line separator. If r is a StringReader, it is
4242+// used directly. Otherwise, it is wrapped in a way that may read extra data
4343+// from the underlying input.
3844func NewLineReader(r io.Reader, lineno int) LineReader {
3939- sr, ok := r.(StringReader)
4545+ sr, ok := r.(readStringReader)
4046 if !ok {
4147 sr = bufio.NewReader(r)
4248 }
···4450}
45514652type lineReader struct {
4747- r StringReader
5353+ r readStringReader
4854 n int
4955}
5056···5662 }
5763 return
5864}
6565+6666+// unwrapLineReader returns a plain io.Reader that was converted to a
6767+// LineReader by wrapping or casting. It should only be called from functions
6868+// that accept an io.Reader as an argument and then convert it.
6969+func unwrapLineReader(lr LineReader) io.Reader {
7070+ switch r := lr.(type) {
7171+ case io.Reader:
7272+ return r
7373+ case *lineReader:
7474+ return r.r
7575+ default:
7676+ panic(fmt.Sprintf("%T does not implement io.Reader and is not a gitdiff wrapper", lr))
7777+ }
7878+}