Skip to content

Commit

Permalink
object coreapi: Address review
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Jul 30, 2018
1 parent 3cf7b34 commit 62f986e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
6 changes: 0 additions & 6 deletions commands/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ func (c *Context) GetApi() (coreiface.CoreAPI, error) {
return c.api, nil
}

// NodeWithoutConstructing returns the underlying node variable
// so that clients may close it.
func (c *Context) NodeWithoutConstructing() *core.IpfsNode {
return c.node
}

// Context returns the node's context.
func (c *Context) Context() context.Context {
n, err := c.GetNode()
Expand Down
6 changes: 4 additions & 2 deletions core/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/ipfs/go-ipfs/core"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/repo/config"

cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
)

// GetNode extracts the node from the environment.
Expand All @@ -20,7 +22,7 @@ func GetNode(env interface{}) (*core.IpfsNode, error) {
}

// GetApi extracts CoreAPI instance from the environment.
func GetApi(env interface{}) (coreiface.CoreAPI, error) {
func GetApi(env cmds.Environment) (coreiface.CoreAPI, error) {
ctx, ok := env.(*commands.Context)
if !ok {
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
Expand All @@ -30,7 +32,7 @@ func GetApi(env interface{}) (coreiface.CoreAPI, error) {
}

// GetConfig extracts the config from the environment.
func GetConfig(env interface{}) (*config.Config, error) {
func GetConfig(env cmds.Environment) (*config.Config, error) {
ctx, ok := env.(*commands.Context)
if !ok {
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
Expand Down
2 changes: 1 addition & 1 deletion core/commands/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ to a file containing 'bar', and returns the hash of the new object.
// TODO: fix import loop with core/commands so we don't need that
// COPIED FROM ONE LEVEL UP
// GetApi extracts CoreAPI instance from the environment.
func GetApi(env interface{}) (coreiface.CoreAPI, error) {
func GetApi(env cmds.Environment) (coreiface.CoreAPI, error) {
ctx, ok := env.(*oldcmds.Context)
if !ok {
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
Expand Down
14 changes: 8 additions & 6 deletions core/coreapi/interface/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,27 @@ type ObjectStat struct {
CumulativeSize int
}

// ChangeType denotes type of change in ObjectChange
type ChangeType int

const (
// DiffAdd is a Type of ObjectChange where a link was added to the graph
DiffAdd = iota
// DiffAdd is set when a link was added to the graph
DiffAdd ChangeType = iota

// DiffRemove is a Type of ObjectChange where a link was removed from the graph
// DiffRemove is set when a link was removed from the graph
DiffRemove

// DiffMod is a Type of ObjectChange where a link was changed in the graph
// DiffMod is set when a link was changed in the graph
DiffMod
)

// ObjectChange represents a change ia a graph
// TODO: do we want this to be an interface?
type ObjectChange struct {
// Type of the change, either:
// * DiffAdd - Added a link
// * DiffRemove - Removed a link
// * DiffMod - Modified a link
Type int
Type ChangeType

// Path to the changed link
Path string
Expand Down
7 changes: 4 additions & 3 deletions dagutils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"fmt"
"path"

dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"

cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
"gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
)

Expand All @@ -21,7 +22,7 @@ const (
// Change represents a change to a DAG and contains a reference to the old and
// new CIDs.
type Change struct {
Type int
Type coreiface.ChangeType
Path string
Before *cid.Cid
After *cid.Cid
Expand Down

0 comments on commit 62f986e

Please sign in to comment.