func (b *Commit) Encode(o plumbing.EncodedObject) error {
	return b.encode(o, true)
}
Encode transforms a Commit into a plumbing.EncodedObject.
package object
import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"io"
	"strings"
	"golang.org/x/crypto/openpgp"
	"gopkg.in/src-d/go-git.v4/plumbing"
	"gopkg.in/src-d/go-git.v4/plumbing/storer"
	"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
const (
	beginpgp string = "-----BEGIN PGP SIGNATURE-----"
	endpgp   string = "-----END PGP SIGNATURE-----"
)
type Hash plumbing.Hash
type Commit struct {
	Hash plumbing.Hash
	Author Signature
	Committer Signature
	PGPSignature string
	Message string
	TreeHash plumbing.Hash
	ParentHashes []plumbing.Hash
	s storer.EncodedObjectStorer
}
func GetCommit(s storer.EncodedObjectStorer, h plumbing.Hash) (*Commit, error) {
	o, err := s.EncodedObject(plumbing.CommitObject, h)
	if err != nil {
		return nil, err
	}
	return DecodeCommit(s, o)
}
func DecodeCommit(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (*Commit, error) {
	c := &Commit{s: s}
	if err := c.Decode(o); err != nil {
		return nil, err
	}
	return c, nil
}
func (c *Commit) Tree() (*Tree, error) {
	return GetTree(c.s, c.TreeHash)
}
func (c *Commit) Patch(to *Commit) (*Patch, error) {
	fromTree, err := c.Tree()
	if err != nil {
		return nil, err
	}
	toTree, err := to.Tree()
	if err != nil {
		return nil, err
	}
	return fromTree.Patch(toTree)
}
func (c *Commit) Parents() CommitIter {
	return NewCommitIter(c.s,
		storer.NewEncodedObjectLookupIter(c.s, plumbing.CommitObject, c.ParentHashes),
	)
}
func (c *Commit) NumParents() int {
	return len(c.ParentHashes)
}
var ErrParentNotFound = errors.New("commit parent not found")
func (c *Commit) Parent(i int) (*Commit, error) {
	if len(c.ParentHashes) == 0 || i > len(c.ParentHashes)-1 {
		return nil, ErrParentNotFound
	}
	return GetCommit(c.s, c.ParentHashes[i])
}
func (c *Commit) File(path string) (*File, error) {
	tree, err := c.Tree()
	if err != nil {
		return nil, err
	}
	return tree.File(path)
}
func (c *Commit) Files() (*FileIter, error) {
	tree, err := c.Tree()
	if err != nil {
		return nil, err
	}
	return tree.Files(), nil
}
func (c *Commit) ID() plumbing.Hash {
	return c.Hash
}
func (c *Commit) Type() plumbing.ObjectType {
	return plumbing.CommitObject
}
func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
	if o.Type() != plumbing.CommitObject {
		return ErrUnsupportedObject
	}
	c.Hash = o.Hash()
	reader, err := o.Reader()
	if err != nil {
		return err
	}
	defer ioutil.CheckClose(reader, &err)
	r := bufio.NewReader(reader)
	var message bool
	var pgpsig bool
	for {
		line, err := r.ReadBytes('\n')
		if err != nil && err != io.EOF {
			return err
		}
		if pgpsig {
			if bytes.Contains(line, []byte(endpgp)) {
				c.PGPSignature += endpgp + "\n"
				pgpsig = false
			} else {
				line = bytes.TrimLeft(line, " ")
				c.PGPSignature += string(line)
			}
			continue
		}
		if bytes.Contains(line, []byte(beginpgp)) {
			c.PGPSignature += beginpgp + "\n"
			pgpsig = true
			continue
		}
		if !message {
			line = bytes.TrimSpace(line)
			if len(line) == 0 {
				message = true
				continue
			}
			split := bytes.SplitN(line, []byte{' '}, 2)
			switch string(split[0]) {
			case "tree":
				c.TreeHash = plumbing.NewHash(string(split[1]))
			case "parent":
				c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(split[1])))
			case "author":
				c.Author.Decode(split[1])
			case "committer":
				c.Committer.Decode(split[1])
			}
		} else {
			c.Message += string(line)
		}
		if err == io.EOF {
			return nil
		}
	}
}