From 87fd4b982832b0b1e8ae1581af26278762dd3a29 Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Fri, 29 Nov 2019 13:18:00 +0100 Subject: [PATCH] Fix --head with siva files Signed-off-by: Vadim Markovtsev --- internal/core/pipeline.go | 54 ++++++++++++++++++--------------------- python/setup.py | 2 +- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/internal/core/pipeline.go b/internal/core/pipeline.go index 3793331f..c4394bb0 100644 --- a/internal/core/pipeline.go +++ b/internal/core/pipeline.go @@ -450,33 +450,14 @@ func (pipeline *Pipeline) Len() int { func (pipeline *Pipeline) Commits(firstParent bool) ([]*object.Commit, error) { var result []*object.Commit repository := pipeline.repository - head, err := repository.Head() + heads, err := pipeline.HeadCommit() if err != nil { - if err == plumbing.ErrReferenceNotFound { - refs, errr := repository.References() - if errr != nil { - return nil, errors.Wrap(errr, "unable to list the references") - } - refs.ForEach(func(ref *plumbing.Reference) error { - if strings.HasPrefix(ref.Name().String(), "refs/heads/HEAD/") { - head = ref - return storer.ErrStop - } - return nil - }) - } - if head == nil && err != nil { - return nil, errors.Wrap(err, "unable to collect the commit history") - } + return nil, err } - + head := heads[0] if firstParent { - commit, err := repository.CommitObject(head.Hash()) - if err != nil { - panic(err) - } // the first parent matches the head - for ; err != io.EOF; commit, err = commit.Parents().Next() { + for commit := head; err != io.EOF; commit, err = commit.Parents().Next() { if err != nil { panic(err) } @@ -488,26 +469,41 @@ func (pipeline *Pipeline) Commits(firstParent bool) ([]*object.Commit, error) { } return result, nil } - cit, err := repository.Log(&git.LogOptions{From: head.Hash()}) + cit, err := repository.Log(&git.LogOptions{From: head.Hash}) if err != nil { return nil, errors.Wrap(err, "unable to collect the commit history") } defer cit.Close() - cit.ForEach(func(commit *object.Commit) error { + err = cit.ForEach(func(commit *object.Commit) error { result = append(result, commit) return nil }) - return result, nil + return result, err } // HeadCommit returns the latest commit in the repository (HEAD). func (pipeline *Pipeline) HeadCommit() ([]*object.Commit, error) { repository := pipeline.repository - headref, err := repository.Head() + head, err := repository.Head() if err != nil { - return nil, err + if err == plumbing.ErrReferenceNotFound { + refs, errr := repository.References() + if errr != nil { + return nil, errors.Wrap(errr, "unable to list the references") + } + err = refs.ForEach(func(ref *plumbing.Reference) error { + if strings.HasPrefix(ref.Name().String(), "refs/heads/HEAD/") { + head = ref + return storer.ErrStop + } + return nil + }) + } + } + if head == nil { + return nil, errors.Wrap(err, "unable to find the head reference") } - commit, err := repository.CommitObject(headref.Hash()) + commit, err := repository.CommitObject(head.Hash()) if err != nil { return nil, err } diff --git a/python/setup.py b/python/setup.py index 98b0064f..a29e2b5e 100644 --- a/python/setup.py +++ b/python/setup.py @@ -22,7 +22,7 @@ description="Python companion for github.com/src-d/hercules to visualize the results.", long_description=long_description, long_description_content_type="text/markdown", - version="10.6.0", + version="10.6.1", license="Apache-2.0", author="source{d}", author_email="machine-learning@sourced.tech",