Skip to content

Commit f4a41a1

Browse files
authored
Merge pull request #14 from erizocosmico/fix/tree-entries-full-path
gitquery: fix tree entries output to output files with full path
2 parents 8a5a2cd + dcb54e0 commit f4a41a1

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

tree_entries.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gitquery
22

33
import (
4+
"io"
45
"strconv"
56

67
"gopkg.in/src-d/go-mysql-server.v0/sql"
@@ -57,31 +58,32 @@ func (treeEntriesTable) Children() []sql.Node {
5758

5859
type treeEntryIter struct {
5960
i *object.TreeIter
61+
fi *object.FileIter
6062
t *object.Tree
61-
ei int
6263
}
6364

6465
func (i *treeEntryIter) Next() (sql.Row, error) {
6566
for {
66-
if i.t == nil {
67-
tree, err := i.i.Next()
67+
if i.fi == nil {
68+
var err error
69+
i.t, err = i.i.Next()
6870
if err != nil {
6971
return nil, err
7072
}
7173

72-
i.t = tree
73-
i.ei = 0
74+
i.fi = i.t.Files()
7475
}
7576

76-
if i.ei >= len(i.t.Entries) {
77+
f, err := i.fi.Next()
78+
if err == io.EOF {
79+
i.fi = nil
7780
i.t = nil
7881
continue
82+
} else if err != nil {
83+
return nil, err
7984
}
8085

81-
e := i.t.Entries[i.ei]
82-
i.ei++
83-
84-
return treeEntryToRow(i.t, e), nil
86+
return fileToRow(i.t, f), nil
8587
}
8688
}
8789

@@ -90,11 +92,11 @@ func (i *treeEntryIter) Close() error {
9092
return nil
9193
}
9294

93-
func treeEntryToRow(t *object.Tree, e object.TreeEntry) sql.Row {
95+
func fileToRow(t *object.Tree, f *object.File) sql.Row {
9496
return sql.NewRow(
9597
t.ID().String(),
96-
e.Hash.String(),
97-
strconv.FormatInt(int64(e.Mode), 8),
98-
e.Name,
98+
f.Hash.String(),
99+
strconv.FormatInt(int64(f.Mode), 8),
100+
f.Name,
99101
)
100102
}

tree_entries_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

66
"gopkg.in/src-d/go-mysql-server.v0/sql"
77

8-
"gopkg.in/src-d/go-git-fixtures.v3"
98
"github.com/stretchr/testify/assert"
9+
"gopkg.in/src-d/go-git-fixtures.v3"
1010
)
1111

1212
func TestTreeEntriesTable_Name(t *testing.T) {
@@ -33,7 +33,7 @@ func TestTreeEntriesTable_RowIter(t *testing.T) {
3333

3434
rows, err := sql.NodeToRows(table)
3535
assert.Nil(err)
36-
assert.Len(rows, 45)
36+
assert.Len(rows, 49)
3737

3838
schema := table.Schema()
3939
for idx, row := range rows {

0 commit comments

Comments
 (0)