Skip to content

Commit 0436bc7

Browse files
committed
Match original field names, tree as map
1 parent da7812f commit 0436bc7

9 files changed

+1839
-1137
lines changed

commit.go

+28-28
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func DecodeCommit(na ipld.NodeAssembler, rd *bufio.Reader) error {
2323
}
2424

2525
c := _Commit{
26-
Parents: _ListParents{[]_Link{}},
27-
MergeTag: _ListTag{[]_Tag{}},
28-
Other: _ListString{[]_String{}},
26+
parents: _ListParents{[]_Link{}},
27+
mergeTag: _ListTag{[]_Tag{}},
28+
other: _ListString{[]_String{}},
2929
}
3030
for {
3131
line, _, err := rd.ReadLine()
@@ -53,30 +53,30 @@ func decodeCommitLine(c Commit, line []byte, rd *bufio.Reader) error {
5353
return err
5454
}
5555

56-
c.GitTree = _LinkTree{cidlink.Link{Cid: shaToCid(sha)}}
56+
c.tree = _LinkTree{cidlink.Link{Cid: shaToCid(sha)}}
5757
case bytes.HasPrefix(line, []byte("parent ")):
5858
psha, err := hex.DecodeString(string(line[7:]))
5959
if err != nil {
6060
return err
6161
}
6262

63-
c.Parents.x = append(c.Parents.x, _Link{cidlink.Link{Cid: shaToCid(psha)}})
63+
c.parents.x = append(c.parents.x, _Link{cidlink.Link{Cid: shaToCid(psha)}})
6464
case bytes.HasPrefix(line, []byte("author ")):
6565
a, err := parsePersonInfo(line)
6666
if err != nil {
6767
return err
6868
}
6969

70-
c.Author = _PersonInfo__Maybe{m: schema.Maybe_Value, v: a}
70+
c.author = _PersonInfo__Maybe{m: schema.Maybe_Value, v: a}
7171
case bytes.HasPrefix(line, []byte("committer ")):
7272
com, err := parsePersonInfo(line)
7373
if err != nil {
7474
return err
7575
}
7676

77-
c.Committer = _PersonInfo__Maybe{m: schema.Maybe_Value, v: com}
77+
c.committer = _PersonInfo__Maybe{m: schema.Maybe_Value, v: com}
7878
case bytes.HasPrefix(line, []byte("encoding ")):
79-
c.Encoding = _String__Maybe{m: schema.Maybe_Value, v: &_String{string(line[9:])}}
79+
c.encoding = _String__Maybe{m: schema.Maybe_Value, v: &_String{string(line[9:])}}
8080
case bytes.HasPrefix(line, []byte("mergetag object ")):
8181
sha, err := hex.DecodeString(string(line)[prefixMergetag:])
8282
if err != nil {
@@ -88,7 +88,7 @@ func decodeCommitLine(c Commit, line []byte, rd *bufio.Reader) error {
8888
return err
8989
}
9090

91-
c.MergeTag.x = append(c.MergeTag.x, *mt)
91+
c.mergeTag.x = append(c.mergeTag.x, *mt)
9292

9393
if rest != nil {
9494
err = decodeCommitLine(c, rest, rd)
@@ -101,16 +101,16 @@ func decodeCommitLine(c Commit, line []byte, rd *bufio.Reader) error {
101101
if err != nil {
102102
return err
103103
}
104-
c.Sig = _GpgSig__Maybe{m: schema.Maybe_Value, v: sig}
104+
c.signature = _GpgSig__Maybe{m: schema.Maybe_Value, v: sig}
105105
case len(line) == 0:
106106
rest, err := ioutil.ReadAll(rd)
107107
if err != nil {
108108
return err
109109
}
110110

111-
c.Message = _String{string(rest)}
111+
c.message = _String{string(rest)}
112112
default:
113-
c.Other.x = append(c.Other.x, _String{string(line)})
113+
c.other.x = append(c.other.x, _String{string(line)})
114114
}
115115
return nil
116116
}
@@ -158,31 +158,31 @@ func encodeCommit(n ipld.Node, w io.Writer) error {
158158

159159
buf := new(bytes.Buffer)
160160

161-
fmt.Fprintf(buf, "tree %s\n", hex.EncodeToString(c.GitTree.sha()))
162-
for _, p := range c.Parents.x {
161+
fmt.Fprintf(buf, "tree %s\n", hex.EncodeToString(c.tree.sha()))
162+
for _, p := range c.parents.x {
163163
fmt.Fprintf(buf, "parent %s\n", hex.EncodeToString(p.sha()))
164164
}
165-
fmt.Fprintf(buf, "author %s\n", c.Author.v.GitString())
166-
fmt.Fprintf(buf, "committer %s\n", c.Committer.v.GitString())
167-
if c.Encoding.m == schema.Maybe_Value {
168-
fmt.Fprintf(buf, "encoding %s\n", c.Encoding.v.x)
165+
fmt.Fprintf(buf, "author %s\n", c.author.v.GitString())
166+
fmt.Fprintf(buf, "committer %s\n", c.committer.v.GitString())
167+
if c.encoding.m == schema.Maybe_Value {
168+
fmt.Fprintf(buf, "encoding %s\n", c.encoding.v.x)
169169
}
170-
for _, mtag := range c.MergeTag.x {
171-
fmt.Fprintf(buf, "mergetag object %s\n", hex.EncodeToString(mtag.Object.sha()))
172-
fmt.Fprintf(buf, " type %s\n", mtag.TagType.x)
173-
fmt.Fprintf(buf, " tag %s\n", mtag.Tag.x)
174-
fmt.Fprintf(buf, " tagger %s\n \n", mtag.Tagger.GitString())
175-
fmt.Fprintf(buf, "%s", mtag.Text.x)
170+
for _, mtag := range c.mergeTag.x {
171+
fmt.Fprintf(buf, "mergetag object %s\n", hex.EncodeToString(mtag.object.sha()))
172+
fmt.Fprintf(buf, " type %s\n", mtag.tagType.x)
173+
fmt.Fprintf(buf, " tag %s\n", mtag.tag.x)
174+
fmt.Fprintf(buf, " tagger %s\n \n", mtag.tagger.GitString())
175+
fmt.Fprintf(buf, "%s", mtag.text.x)
176176
}
177-
if c.Sig.m == schema.Maybe_Value {
177+
if c.signature.m == schema.Maybe_Value {
178178
fmt.Fprintln(buf, "gpgsig -----BEGIN PGP SIGNATURE-----")
179-
fmt.Fprint(buf, c.Sig.v.x)
179+
fmt.Fprint(buf, c.signature.v.x)
180180
fmt.Fprintln(buf, " -----END PGP SIGNATURE-----")
181181
}
182-
for _, line := range c.Other.x {
182+
for _, line := range c.other.x {
183183
fmt.Fprintln(buf, line.x)
184184
}
185-
fmt.Fprintf(buf, "\n%s", c.Message.x)
185+
fmt.Fprintf(buf, "\n%s", c.message.x)
186186

187187
fmt.Printf("encode commit len: %d \n", buf.Len())
188188
// fmt.Printf("out: %s\n", string(buf.Bytes()))

gen/gen.go

+24-26
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,39 @@ func main() {
1818
ts.Accumulate(schema.SpawnList("ListString", "String", false))
1919
ts.Accumulate(schema.SpawnLink("Link"))
2020
ts.Accumulate(schema.SpawnStruct("PersonInfo", []schema.StructField{
21-
schema.SpawnStructField("Name", "String", false, false),
22-
schema.SpawnStructField("Email", "String", false, false),
23-
schema.SpawnStructField("Date", "String", false, false),
24-
schema.SpawnStructField("Timezone", "String", false, false),
25-
}, schema.SpawnStructRepresentationStringjoin(" ")))
21+
schema.SpawnStructField("name", "String", false, false),
22+
schema.SpawnStructField("email", "String", false, false),
23+
schema.SpawnStructField("date", "String", false, false),
24+
schema.SpawnStructField("timezone", "String", false, false),
25+
}, schema.SpawnStructRepresentationMap(map[string]string{})))
2626
ts.Accumulate(schema.SpawnString("GpgSig"))
2727
ts.Accumulate(schema.SpawnStruct("Tag", []schema.StructField{
28-
schema.SpawnStructField("Object", "Link", false, false),
29-
schema.SpawnStructField("TagType", "String", false, false),
30-
schema.SpawnStructField("Tag", "String", false, false),
31-
schema.SpawnStructField("Tagger", "PersonInfo", false, false),
32-
schema.SpawnStructField("Text", "String", false, false),
33-
}, schema.SpawnStructRepresentationMap(map[string]string{"Type": "TagType"})))
28+
schema.SpawnStructField("object", "Link", false, false),
29+
schema.SpawnStructField("tagType", "String", false, false),
30+
schema.SpawnStructField("tag", "String", false, false),
31+
schema.SpawnStructField("tagger", "PersonInfo", false, false),
32+
schema.SpawnStructField("text", "String", false, false),
33+
}, schema.SpawnStructRepresentationMap(map[string]string{})))
3434
ts.Accumulate(schema.SpawnList("ListTag", "Tag", false))
3535
ts.Accumulate(schema.SpawnList("ListParents", "Link", false)) //Todo: type 'Parents' links
3636
ts.Accumulate(schema.SpawnStruct("Commit", []schema.StructField{
37-
schema.SpawnStructField("GitTree", "LinkTree", false, false),
38-
schema.SpawnStructField("Parents", "ListParents", false, false),
39-
schema.SpawnStructField("Message", "String", false, false),
40-
schema.SpawnStructField("Author", "PersonInfo", true, false),
41-
schema.SpawnStructField("Committer", "PersonInfo", true, false),
42-
schema.SpawnStructField("Encoding", "String", true, false),
43-
schema.SpawnStructField("Sig", "GpgSig", true, false),
44-
schema.SpawnStructField("MergeTag", "ListTag", false, false),
45-
schema.SpawnStructField("Other", "ListString", false, false),
37+
schema.SpawnStructField("tree", "LinkTree", false, false),
38+
schema.SpawnStructField("parents", "ListParents", false, false),
39+
schema.SpawnStructField("message", "String", false, false),
40+
schema.SpawnStructField("author", "PersonInfo", true, false),
41+
schema.SpawnStructField("committer", "PersonInfo", true, false),
42+
schema.SpawnStructField("encoding", "String", true, false),
43+
schema.SpawnStructField("signature", "GpgSig", true, false),
44+
schema.SpawnStructField("mergeTag", "ListTag", false, false),
45+
schema.SpawnStructField("other", "ListString", false, false),
4646
}, schema.SpawnStructRepresentationMap(map[string]string{})))
4747
ts.Accumulate(schema.SpawnBytes("Blob"))
48-
49-
ts.Accumulate(schema.SpawnList("Tree", "TreeEntry", false))
48+
ts.Accumulate(schema.SpawnMap("Tree", "String", "TreeEntry", false))
5049
ts.Accumulate(schema.SpawnLinkReference("LinkTree", "Tree"))
5150
ts.Accumulate(schema.SpawnStruct("TreeEntry", []schema.StructField{
52-
schema.SpawnStructField("Mode", "String", false, false),
53-
schema.SpawnStructField("Name", "String", false, false),
54-
schema.SpawnStructField("Hash", "Link", false, false),
55-
}, schema.SpawnStructRepresentationStringjoin(" ")))
51+
schema.SpawnStructField("mode", "String", false, false),
52+
schema.SpawnStructField("hash", "Link", false, false),
53+
}, schema.SpawnStructRepresentationMap(map[string]string{})))
5654

