diff options
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 9e325e4..d9a1d7e 100644 --- a/repository.go +++ b/repository.go @@ -608,6 +608,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) { @@ -671,7 +691,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 @@ -838,29 +858,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 { @@ -869,21 +888,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 { |