forked from src-d/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request src-d#1206 from knqyf263/feature/add_log_limiting
Add limiting options to git log
- Loading branch information
Showing
5 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package object | ||
|
||
import ( | ||
"io" | ||
"time" | ||
|
||
"gopkg.in/src-d/go-git.v4/plumbing/storer" | ||
) | ||
|
||
type commitLimitIter struct { | ||
sourceIter CommitIter | ||
limitOptions LogLimitOptions | ||
} | ||
|
||
type LogLimitOptions struct { | ||
Since *time.Time | ||
Until *time.Time | ||
} | ||
|
||
func NewCommitLimitIterFromIter(commitIter CommitIter, limitOptions LogLimitOptions) CommitIter { | ||
iterator := new(commitLimitIter) | ||
iterator.sourceIter = commitIter | ||
iterator.limitOptions = limitOptions | ||
return iterator | ||
} | ||
|
||
func (c *commitLimitIter) Next() (*Commit, error) { | ||
for { | ||
commit, err := c.sourceIter.Next() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if c.limitOptions.Since != nil && commit.Committer.When.Before(*c.limitOptions.Since) { | ||
continue | ||
} | ||
if c.limitOptions.Until != nil && commit.Committer.When.After(*c.limitOptions.Until) { | ||
continue | ||
} | ||
return commit, nil | ||
} | ||
} | ||
|
||
func (c *commitLimitIter) ForEach(cb func(*Commit) error) error { | ||
for { | ||
commit, nextErr := c.Next() | ||
if nextErr == io.EOF { | ||
break | ||
} | ||
if nextErr != nil { | ||
return nextErr | ||
} | ||
err := cb(commit) | ||
if err == storer.ErrStop { | ||
return nil | ||
} else if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *commitLimitIter) Close() { | ||
c.sourceIter.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters