MCPcopy Create free account
hub / github.com/go-git/go-git / Decode

Method Decode

plumbing/object/commit.go:186–275  ·  view source on GitHub ↗

Decode transforms a plumbing.EncodedObject into a Commit struct.

(o plumbing.EncodedObject)

Source from the content-addressed store, hash-verified

184
185// Decode transforms a plumbing.EncodedObject into a Commit struct.
186func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
187 if o.Type() != plumbing.CommitObject {
188 return ErrUnsupportedObject
189 }
190
191 c.Hash = o.Hash()
192 c.Encoding = defaultUtf8CommitMessageEncoding
193
194 reader, err := o.Reader()
195 if err != nil {
196 return err
197 }
198 defer ioutil.CheckClose(reader, &err)
199
200 r := sync.GetBufioReader(reader)
201 defer sync.PutBufioReader(r)
202
203 var message bool
204 var mergetag bool
205 var pgpsig bool
206 var msgbuf bytes.Buffer
207 for {
208 line, err := r.ReadBytes('\n')
209 if err != nil && err != io.EOF {
210 return err
211 }
212
213 if mergetag {
214 if len(line) > 0 && line[0] == ' ' {
215 line = bytes.TrimLeft(line, " ")
216 c.MergeTag += string(line)
217 continue
218 } else {
219 mergetag = false
220 }
221 }
222
223 if pgpsig {
224 if len(line) > 0 && line[0] == ' ' {
225 line = bytes.TrimLeft(line, " ")
226 c.PGPSignature += string(line)
227 continue
228 } else {
229 pgpsig = false
230 }
231 }
232
233 if !message {
234 line = bytes.TrimSpace(line)
235 if len(line) == 0 {
236 message = true
237 continue
238 }
239
240 split := bytes.SplitN(line, []byte{' '}, 2)
241
242 var data []byte
243 if len(split) == 2 {

Callers 7

TestDecodeNonCommitMethod · 0.95
TestMalformedHeaderMethod · 0.95
toObjectMethod · 0.95
DecodeCommitFunction · 0.95

Calls 11

CheckCloseFunction · 0.92
GetBufioReaderFunction · 0.92
PutBufioReaderFunction · 0.92
NewHashFunction · 0.92
MessageEncodingTypeAlias · 0.85
TypeMethod · 0.65
HashMethod · 0.65
ReaderMethod · 0.65
DecodeMethod · 0.65
StringMethod · 0.65
WriteMethod · 0.45