Skip to content

Commit

Permalink
Further minimise changes to current release
Browse files Browse the repository at this point in the history
* mergeTag -> mergetag
* tagType -> type
  • Loading branch information
rvagg committed Jul 31, 2021
1 parent 4e0e59b commit 5200aad
Show file tree
Hide file tree
Showing 9 changed files with 3,361 additions and 3,347 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ type PersonInfo struct {
}
type Commit struct {
tree &Tree # see "Tree" section below
parents [&Commit]
message String
author optional PersonInfo
committer optional PersonInfo
message String
parents [&Commit]
tree &Tree # see "Tree" section below
encoding optional String
signature optional GpgSig
mergeTag [Tag]
mergetag [Tag]
other [String]
}
```
Expand Down Expand Up @@ -78,11 +78,11 @@ As JSON, real data would look something like:

```ipldsch
type Tag struct {
message String
object &Any
type String
tag String
tagger PersonInfo
tagType String
message String
}
```

Expand Down
14 changes: 6 additions & 8 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func DecodeCommit(na ipld.NodeAssembler, rd *bufio.Reader) error {
}

c := _Commit{
parents: _ListParents{[]_LinkCommit{}},
mergeTag: _ListTag{[]_Tag{}},
other: _ListString{[]_String{}},
parents: _Commit_Link_List{[]_Commit_Link{}},
}
for {
line, _, err := rd.ReadLine()
Expand Down Expand Up @@ -53,14 +51,14 @@ func decodeCommitLine(c Commit, line []byte, rd *bufio.Reader) error {
return err
}

c.tree = _LinkTree{cidlink.Link{Cid: shaToCid(sha)}}
c.tree = _Tree_Link{cidlink.Link{Cid: shaToCid(sha)}}
case bytes.HasPrefix(line, []byte("parent ")):
psha, err := hex.DecodeString(string(line[7:]))
if err != nil {
return err
}

c.parents.x = append(c.parents.x, _LinkCommit{cidlink.Link{Cid: shaToCid(psha)}})
c.parents.x = append(c.parents.x, _Commit_Link{cidlink.Link{Cid: shaToCid(psha)}})
case bytes.HasPrefix(line, []byte("author ")):
a, err := parsePersonInfo(line)
if err != nil {
Expand Down Expand Up @@ -88,7 +86,7 @@ func decodeCommitLine(c Commit, line []byte, rd *bufio.Reader) error {
return err
}

c.mergeTag.x = append(c.mergeTag.x, *mt)
c.mergetag.x = append(c.mergetag.x, *mt)

if rest != nil {
err = decodeCommitLine(c, rest, rd)
Expand Down Expand Up @@ -167,9 +165,9 @@ func encodeCommit(n ipld.Node, w io.Writer) error {
if c.encoding.m == schema.Maybe_Value {
fmt.Fprintf(buf, "encoding %s\n", c.encoding.v.x)
}
for _, mtag := range c.mergeTag.x {
for _, mtag := range c.mergetag.x {
fmt.Fprintf(buf, "mergetag object %s\n", hex.EncodeToString(mtag.object.sha()))
fmt.Fprintf(buf, " type %s\n", mtag.tagType.x)
fmt.Fprintf(buf, " type %s\n", mtag.typ.x)
fmt.Fprintf(buf, " tag %s\n", mtag.tag.x)
fmt.Fprintf(buf, " tagger %s\n \n", mtag.tagger.GitString())
fmt.Fprintf(buf, "%s", mtag.message.x)
Expand Down
36 changes: 24 additions & 12 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,57 @@ func main() {
ts.Init()
adjCfg := &gengo.AdjunctCfg{
CfgUnionMemlayout: map[schema.TypeName]string{},
FieldSymbolLowerOverrides: map[gengo.FieldTuple]string{
{TypeName: "Tag", FieldName: "type"}: "typ",
},
}

ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnList("ListString", "String", false))
ts.Accumulate(schema.SpawnLink("Link"))

ts.Accumulate(schema.SpawnList("String_List", "String", false))

ts.Accumulate(schema.SpawnStruct("PersonInfo", []schema.StructField{
schema.SpawnStructField("date", "String", false, false),
schema.SpawnStructField("timezone", "String", false, false),
schema.SpawnStructField("email", "String", false, false),
schema.SpawnStructField("name", "String", false, false),
}, schema.SpawnStructRepresentationMap(map[string]string{})))

ts.Accumulate(schema.SpawnString("GpgSig"))

ts.Accumulate(schema.SpawnStruct("Tag", []schema.StructField{
schema.SpawnStructField("message", "String", false, false),
schema.SpawnStructField("object", "Link", false, false),
schema.SpawnStructField("type", "String", false, false),
schema.SpawnStructField("tag", "String", false, false),
schema.SpawnStructField("tagger", "PersonInfo", false, false),
schema.SpawnStructField("tagType", "String", false, false),
schema.SpawnStructField("message", "String", false, false),
}, schema.SpawnStructRepresentationMap(map[string]string{})))
ts.Accumulate(schema.SpawnList("ListTag", "Tag", false))
ts.Accumulate(schema.SpawnLinkReference("LinkCommit", "Commit"))
ts.Accumulate(schema.SpawnList("ListParents", "LinkCommit", false))

ts.Accumulate(schema.SpawnList("Tag_List", "Tag", false))

ts.Accumulate(schema.SpawnStruct("Commit", []schema.StructField{
schema.SpawnStructField("tree", "Tree_Link", false, false),
schema.SpawnStructField("parents", "Commit_Link_List", false, false),
schema.SpawnStructField("message", "String", false, false),
schema.SpawnStructField("author", "PersonInfo", true, false),
schema.SpawnStructField("committer", "PersonInfo", true, false),
schema.SpawnStructField("message", "String", false, false),
schema.SpawnStructField("parents", "ListParents", false, false),
schema.SpawnStructField("tree", "LinkTree", false, false),
schema.SpawnStructField("encoding", "String", true, false),
schema.SpawnStructField("signature", "GpgSig", true, false),
schema.SpawnStructField("mergeTag", "ListTag", false, false),
schema.SpawnStructField("other", "ListString", false, false),
schema.SpawnStructField("mergetag", "Tag_List", false, false),
schema.SpawnStructField("other", "String_List", false, false),
}, schema.SpawnStructRepresentationMap(map[string]string{})))
ts.Accumulate(schema.SpawnLinkReference("Commit_Link", "Commit"))
ts.Accumulate(schema.SpawnList("Commit_Link_List", "Commit_Link", false))

ts.Accumulate(schema.SpawnBytes("Blob"))

ts.Accumulate(schema.SpawnMap("Tree", "String", "TreeEntry", false))
ts.Accumulate(schema.SpawnLinkReference("LinkTree", "Tree"))
ts.Accumulate(schema.SpawnStruct("TreeEntry", []schema.StructField{
schema.SpawnStructField("mode", "String", false, false),
schema.SpawnStructField("hash", "Link", false, false),
}, schema.SpawnStructRepresentationMap(map[string]string{})))
ts.Accumulate(schema.SpawnLinkReference("Tree_Link", "Tree"))

if errs := ts.ValidateGraph(); errs != nil {
for _, err := range errs {
Expand Down
6 changes: 5 additions & 1 deletion git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func testNode(t *testing.T, nd ipld.Node) error {
t.Fatalf("Tag is not a tag")
}

tt, err := tag.tagType.AsString()
tt, err := tag.typ.AsString()
assert(t, err == nil)

assert(t, tt == "commit" || tt == "tree" || tt == "blob" || tt == "tag")
Expand All @@ -222,7 +222,11 @@ func testNode(t *testing.T, nd ipld.Node) error {
}

assert(t, len(tree.m) > 0)

default:
return fmt.Errorf("unexpected or unknown NodePrototype %v", nd.Prototype())
}

return nil
}

Expand Down
Loading

0 comments on commit 5200aad

Please sign in to comment.