1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-27 07:57:30 +08:00

dag: diff: check CIDs in base case when comparing nodes

Fixes #4591.

License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
This commit is contained in:
Lucas Molas
2018-03-05 12:00:34 -03:00
parent de92ff6961
commit 90acbfaae7
2 changed files with 22 additions and 1 deletions

View File

@ -95,7 +95,12 @@ func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs
// Diff returns a set of changes that transform node 'a' into node 'b'
func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, error) {
// Base case where both nodes are leaves, just compare
// their CIDs.
if len(a.Links()) == 0 && len(b.Links()) == 0 {
if a.Cid().Equals(b.Cid()) {
return []*Change{}, nil
}
return []*Change{
&Change{
Type: Mod,

View File

@ -20,7 +20,11 @@ test_expect_success "create some objects for testing diffs" '
echo "nested" > foo/baz/dog &&
C=$(ipfs add -r -q foo | tail -n1)
echo "changed" > foo/bar &&
D=$(ipfs add -r -q foo | tail -n1)
D=$(ipfs add -r -q foo | tail -n1) &&
echo "" > single_file &&
SINGLE_FILE=$(ipfs add -r -q single_file | tail -n1) &&
mkdir empty_dir
EMPTY_DIR=$(ipfs add -r -q empty_dir | tail -n1)
'
test_expect_success "diff against self is empty" '
@ -32,6 +36,18 @@ test_expect_success "identity diff output looks good" '
test_cmp diff_exp diff_out
'
test_expect_success "diff against self (single file) is empty" '
ipfs object diff $SINGLE_FILE $SINGLE_FILE > diff_out
printf "" > diff_exp &&
test_cmp diff_exp diff_out
'
test_expect_success "diff against self (empty dir) is empty" '
ipfs object diff $EMPTY_DIR $EMPTY_DIR > diff_out
printf "" > diff_exp &&
test_cmp diff_exp diff_out
'
test_expect_success "diff added link works" '
ipfs object diff $A $B > diff_out
'