mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-12-05 02:54:46 +01:00
23358bc55d
* 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>
53 lines
1.9 KiB
Go
Vendored
53 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
|
|
}
|