Skip to content

Commit 8f0e305

Browse files
committed
gitbase: ignore references not pointing to commit objects
Signed-off-by: Miguel Molina <[email protected]>
1 parent 3068d27 commit 8f0e305

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

commits.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,45 +215,51 @@ func newCommitIter(
215215
}, nil
216216
}
217217

218-
func (i *commitIter) loadNextRef() (skip bool, err error) {
219-
if i.refs == nil {
220-
return false, io.EOF
221-
}
218+
func (i *commitIter) loadNextRef() (err error) {
219+
for {
220+
if i.refs == nil {
221+
return io.EOF
222+
}
222223

223-
i.ref, err = i.refs.Next()
224-
if err != nil {
225-
if err == io.EOF {
226-
return false, io.EOF
224+
i.ref, err = i.refs.Next()
225+
if err != nil {
226+
if err != io.EOF && i.skipGitErrors {
227+
continue
228+
}
229+
230+
return err
227231
}
228232

229-
if i.skipGitErrors {
230-
return true, nil
233+
if i.ref.Type() != plumbing.HashReference {
234+
i.ref = nil
235+
continue
231236
}
232237

233-
return false, err
234-
}
238+
obj, err := i.repo.Object(plumbing.AnyObject, i.ref.Hash())
239+
if err != nil {
240+
if i.skipGitErrors {
241+
continue
242+
}
235243

236-
if i.ref.Type() != plumbing.HashReference {
237-
i.ref = nil
238-
return true, nil
239-
}
244+
return err
245+
}
246+
247+
if obj.Type() != plumbing.CommitObject {
248+
continue
249+
}
240250

241-
i.queue = append(i.queue, i.ref.Hash())
251+
i.queue = append(i.queue, i.ref.Hash())
242252

243-
return false, nil
253+
return nil
254+
}
244255
}
245256

246257
func (i *commitIter) Next() (*object.Commit, error) {
247258
for {
248259
if i.ref == nil {
249-
skip, err := i.loadNextRef()
250-
if err != nil {
260+
if err := i.loadNextRef(); err != nil {
251261
return nil, err
252262
}
253-
254-
if skip {
255-
continue
256-
}
257263
}
258264

259265
if len(i.queue) == 0 {

integration_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,23 @@ func TestIntegration(t *testing.T) {
329329
{"Ignore List", int32(1)},
330330
},
331331
},
332+
{
333+
`
334+
SELECT
335+
repository_id,
336+
contributor_count
337+
FROM (
338+
SELECT
339+
repository_id,
340+
COUNT(DISTINCT commit_author_email) AS contributor_count
341+
FROM commits
342+
GROUP BY repository_id
343+
) AS q
344+
ORDER BY contributor_count DESC
345+
LIMIT 10
346+
`,
347+
[]sql.Row{{"worktree", int32(9)}},
348+
},
332349
}
333350

334351
runTests := func(t *testing.T) {

0 commit comments

Comments
 (0)