mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 09:34:03 +08:00
dag: fix git plugin
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -2,12 +2,15 @@ package git
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/ipfs/go-ipfs/core/coredag"
|
"github.com/ipfs/go-ipfs/core/coredag"
|
||||||
"github.com/ipfs/go-ipfs/plugin"
|
"github.com/ipfs/go-ipfs/plugin"
|
||||||
|
|
||||||
"gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
|
"gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
|
||||||
|
mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash"
|
||||||
"gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
|
"gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
|
||||||
git "gx/ipfs/Qma7Kuwun7w8SZphjEPDVxvGfetBkqdNGmigDA13sJdLex/go-ipld-git"
|
git "gx/ipfs/Qma7Kuwun7w8SZphjEPDVxvGfetBkqdNGmigDA13sJdLex/go-ipld-git"
|
||||||
)
|
)
|
||||||
@ -44,7 +47,15 @@ func (*gitPlugin) RegisterInputEncParsers(iec coredag.InputEncParsers) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseRawGit(r io.Reader) ([]format.Node, error) {
|
func parseRawGit(r io.Reader, mhType uint64, mhLen int) ([]format.Node, error) {
|
||||||
|
if mhType != math.MaxUint64 && mhType != mh.SHA1 {
|
||||||
|
return nil, fmt.Errorf("unsupported mhType %d", mhType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if mhLen != -1 && mhLen != mh.DefaultLengths[mh.SHA1] {
|
||||||
|
return nil, fmt.Errorf("invalid mhLen %d", mhType)
|
||||||
|
}
|
||||||
|
|
||||||
nd, err := git.ParseObject(r)
|
nd, err := git.ParseObject(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -53,12 +64,12 @@ func parseRawGit(r io.Reader) ([]format.Node, error) {
|
|||||||
return []format.Node{nd}, nil
|
return []format.Node{nd}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseZlibGit(r io.Reader) ([]format.Node, error) {
|
func parseZlibGit(r io.Reader, mhType uint64, mhLen int) ([]format.Node, error) {
|
||||||
rc, err := zlib.NewReader(r)
|
rc, err := zlib.NewReader(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
return parseRawGit(rc)
|
return parseRawGit(rc, mhType, mhLen)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user