Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions merkledag/utils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 17 additions & 1 deletion test/sharness/t0052-object-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" '
Expand All @@ -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
'
Expand Down