-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update go-ipld-git to a go-ipld-prime codec (#46)
Codec re-written as an IPLD-prime codec.
- Loading branch information
Showing
23 changed files
with
9,918 additions
and
1,268 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# CHANGELOG | ||
|
||
## v0.1.0 | ||
|
||
This release includes BREAKING CHANGES | ||
|
||
* go-ipld-git is now a [go-ipld-prime](https://github.com/ipld/go-ipld-prime) IPLD codec. Use `Decode(na ipld.NodeAssembler, r io.Reader) error` and `Encode(n ipld.Node, w io.Writer) error` for direct use if required. | ||
* There is now only one `Tag` type, `MergeTag` has been removed which had a `text` property. Use `Tag`'s `message` property instead to retrieve the tag message from a commit's `mergetag`. i.e. `<commit>/mergetag/message` instead of `<commit>/mergetag/text`. | ||
* `PersonInfo` no longer exposes the human-readable RFC3339 format `date` field as a DAG node. The `date` and `timezone` fields are kept as their original string forms (to enable precise round-trips) as they exist in encoded Git data. e.g. `<commit>/author/date` now returns seconds in string form rather than an RFC3339 date string. Use this value and `<commit>/author/timezone` to reconstruct the original if needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,42 @@ | ||
package ipldgit | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"bufio" | ||
"fmt" | ||
"io" | ||
|
||
cid "github.com/ipfs/go-cid" | ||
node "github.com/ipfs/go-ipld-format" | ||
"github.com/ipld/go-ipld-prime" | ||
) | ||
|
||
type Blob struct { | ||
rawData []byte | ||
cid cid.Cid | ||
} | ||
|
||
func (b *Blob) Cid() cid.Cid { | ||
return b.cid | ||
} | ||
|
||
func (b *Blob) Copy() node.Node { | ||
nb := *b | ||
return &nb | ||
} | ||
|
||
func (b *Blob) Links() []*node.Link { | ||
return nil | ||
} | ||
|
||
func (b *Blob) Resolve(_ []string) (interface{}, []string, error) { | ||
return nil, nil, errors.New("no such link") | ||
} | ||
|
||
func (b *Blob) ResolveLink(_ []string) (*node.Link, []string, error) { | ||
return nil, nil, errors.New("no such link") | ||
} | ||
|
||
func (b *Blob) Loggable() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"type": "git_blob", | ||
// DecodeBlob fills a NodeAssembler (from `Type.Blob__Repr.NewBuilder()`) from a stream of bytes | ||
func DecodeBlob(na ipld.NodeAssembler, rd *bufio.Reader) error { | ||
sizen, err := readNullTerminatedNumber(rd) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
func (b *Blob) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(b.rawData) | ||
} | ||
|
||
func (b *Blob) RawData() []byte { | ||
return []byte(b.rawData) | ||
} | ||
prefix := fmt.Sprintf("blob %d\x00", sizen) | ||
buf := make([]byte, len(prefix)+sizen) | ||
copy(buf, prefix) | ||
|
||
func (b *Blob) Size() (uint64, error) { | ||
return uint64(len(b.rawData)), nil | ||
} | ||
n, err := io.ReadFull(rd, buf[len(prefix):]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
func (b *Blob) Stat() (*node.NodeStat, error) { | ||
return &node.NodeStat{}, nil | ||
} | ||
if n != sizen { | ||
return fmt.Errorf("blob size was not accurate") | ||
} | ||
|
||
func (b *Blob) String() string { | ||
return "[git blob]" | ||
return na.AssignBytes(buf) | ||
} | ||
|
||
func (b *Blob) Tree(p string, depth int) []string { | ||
return nil | ||
} | ||
func encodeBlob(n ipld.Node, w io.Writer) error { | ||
b, err := n.AsBytes() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
func (b *Blob) GitSha() []byte { | ||
return cidToSha(b.Cid()) | ||
_, err = w.Write(b) | ||
return err | ||
} | ||
|
||
var _ node.Node = (*Blob)(nil) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.