5755
if errs := ts.ValidateGraph(); errs != nil {
5856
for _, err := range errs {

git_test.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
func TestObjectParse(t *testing.T) {
21-
lb := cidlink.LinkPrototype{cid.Prefix{
21+
lb := cidlink.LinkPrototype{Prefix: cid.Prefix{
2222
Version: 1,
2323
Codec: cid.GitRaw,
2424
MhType: 0x11,
@@ -93,7 +93,7 @@ func TestObjectParse(t *testing.T) {
9393
}
9494

9595
func TestArchiveObjectParse(t *testing.T) {
96-
lb := cidlink.LinkPrototype{cid.Prefix{
96+
lb := cidlink.LinkPrototype{Prefix: cid.Prefix{
9797
Version: 1,
9898
Codec: cid.GitRaw,
9999
MhType: 0x11,
@@ -201,25 +201,25 @@ func testNode(t *testing.T, nd ipld.Node) error {
201201
t.Fatalf("Commit is not a commit")
202202
}
203203

204-
assert(t, !commit.GitTree.IsNull())
204+
assert(t, !commit.tree.IsNull())
205205
case Type.Tag:
206206
tag, ok := nd.(Tag)
207207
if !ok {
208208
t.Fatalf("Tag is not a tag")
209209
}
210210

211-
tt, err := tag.TagType.AsString()
211+
tt, err := tag.tagType.AsString()
212212
assert(t, err == nil)
213213
assert(t, tt == "commit" || tt == "tree" || tt == "blob" || tt == "tag")
214-
assert(t, !tag.Object.IsNull())
214+
assert(t, !tag.object.IsNull())
215215

216216
case Type.Tree:
217217
tree, ok := nd.(Tree)
218218
if !ok {
219219
t.Fatalf("Tree is not a tree")
220220
}
221221

222-
assert(t, len(tree.x) > 0)
222+
assert(t, len(tree.m) > 0)
223223
}
224224
return nil
225225
}
@@ -234,25 +234,25 @@ func TestParsePersonInfo(t *testing.T) {
234234
t.Fatal("not equal:", string(p1), "vs: ", pi.GitString())
235235
}
236236

237-
if d, err := pi.LookupByString("Date"); err != nil {
237+
if d, err := pi.LookupByString("date"); err != nil {
238238
t.Fatalf("invalid date, got %s\n", err)
239239
} else if ds, _ := d.AsString(); ds != "123456" {
240240
t.Fatalf("invalid date, got %s\n", ds)
241241
}
242242

243-
if d, err := pi.LookupByString("Timezone"); err != nil {
243+
if d, err := pi.LookupByString("timezone"); err != nil {
244244
t.Fatalf("invalid timezone, got %s\n", err)
245245
} else if ds, _ := d.AsString(); ds != "+0123" {
246246
t.Fatalf("invalid timezone, got %s\n", ds)
247247
}
248248

249-
if d, err := pi.LookupByString("Email"); err != nil {
249+
if d, err := pi.LookupByString("email"); err != nil {
250250
t.Fatalf("invalid email, got %s\n", err)
251251
} else if ds, _ := d.AsString(); ds != "[email protected]" {
252252
t.Fatalf("invalid email, got %s\n", ds)
253253
}
254254

255-
if d, err := pi.LookupByString("Name"); err != nil {
255+
if d, err := pi.LookupByString("name"); err != nil {
256256
t.Fatalf("invalid name, got %s\n", err)
257257
} else if ds, _ := d.AsString(); ds != "Someone" {
258258
t.Fatalf("invalid name, got %s\n", ds)
@@ -267,7 +267,7 @@ func TestParsePersonInfo(t *testing.T) {
267267
t.Fatal("not equal", p2, pi.GitString())
268268
}
269269

270-
if d, err := pi.LookupByString("Name"); err != nil {
270+
if d, err := pi.LookupByString("name"); err != nil {
271271
t.Fatalf("invalid name, got %s\n", err)
272272
} else if ds, _ := d.AsString(); ds != "So Me One" {
273273
t.Fatalf("invalid name, got %s\n", ds)
@@ -281,25 +281,25 @@ func TestParsePersonInfo(t *testing.T) {
281281
if !bytes.Equal([]byte(pi.GitString()), p3[7:]) {
282282
t.Fatal("not equal", p3, pi.GitString())
283283
}
284-
if d, err := pi.LookupByString("Date"); err != nil {
284+
if d, err := pi.LookupByString("date"); err != nil {
285285
t.Fatalf("invalid date, got %s\n", err)
286286
} else if ds, _ := d.AsString(); ds != "987654" {
287287
t.Fatalf("invalid date, got %s\n", ds)
288288
}
289289

290-
if d, err := pi.LookupByString("Timezone"); err != nil {
290+
if d, err := pi.LookupByString("timezone"); err != nil {
291291
t.Fatalf("invalid tz, got %s\n", err)
292292
} else if ds, _ := d.AsString(); ds != "+4321" {
293293
t.Fatalf("invalid tz, got %s\n", ds)
294294
}
295295

296-
if d, err := pi.LookupByString("Email"); err != nil {
296+
if d, err := pi.LookupByString("email"); err != nil {
297297
t.Fatalf("invalid email, got %s\n", err)
298298
} else if ds, _ := d.AsString(); ds != "[email protected], [email protected]" {
299299
t.Fatalf("invalid email, got %s\n", ds)
300300
}
301301

302-
if d, err := pi.LookupByString("Name"); err != nil {
302+
if d, err := pi.LookupByString("name"); err != nil {
303303
t.Fatalf("invalid name, got %s\n", err)
304304
} else if ds, _ := d.AsString(); ds != "Some One & Other One" {
305305
t.Fatalf("invalid name, got %s\n", ds)
@@ -314,25 +314,25 @@ func TestParsePersonInfo(t *testing.T) {
314314
t.Fatal("not equal", p4, pi.GitString())
315315
}
316316

317-
if d, err := pi.LookupByString("Name"); err != nil {
317+
if d, err := pi.LookupByString("name"); err != nil {
318318
t.Fatalf("invalid name, got %s\n", err)
319319
} else if ds, _ := d.AsString(); ds != "" {
320320
t.Fatalf("invalid name, got %s\n", ds)
321321
}
322322

323-
if d, err := pi.LookupByString("Email"); err != nil {
323+
if d, err := pi.LookupByString("email"); err != nil {
324324
t.Fatalf("invalid email, got %s\n", err)
325325
} else if ds, _ := d.AsString(); ds != "[email protected]" {
326326
t.Fatalf("invalid email, got %s\n", ds)
327327
}
328328

329-
if d, err := pi.LookupByString("Date"); err != nil {
329+
if d, err := pi.LookupByString("date"); err != nil {
330330
t.Fatalf("invalid date, got %s\n", err)
331331
} else if ds, _ := d.AsString(); ds != "987654" {
332332
t.Fatalf("invalid date, got %s\n", ds)
333333
}
334334

335-
if d, err := pi.LookupByString("Timezone"); err != nil {
335+
if d, err := pi.LookupByString("timezone"); err != nil {
336336
t.Fatalf("invalid tz, got %s\n", err)
337337
} else if ds, _ := d.AsString(); ds != "+4321" {
338338
t.Fatalf("invalid tz, got %s\n", ds)
@@ -347,7 +347,7 @@ func TestParsePersonInfo(t *testing.T) {
347347
t.Fatal("not equal", p5, pi.GitString())
348348
}
349349

350-
if d, err := pi.LookupByString("Name"); err != nil {
350+
if d, err := pi.LookupByString("name"); err != nil {
351351
t.Fatalf("invalid name, got %s\n", err)
352352
} else if ds, _ := d.AsString(); ds != "Someone " {
353353
t.Fatalf("invalid name, got %s\n", ds)
@@ -423,7 +423,7 @@ func BenchmarkRawData(b *testing.B) {
423423
}
424424

425425
func BenchmarkCid(b *testing.B) {
426-
lb := cidlink.LinkPrototype{cid.Prefix{
426+
lb := cidlink.LinkPrototype{Prefix: cid.Prefix{
427427
Version: 1,
428428
Codec: cid.GitRaw,
429429
MhType: 0x11,

0 commit comments

Comments
 (0)