This commit is contained in:
Adam Majer 2024-07-16 06:56:57 +02:00
parent fd077efa19
commit 4af0d31c69
2 changed files with 25 additions and 13 deletions

View File

@ -210,29 +210,33 @@ type ChanIO struct {
} }
func (c *ChanIO) Write(p []byte) (int, error) { func (c *ChanIO) Write(p []byte) (int, error) {
for i := range len(p) { for _, b := range p {
c.ch <- p[i] c.ch <- b
} }
return len(p), nil return len(p), nil
} }
// read at least 1 byte, but don't block if nothing in channel // read at least 1 byte, but don't block if nothing more in channel
func (c *ChanIO) Read(p []byte) (int, error) { func (c *ChanIO) Read(data []byte) (int, error) {
data, ok := <-c.ch var ok bool
for i := 0; i < cap(p); i++ { var idx int
data, ok = <-c.ch
data[idx], ok = <-c.ch
if !ok {
return 0, io.EOF
}
idx++
for len(c.ch) > 0 && idx < len(data) {
data[idx], ok = <- c.ch
if !ok { if !ok {
return len(p), io.EOF return idx, io.EOF
} }
p[i] = data idx++
if len(c.ch) < 1 {
break
}
} }
return len(p), nil return idx, nil
} }
type gitMsg struct { type gitMsg struct {

View File

@ -219,3 +219,11 @@ Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>` + "\x00"
} }
}) })
} }
/*func TestCommitTreeParsingOfHead(t *testing.T) {
t.Run("reads HEAD and parses the tree", func (t *testing.T) {
}
}
*/