coreapi: implement Object.Diff
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@00f6430f32022c0038bb4407cca5d9f136b0ee24 This commit was moved from ipfs/boxo@83c279f0be6bbc7a498345e8b82b7331b8fb356c
Łukasz Magiera committed
Feb 2, 2018 at 21:50 UTC
5dbe176f5331c80be35bce0feeba622113c5545a
1 file changed
+37
core/coreiface/object.go
+37
@@ -31,6 +31,39 @@ type ObjectStat struct {
31
CumulativeSize int
32
}
33
34
+
35
+const (
36
+ // DiffAdd is a Type of ObjectChange where a link was added to the graph
37
+ DiffAdd = iota
38
+
39
+ // DiffRemove is a Type of ObjectChange where a link was removed from the graph
40
+ DiffRemove
41
+
42
+ // DiffMod is a Type of ObjectChange where a link was changed in the graph
43
+ DiffMod
44
+)
45
+
46
+// ObjectChange represents a change ia a graph
47
+// TODO: do we want this to be an interface?
48
+type ObjectChange struct {
49
+ // Type of the change, either:
50
+ // * DiffAdd - Added a link
51
+ // * DiffRemove - Removed a link
52
+ // * DiffMod - Modified a link
53
+ Type int
54
+
55
+ // Path to the changed link
56
+ Path string
57
+
58
+ // Before holds the link path before the change. Note that when a link is
59
+ // added, this will be nil.
60
+ Before Path
61
+
62
+ // After holds the link path after the change. Note that when a link is
63
+ // removed, this will be nil.
64
+ After Path
65
+}
66
+
67
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
68
// for manipulating MerkleDAG data structures.
69
type ObjectAPI interface {
@@ -65,4 +98,8 @@ type ObjectAPI interface {
98
99
// SetData sets the data contained in the node
100
SetData(context.Context, Path, io.Reader) (ResolvedPath, error)
101
+
102
+ // Diff returns a set of changes needed to transform the first object into the
103
+ // second.
104
+ Diff(context.Context, Path, Path) ([]ObjectChange, error)
105
}