Skip to content

Commit 0d2dd19

Browse files
committed
commands: switch object commands to CoreAPI
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
1 parent f062dd6 commit 0d2dd19

File tree

4 files changed

+120
-346
lines changed

4 files changed

+120
-346
lines changed

core/commands/object/diff.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import (
66
"io"
77

88
cmds "github.com/ipfs/go-ipfs/commands"
9-
core "github.com/ipfs/go-ipfs/core"
109
e "github.com/ipfs/go-ipfs/core/commands/e"
1110
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
12-
path "github.com/ipfs/go-ipfs/path"
11+
1312
cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
1413
)
1514

@@ -52,7 +51,7 @@ Example:
5251
cmdkit.BoolOption("verbose", "v", "Print extra information."),
5352
},
5453
Run: func(req cmds.Request, res cmds.Response) {
55-
node, err := req.InvocContext().GetNode()
54+
api, err := req.InvocContext().GetApi()
5655
if err != nil {
5756
res.SetError(err, cmdkit.ErrNormal)
5857
return
@@ -61,39 +60,37 @@ Example:
6160
a := req.Arguments()[0]
6261
b := req.Arguments()[1]
6362

64-
pa, err := path.ParsePath(a)
63+
pa, err := api.ParsePath(req.Context(), a, api.WithResolve(true))
6564
if err != nil {
6665
res.SetError(err, cmdkit.ErrNormal)
6766
return
6867
}
6968

70-
pb, err := path.ParsePath(b)
69+
pb, err := api.ParsePath(req.Context(), b, api.WithResolve(true))
7170
if err != nil {
7271
res.SetError(err, cmdkit.ErrNormal)
7372
return
7473
}
7574

76-
ctx := req.Context()
75+
changes, err := api.Object().Diff(req.Context(), pa, pb)
7776

78-
obj_a, err := core.Resolve(ctx, node.Namesys, node.Resolver, pa)
79-
if err != nil {
80-
res.SetError(err, cmdkit.ErrNormal)
81-
return
82-
}
77+
out := make([]*dagutils.Change, len(changes))
78+
for i, change := range changes {
79+
out[i] = &dagutils.Change{
80+
Type: change.Type,
81+
Path: change.Path,
82+
}
8383

84-
obj_b, err := core.Resolve(ctx, node.Namesys, node.Resolver, pb)
85-
if err != nil {
86-
res.SetError(err, cmdkit.ErrNormal)
87-
return
88-
}
84+
if change.Before != nil {
85+
out[i].Before = change.Before.Cid()
86+
}
8987

90-
changes, err := dagutils.Diff(ctx, node.DAG, obj_a, obj_b)
91-
if err != nil {
92-
res.SetError(err, cmdkit.ErrNormal)
93-
return
88+
if change.After != nil {
89+
out[i].After = change.After.Cid()
90+
}
9491
}
9592

96-
res.SetOutput(&Changes{changes})
93+
res.SetOutput(&Changes{out})
9794
},
9895
Type: Changes{},
9996
Marshalers: cmds.MarshalerMap{

0 commit comments

Comments
 (0)