aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorkuba-- <kuba@sourced.tech>2019-01-03 22:47:04 +0100
committerkuba-- <kuba@sourced.tech>2019-01-07 08:52:54 +0100
commit3180dff8c5618b2e146a7fb4ac36be10851c86cc (patch)
tree88ded2ac78340fc8c4a022a90e6ea3d5de34259a /repository.go
parent791aea319719ee757cb862e83ec43b25113de2c1 (diff)
downloadgo-git-3180dff8c5618b2e146a7fb4ac36be10851c86cc.tar.gz
Implement git log --all
Signed-off-by: kuba-- <kuba@sourced.tech>
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go71
1 files changed, 47 insertions, 24 deletions
diff --git a/repository.go b/repository.go
index 1f64b9f..6be07c2 100644
--- a/repository.go
+++ b/repository.go
@@ -1027,41 +1027,64 @@ func (r *Repository) PushContext(ctx context.Context, o *PushOptions) error {
// 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
- }
-
- var commitIter object.CommitIter
+ var (
+ err error
+ commitIterFunc func(*object.Commit) object.CommitIter
+ commitIter object.CommitIter
+ )
switch o.Order {
case LogOrderDefault:
- commitIter = object.NewCommitPreorderIter(commit, nil, nil)
+ commitIterFunc = func(c *object.Commit) object.CommitIter {
+ return object.NewCommitPreorderIter(c, nil, nil)
+ }
case LogOrderDFS:
- commitIter = object.NewCommitPreorderIter(commit, nil, nil)
+ commitIterFunc = func(c *object.Commit) object.CommitIter {
+ return object.NewCommitPreorderIter(c, nil, nil)
+ }
case LogOrderDFSPost:
- commitIter = object.NewCommitPostorderIter(commit, nil)
+ commitIterFunc = func(c *object.Commit) object.CommitIter {
+ return object.NewCommitPostorderIter(c, nil)
+ }
case LogOrderBSF:
- commitIter = object.NewCommitIterBSF(commit, nil, nil)
+ commitIterFunc = func(c *object.Commit) object.CommitIter {
+ return object.NewCommitIterBSF(c, nil, nil)
+ }
case LogOrderCommitterTime:
- commitIter = object.NewCommitIterCTime(commit, nil, nil)
+ commitIterFunc = func(c *object.Commit) object.CommitIter {
+ return object.NewCommitIterCTime(c, nil, nil)
+ }
default:
return nil, fmt.Errorf("invalid Order=%v", o.Order)
}
- if o.FileName == nil {
- return commitIter, nil
+ if o.All {
+ commitIter, err = object.NewCommitAllIter(r.Storer, commitIterFunc)
+ if err != nil {
+ return nil, err
+ }
+ } else {
+ 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
+ }
+ commitIter = commitIterFunc(commit)
}
- return object.NewCommitFileIterFromIter(*o.FileName, commitIter), nil
+
+ if o.FileName != nil {
+ commitIter = object.NewCommitFileIterFromIter(*o.FileName, commitIter, o.All)
+ }
+
+ return commitIter, nil
}
// Tags returns all the tag References in a repository.