diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-11 23:16:48 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-11 23:16:48 +0200 |
commit | 7a428a915ce2b7bb0f4fc6dcee77932ebacfabbf (patch) | |
tree | a116c49d89ae0450c9999a85896d1a10ba7d8a0b /repository.go | |
parent | 116fed7ea746255805f5664d9b6fd7cdb1b52663 (diff) | |
parent | 9b45f468c61a0756dd19d09b64c2b1a88cc99ec5 (diff) | |
download | go-git-7a428a915ce2b7bb0f4fc6dcee77932ebacfabbf.tar.gz |
merge, Repository.Log
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 71 |
1 files changed, 45 insertions, 26 deletions
diff --git a/repository.go b/repository.go index 71a53e7..2fdbafc 100644 --- a/repository.go +++ b/repository.go @@ -610,6 +610,26 @@ func (r *Repository) Push(o *PushOptions) error { return remote.Push(o) } +// Log returns the commit history from the given LogOptions. +func (r *Repository) Log(o *LogOptions) (object.CommitIter, error) { + h := o.From + if o.From == plumbing.ZeroHash { + head, err := r.Head() + if err != nil { + return nil, err + } + + h = head.Hash() + } + + commit, err := r.CommitObject(h) + if err != nil { + return nil, err + } + + return object.NewCommitPreIterator(commit), nil +} + // Tags returns all the References from Tags. This method returns all the tag // types, lightweight, and annotated ones. func (r *Repository) Tags() (storer.ReferenceIter, error) { @@ -673,7 +693,7 @@ func (r *Repository) CommitObject(h plumbing.Hash) (*object.Commit, error) { } // CommitObjects returns an unsorted CommitIter with all the commits in the repository. -func (r *Repository) CommitObjects() (*object.CommitIter, error) { +func (r *Repository) CommitObjects() (object.CommitIter, error) { iter, err := r.Storer.IterEncodedObjects(plumbing.CommitObject) if err != nil { return nil, err @@ -840,29 +860,28 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err commit = c } case revision.CaretReg: - history, err := commit.History() - - if err != nil { - return &plumbing.ZeroHash, err - } + history := object.NewCommitPreIterator(commit) re := item.(revision.CaretReg).Regexp negate := item.(revision.CaretReg).Negate var c *object.Commit - for i := 0; i < len(history); i++ { - if !negate && re.MatchString(history[i].Message) { - c = history[i] - - break + err := history.ForEach(func(hc *object.Commit) error { + if !negate && re.MatchString(hc.Message) { + c = hc + return storer.ErrStop } - if negate && !re.MatchString(history[i].Message) { - c = history[i] - - break + if negate && !re.MatchString(hc.Message) { + c = hc + return storer.ErrStop } + + return nil + }) + if err != nil { + return &plumbing.ZeroHash, err } if c == nil { @@ -871,21 +890,21 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err commit = c case revision.AtDate: - history, err := commit.History() - - if err != nil { - return &plumbing.ZeroHash, err - } + history := object.NewCommitPreIterator(commit) date := item.(revision.AtDate).Date - var c *object.Commit - for i := 0; i < len(history); i++ { - if date.Equal(history[i].Committer.When.UTC()) || history[i].Committer.When.UTC().Before(date) { - c = history[i] - - break + var c *object.Commit + err := history.ForEach(func(hc *object.Commit) error { + if date.Equal(hc.Committer.When.UTC()) || hc.Committer.When.UTC().Before(date) { + c = hc + return storer.ErrStop } + + return nil + }) + if err != nil { + return &plumbing.ZeroHash, err } if c == nil { |