Source File
commit.go
Belonging Package
github.com/go-git/go-git/v5/plumbing/object
func ( storer.EncodedObjectStorer, plumbing.Hash) (*Commit, error) {
, := .EncodedObject(plumbing.CommitObject, )
if != nil {
return nil,
}
return DecodeCommit(, )
}
func ( *Commit) ( *Commit) (*Patch, error) {
return .PatchContext(context.Background(), )
}
func ( *Commit) () CommitIter {
return NewCommitIter(.s,
storer.NewEncodedObjectLookupIter(.s, plumbing.CommitObject, .ParentHashes),
)
}
func ( *Commit) () int {
return len(.ParentHashes)
}
var ErrParentNotFound = errors.New("commit parent not found")
func ( *Commit) ( int) (*Commit, error) {
if len(.ParentHashes) == 0 || > len(.ParentHashes)-1 {
return nil, ErrParentNotFound
}
return GetCommit(.s, .ParentHashes[])
}
func ( *Commit) () plumbing.ObjectType {
return plumbing.CommitObject
}
func ( *Commit) ( plumbing.EncodedObject) ( error) {
if .Type() != plumbing.CommitObject {
return ErrUnsupportedObject
}
.Hash = .Hash()
, := .Reader()
if != nil {
return
}
defer ioutil.CheckClose(, &)
:= bufPool.Get().(*bufio.Reader)
defer bufPool.Put()
.Reset()
var bool
var bool
var bytes.Buffer
for {
, := .ReadBytes('\n')
if != nil && != io.EOF {
return
}
if {
if len() > 0 && [0] == ' ' {
= bytes.TrimLeft(, " ")
.PGPSignature += string()
continue
} else {
= false
}
}
if ! {
= bytes.TrimSpace()
if len() == 0 {
= true
continue
}
:= bytes.SplitN(, []byte{' '}, 2)
var []byte
if len() == 2 {
= [1]
}
switch string([0]) {
case "tree":
.TreeHash = plumbing.NewHash(string())
case "parent":
.ParentHashes = append(.ParentHashes, plumbing.NewHash(string()))
case "author":
.Author.Decode()
case "committer":
.Committer.Decode()
case headerpgp:
.PGPSignature += string() + "\n"
= true
}
} else {
.Write()
}
if == io.EOF {
break
}
}
.Message = .String()
return nil
}
func ( *Commit) ( plumbing.EncodedObject) error {
return .encode(, false)
}
func ( *Commit) ( plumbing.EncodedObject, bool) ( error) {
.SetType(plumbing.CommitObject)
, := .Writer()
if != nil {
return
}
defer ioutil.CheckClose(, &)
if _, = fmt.Fprintf(, "tree %s\n", .TreeHash.String()); != nil {
return
}
for , := range .ParentHashes {
if _, = fmt.Fprintf(, "parent %s\n", .String()); != nil {
return
}
}
if _, = fmt.Fprint(, "author "); != nil {
return
}
if = .Author.Encode(); != nil {
return
}
if _, = fmt.Fprint(, "\ncommitter "); != nil {
return
}
if = .Committer.Encode(); != nil {
return
}
if .PGPSignature != "" && {
if _, = fmt.Fprint(, "\n"+headerpgp+" "); != nil {
return
}
func ( *Commit) () (FileStats, error) {
return .StatsContext(context.Background())
}
func ( *Commit) ( context.Context) (FileStats, error) {
, := .Tree()
if != nil {
return nil,
}
:= &Tree{}
if .NumParents() != 0 {
, := .Parents().Next()
if != nil {
return nil,
}
, = .Tree()
if != nil {
return nil,
}
}
, := .PatchContext(, )
if != nil {
return nil,
}
return getFileStatsFromFilePatches(.FilePatches()), nil
}
func ( *Commit) () string {
return fmt.Sprintf(
"%s %s\nAuthor: %s\nDate: %s\n\n%s\n",
plumbing.CommitObject, .Hash, .Author.String(),
.Author.When.Format(DateFormat), indent(.Message),
)
}
:= strings.NewReader(.PGPSignature)
type storerCommitIter struct {
storer.EncodedObjectIter
s storer.EncodedObjectStorer
}
func ( storer.EncodedObjectStorer, storer.EncodedObjectIter) CommitIter {
return &storerCommitIter{, }
}
func ( *storerCommitIter) () (*Commit, error) {
, := .EncodedObjectIter.Next()
if != nil {
return nil,
}
return DecodeCommit(.s, )
}
func ( *storerCommitIter) ( func(*Commit) error) error {
return .EncodedObjectIter.ForEach(func( plumbing.EncodedObject) error {
, := DecodeCommit(.s, )
if != nil {
return
}
return ()
})
}
func ( *storerCommitIter) () {
.EncodedObjectIter.Close()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |