aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2019-02-12 15:57:50 +0100
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2019-02-12 17:09:04 +0100
commit6c2a0daafcd6c8f3f695c8b7a2c881d3abc276b1 (patch)
tree68de2b80ea57b3179e280a63ef1c64c143e60872 /plumbing
parenta1f6ef44dfed1253ef7f3bc049f66b15f8fc2ab2 (diff)
downloadgo-git-6c2a0daafcd6c8f3f695c8b7a2c881d3abc276b1.tar.gz
Ignore missing references on log --all
To mimic the actual standard git behavior, we must ignore references that are pointing to wrong/unexistent objects. Signed-off-by: Antonio Jesus Navarro Perez <antnavper@gmail.com>
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/commit_walker.go34
1 files changed, 23 insertions, 11 deletions
diff --git a/plumbing/object/commit_walker.go b/plumbing/object/commit_walker.go
index 8c76557..fabd0c9 100644
--- a/plumbing/object/commit_walker.go
+++ b/plumbing/object/commit_walker.go
@@ -197,26 +197,38 @@ func NewCommitAllIter(repoStorer storage.Storer, commitIterFunc func(*Commit) Co
commitsPath := list.New()
commitsLookup := make(map[plumbing.Hash]*list.Element)
head, err := storer.ResolveReference(repoStorer, plumbing.HEAD)
- if err != nil {
+ if err != nil && err != plumbing.ErrReferenceNotFound {
return nil, err
+ } else if err != plumbing.ErrReferenceNotFound {
+ if err = addReference(repoStorer, commitIterFunc, head, commitsPath, commitsLookup); err != nil {
+ return nil, err
+ }
}
// add all references along with the HEAD
- if err = addReference(repoStorer, commitIterFunc, head, commitsPath, commitsLookup); err != nil {
- return nil, err
- }
refIter, err := repoStorer.IterReferences()
if err != nil {
return nil, err
}
defer refIter.Close()
- err = refIter.ForEach(
- func(ref *plumbing.Reference) error {
- return addReference(repoStorer, commitIterFunc, ref, commitsPath, commitsLookup)
- },
- )
- if err != nil {
- return nil, err
+
+ for {
+ ref, err := refIter.Next()
+ if err == io.EOF {
+ break
+ }
+
+ if err == plumbing.ErrReferenceNotFound {
+ continue
+ }
+
+ if err != nil {
+ return nil, err
+ }
+
+ if err = addReference(repoStorer, commitIterFunc, ref, commitsPath, commitsLookup); err != nil {
+ return nil, err
+ }
}
return &commitAllIterator{commitsPath.Front()}, nil