gitea/vendor/github.com/djherbis/nio/v3/nio.go
zeripath 23358bc55d
Use git log name-status in get last commit (#16059)
* Improve get last commit using git log --name-status

git log --name-status -c provides information about the diff between a
commit and its parents. Using this and adjusting the algorithm to use
the first change to a path allows for a much faster generation of commit
info.

There is a subtle change in the results generated but this will cause
the results to more closely match those from elsewhere.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
2021-06-21 01:00:46 +03:00

54 lines
1.9 KiB
Go
Vendored

// Package nio provides a few buffered io primitives.
package nio
import "io"
// Buffer is used to store bytes.
type Buffer interface {
// Len returns how many bytes are buffered
Len() int64
// Cap returns how many bytes can in the buffer at a time
Cap() int64
// ReadWriter writes are stored in the buffer, reads return the stored data
io.ReadWriter
}
// Pipe creates a buffered pipe.
// It can be used to connect code expecting an io.Reader with code expecting an io.Writer.
// Reads on one end read from the supplied Buffer. Writes write to the supplied Buffer.
// It is safe to call Read and Write in parallel with each other or with Close.
// Close will complete once pending I/O is done, and may cancel blocking Read/Writes.
// Buffered data will still be available to Read after the Writer has been closed.
// Parallel calls to Read, and parallel calls to Write are also safe :
// the individual calls will be gated sequentially.
func Pipe(buf Buffer) (r *PipeReader, w *PipeWriter) {
p := newBufferedPipe(buf)
r = &PipeReader{bufpipe: p}
w = &PipeWriter{bufpipe: p}
return r, w
}
// Copy copies from src to buf, and from buf to dst in parallel until
// either EOF is reached on src or an error occurs. It returns the number of bytes
// copied to dst and the first error encountered while copying, if any.
// EOF is not considered to be an error. If src implements WriterTo, it is used to
// write to the supplied Buffer. If dst implements ReaderFrom, it is used to read from
// the supplied Buffer.
func Copy(dst io.Writer, src io.Reader, buf Buffer) (n int64, err error) {
return io.Copy(dst, NewReader(src, buf))
}
// NewReader reads from the buffer which is concurrently filled with data from the passed src.
func NewReader(src io.Reader, buf Buffer) io.ReadCloser {
r, w := Pipe(buf)
go func() {
_, err := io.Copy(w, src)
w.CloseWithError(err)
}()
return r
}