diff options
Diffstat (limited to 'plumbing/protocol/packp/shallowupd.go')
-rw-r--r-- | plumbing/protocol/packp/shallowupd.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/plumbing/protocol/packp/shallowupd.go b/plumbing/protocol/packp/shallowupd.go index 89063de..40f58e8 100644 --- a/plumbing/protocol/packp/shallowupd.go +++ b/plumbing/protocol/packp/shallowupd.go @@ -24,6 +24,7 @@ func (r *ShallowUpdate) Decode(reader io.Reader) error { for s.Scan() { line := s.Bytes() + line = bytes.TrimSpace(line) var err error switch { @@ -71,3 +72,21 @@ func (r *ShallowUpdate) decodeLine(line, prefix []byte, expLen int) (plumbing.Ha raw := string(line[expLen-40 : expLen]) return plumbing.NewHash(raw), nil } + +func (r *ShallowUpdate) Encode(w io.Writer) error { + e := pktline.NewEncoder(w) + + for _, h := range r.Shallows { + if err := e.Encodef("%s%s\n", shallow, h.String()); err != nil { + return err + } + } + + for _, h := range r.Unshallows { + if err := e.Encodef("%s%s\n", unshallow, h.String()); err != nil { + return err + } + } + + return e.Flush() +} |