Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
868b4b06
Commit
868b4b06
authored
Apr 14, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basic implementation of object diff
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
70e5c88f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
8 deletions
+27
-8
utils/diff.go
utils/diff.go
+27
-8
No files found.
utils/diff.go
View file @
868b4b06
...
...
@@ -75,17 +75,25 @@ func ApplyChange(ctx context.Context, ds dag.DAGService, nd *dag.Node, cs []*Cha
return
e
.
Finalize
(
ds
)
}
func
Diff
(
ctx
context
.
Context
,
ds
dag
.
DAGService
,
a
,
b
*
dag
.
Node
)
[]
*
Change
{
func
Diff
(
ctx
context
.
Context
,
ds
dag
.
DAGService
,
a
,
b
*
dag
.
Node
)
(
[]
*
Change
,
error
)
{
if
len
(
a
.
Links
)
==
0
&&
len
(
b
.
Links
)
==
0
{
ak
,
_
:=
a
.
Key
()
bk
,
_
:=
b
.
Key
()
ak
,
err
:=
a
.
Key
()
if
err
!=
nil
{
return
nil
,
err
}
bk
,
err
:=
b
.
Key
()
if
err
!=
nil
{
return
nil
,
err
}
return
[]
*
Change
{
&
Change
{
Type
:
Mod
,
Before
:
ak
,
After
:
bk
,
},
}
}
,
nil
}
var
out
[]
*
Change
...
...
@@ -99,9 +107,20 @@ func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change {
if
bytes
.
Equal
(
l
.
Hash
,
lnk
.
Hash
)
{
// no change... ignore it
}
else
{
anode
,
_
:=
lnk
.
GetNode
(
ctx
,
ds
)
bnode
,
_
:=
l
.
GetNode
(
ctx
,
ds
)
sub
:=
Diff
(
ctx
,
ds
,
anode
,
bnode
)
anode
,
err
:=
lnk
.
GetNode
(
ctx
,
ds
)
if
err
!=
nil
{
return
nil
,
err
}
bnode
,
err
:=
l
.
GetNode
(
ctx
,
ds
)
if
err
!=
nil
{
return
nil
,
err
}
sub
,
err
:=
Diff
(
ctx
,
ds
,
anode
,
bnode
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
subc
:=
range
sub
{
subc
.
Path
=
path
.
Join
(
lnk
.
Name
,
subc
.
Path
)
...
...
@@ -128,7 +147,7 @@ func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change {
})
}
return
out
return
out
,
nil
}
type
Conflict
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment