Skip to content

Commit a170693

Browse files
committed
Make Resolve(nil) return map of top-level objects, fixes #20
1 parent bd8ed46 commit a170693

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

commit.go

+29
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ func (pi *PersonInfo) tree(name string, depth int) []string {
7171
}
7272

7373
func (pi *PersonInfo) resolve(p []string) (interface{}, []string, error) {
74+
if p == nil {
75+
return map[string]interface{}{
76+
"name": pi.Name,
77+
"email": pi.Email,
78+
"date": pi.Date + " " + pi.Timezone,
79+
}, nil, nil
80+
}
81+
7482
switch p[0] {
7583
case "name":
7684
return pi.Name, p[1:], nil
@@ -157,6 +165,18 @@ func (c *Commit) RawData() []byte {
157165
}
158166

159167
func (c *Commit) Resolve(path []string) (interface{}, []string, error) {
168+
if path == nil {
169+
return map[string]interface{}{
170+
"parents": c.Parents,
171+
"author": c.Author,
172+
"committer": c.Committer,
173+
"signature": c.Sig.Text,
174+
"message": c.Message,
175+
"tree": &node.Link{Cid: c.GitTree},
176+
"mergetag": c.MergeTag,
177+
}, nil, nil
178+
}
179+
160180
if len(path) == 0 {
161181
return nil, nil, fmt.Errorf("zero length path")
162182
}
@@ -260,6 +280,15 @@ func (c *Commit) GitSha() []byte {
260280
}
261281

262282
func (t *MergeTag) resolve(path []string) (interface{}, []string, error) {
283+
if path == nil {
284+
return map[string]interface{}{
285+
"object": &node.Link{Cid: t.Object},
286+
"tag": t.Tag,
287+
"tagger": t.Tagger,
288+
"text": t.Text,
289+
"type": t.Type,
290+
}, nil, nil
291+
}
263292
if len(path) == 0 {
264293
return nil, nil, fmt.Errorf("zero length path")
265294
}

tag.go

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ func (t *Tag) RawData() []byte {
6464
}
6565

6666
func (t *Tag) Resolve(path []string) (interface{}, []string, error) {
67+
if path == nil {
68+
return map[string]interface{}{
69+
"object": &node.Link{Cid: t.Object},
70+
"type": t.Type,
71+
"tagger": t.Tagger,
72+
"message": t.Message,
73+
"tag": t.Tag,
74+
}, nil, nil
75+
}
6776
if len(path) == 0 {
6877
return nil, nil, fmt.Errorf("zero length path")
6978
}

tree.go

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (t *Tree) RawData() []byte {
112112
}
113113

114114
func (t *Tree) Resolve(p []string) (interface{}, []string, error) {
115+
if p == nil {
116+
return t.entries, nil, nil
117+
}
118+
115119
e, ok := t.entries[p[0]]
116120
if !ok {
117121
return nil, nil, errors.New("no such link")

0 commit comments

Comments
 (0)