MCPcopy Index your code
hub / github.com/go-git/go-git / Decode

Method Decode

plumbing/object/commit.go:253–283  ·  view source on GitHub ↗

Decode transforms a plumbing.EncodedObject into a Commit struct.

(o plumbing.EncodedObject)

Source from the content-addressed store, hash-verified

251
252// Decode transforms a plumbing.EncodedObject into a Commit struct.
253func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
254 if o.Type() != plumbing.CommitObject {
255 return ErrUnsupportedObject
256 }
257
258 c.reset()
259 c.Hash = o.Hash()
260 c.src = o
261
262 reader, err := o.Reader()
263 if err != nil {
264 return err
265 }
266 defer ioutil.CheckClose(reader, &err)
267
268 r := sync.GetBufioReader(reader)
269 defer sync.PutBufioReader(r)
270
271 s := &commitScanner{r: r, c: c}
272 for state := scanTree; state != nil; {
273 state, err = state(s)
274 if err != nil {
275 return err
276 }
277 }
278 if !s.sawTree {
279 return fmt.Errorf("%w: missing tree header", ErrMalformedCommit)
280 }
281 c.Message = s.msgbuf.String()
282 return nil
283}
284
285// Encode transforms a Commit into a plumbing.EncodedObject.
286func (c *Commit) Encode(o plumbing.EncodedObject) error {

Callers 12

TestDecodeNonCommitMethod · 0.95
TestMalformedHeaderMethod · 0.95
toObjectMethod · 0.95
DecodeCommitFunction · 0.95
matchesSourceMethod · 0.95
decodeCommitFunction · 0.95

Calls 8

resetMethod · 0.95
CheckCloseFunction · 0.92
GetBufioReaderFunction · 0.92
PutBufioReaderFunction · 0.92
TypeMethod · 0.65
HashMethod · 0.65
ReaderMethod · 0.65
StringMethod · 0.65