From 0f1275fc30cb8162360a7e03b899478593a81c9a Mon Sep 17 00:00:00 2001 From: Sebastian Beisch Date: Wed, 11 Nov 2020 10:53:10 +0100 Subject: [PATCH] refactor(internal/git): revert list commits changes --- internal/gitutil/gitutil.go | 46 +++++++------------------------------ 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/internal/gitutil/gitutil.go b/internal/gitutil/gitutil.go index 67ec880..660a637 100644 --- a/internal/gitutil/gitutil.go +++ b/internal/gitutil/gitutil.go @@ -134,7 +134,7 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { return nil, err } - var commits []shared.Commit + commits := make(map[string]shared.Commit) var foundEnd bool err = cIter.ForEach(func(c *object.Commit) error { @@ -147,55 +147,25 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { if !foundEnd { log.Tracef("Found commit with hash %s", c.Hash.String()) - commit := shared.Commit{ + commits[c.Hash.String()] = shared.Commit{ Message: c.Message, Author: c.Committer.Name, Hash: c.Hash.String(), } - commits = append(commits, commit) - if len(c.ParentHashes) == 2 { - parent, err := g.Repository.CommitObject(c.ParentHashes[1]) - if err == nil { - commit := shared.Commit{ - Message: parent.Message, - Author: parent.Committer.Name, - Hash: parent.Hash.String(), - } - commits = append(commits, commit) - log.Tracef("Found parent check for merge commits for hash %s", c.ParentHashes[1].String()) - - commits = append(commits, g.getParents(parent)...) - } - - } } return nil }) if err != nil { - return commits, errors.Wrap(err, "Could not read commits, check git clone depth in your ci") + return nil, errors.Wrap(err, "Could not read commits, check git clone depth in your ci") } - return commits, nil -} + l := make([]shared.Commit, 0) -func (g *GitUtil) getParents(current *object.Commit) []shared.Commit { - commits := make([]shared.Commit, 0) - for _, i2 := range current.ParentHashes { - parent, err := g.Repository.CommitObject(i2) - if err != nil { - continue - } - commit := shared.Commit{ - Message: parent.Message, - Author: parent.Committer.Name, - Hash: parent.Hash.String(), - } - commits = append(commits, commit) - if len(parent.ParentHashes) == 1 { - commits = append(commits, g.getParents(parent)...) - } + for _, value := range commits { + l = append(l, value) } - return commits + + return l, nil }