aboutsummaryrefslogtreecommitdiffstats
path: root/commit.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-23 00:37:36 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-23 00:37:36 +0200
commit9ae3c5808fcfa468d1f9394c9b16bc02f573ba79 (patch)
tree917c5dc717c02654baeebd06bef89436ad4c65ec /commit.go
parent2ed3474ab8e52c98a87e390d5128d45d693a115d (diff)
downloadgo-git-9ae3c5808fcfa468d1f9394c9b16bc02f573ba79.tar.gz
WalkCommitHistory adn Commit.History
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/commit.go b/commit.go
index 4a4a202..4a4fe25 100644
--- a/commit.go
+++ b/commit.go
@@ -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))
+}