diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-23 00:37:36 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-23 00:37:36 +0200 |
commit | 9ae3c5808fcfa468d1f9394c9b16bc02f573ba79 (patch) | |
tree | 917c5dc717c02654baeebd06bef89436ad4c65ec /commit.go | |
parent | 2ed3474ab8e52c98a87e390d5128d45d693a115d (diff) | |
download | go-git-9ae3c5808fcfa468d1f9394c9b16bc02f573ba79.tar.gz |
WalkCommitHistory adn Commit.History
Diffstat (limited to 'commit.go')
-rw-r--r-- | commit.go | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -125,6 +125,18 @@ func (c *Commit) Decode(o core.Object) (err error) { } } +// History return a slice with the previous commits in the history of this commit +func (c *Commit) History() ([]*Commit, error) { + var commits []*Commit + err := WalkCommitHistory(c, func(commit *Commit) error { + commits = append(commits, commit) + return nil + }) + + ReverseSortCommits(commits) + return commits, err +} + func (c *Commit) String() string { return fmt.Sprintf( "%s %s\nAuthor: %s\nDate: %s\n", @@ -193,3 +205,9 @@ func SortCommits(l []*Commit) { s := &commitSorterer{l} sort.Sort(s) } + +// ReverseSortCommits sort a commit list by commit date, from newer to older. +func ReverseSortCommits(l []*Commit) { + s := &commitSorterer{l} + sort.Sort(sort.Reverse(s)) +} |