-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(object): add support for raw leaves in object diff #5472
Conversation
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
f7b14ba
to
26a3ebf
Compare
@Stebalien, something seems to be incorrect in ci |
Yes, this definitely looks like the right approach, treat the nodes as IPLD nodes as long as possible and only convert them to Could you add a test for the raw nodes case? (And also, if it's not too much trouble, could you add some comment lines explaining that this now supports raw nodes and why.) |
And great job!! (I should have started with that line :) |
@schomatis Yes, thx for your reply. I add the comment and test cases. Could you help me review this again? But something seems to be incorrect about our ci. |
4254f14
to
1ce6e04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great @overbool!! This LGTM (minus the two code nits), I would like to get someone else to check the tests structure, overloading test cases (with more than one test_cmp
call per case) seems sensible to me but we may be breaking some unwritten rule.
core/commands/object/diff.go
Outdated
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface" | ||
"github.com/ipfs/go-ipfs/dagutils" | ||
|
||
cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure this was some IDE automatic feature (it happens to me also) but could you restore the e
and cmdkit
names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
core/commands/object/diff.go
Outdated
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit" | ||
) | ||
|
||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm usually all for declaring constants and avoiding hard-coding inside functions but in this particular case of strings it doesn't seem to be worth it, those strings won't be repeated elsewhere and they make more sense inside the StringArg
call instead of isolated here where we wouldn't now what they are used for, it will be just repeating the "obj_a" string as just the name of the string constant with the same value.
@magik6k Could you take a look at the tests please? |
Yeah, I wouldn't worry too much about it, they tend to fail for no (apparent) reason fairly regularly, my main rule of thumb is that if another CI that is doing the same test is passing then I'm good. |
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
1ce6e04
to
5b0a948
Compare
@schomatis Thx for your suggestion. I had fixed them. |
@schomatis Should I split the test cases to keep the rule (one test_cmp call per case)? |
@magik6k Sorry, I wasn't very clear. I meant if you could take a look at the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the test cases to be separate, makes it more obvious when something fails (slightly easier to read too).
dagutils/diff.go
Outdated
@@ -94,7 +94,11 @@ func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs | |||
return e.Finalize(ctx, ds) | |||
} | |||
|
|||
// Diff returns a set of changes that transform node 'a' into node 'b' | |||
// Diff returns a set of changes that transform node 'a' into node 'b'. | |||
// It supports two nodes forms: ProtoNode and RawNode. Because we treats |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/treats/treat
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
@magik6k I had separated the test cases and modified the spelling mistake,could you help me review it again? |
Nice work, thanks @overbool ! |
@schomatis thx for your help in this issue |
How will this behave when passed, e.g., DagCBOR nodes? I think this'll just continue as if nothing is wrong and print out nonsensical results. We should fail when we encounter non-protobuf/non-raw nodes. |
Why?
Where? I don't have any experience with CBOR so I fail to see the relation between that type of node and this particular PR. The title of the PR may be misleading, it emphasizes why we are doing this but not what we are changing here. This just doesn't force the |
This is how we're calculating the diff. We're removing all the links present in both nodes A and B from both A and B, leaving only the links present in only one or the other. However, this will fail for any format that's not ProtoNode as we won't be able to remove the links. This is fine for raw nodes only because they don't have links. One solution is to just treat all non-ProtoNodes as opaque "things" (i.e., stop diffing). Diff would, at the top, check to see if we have two protonodes. If not, it would compare the CIDs and emit a Is this making any sense or am I still misunderstanding what this patch does. |
If other format Nodes have links and implement Currently, |
Yes, it seems like a reasonable compromise. @overbool Are you ok with making that change? If not, we can merge this PR as-is, since it's already solving #5470 (and the fact that this command is deeply broken is beyond responsibility of this PR). |
@schomatis What do you mean about
about this? |
Yes, instead of returning an error if the conversion to a |
@schomatis, i got it. |
@@ -112,8 +116,8 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that much (I think), we could add a check here to verify that, if they have links, i.e., they are not raw nodes because they passed the first check (hence we would still be supporting them), they must be proto-nodes; if not, you could also return a Mod
as before. Actually you could even merge this proto-node check in the previous if
, WDYT?
@Stebalien @schomatis According to your suggestion, I made some changes in It only traverses links in the following cases:
Otherwise, it compares the cid and emits a Mod change object. |
@@ -209,3 +197,16 @@ func MergeDiffs(a, b []*Change) ([]*Change, []Conflict) { | |||
} | |||
return out, conflicts | |||
} | |||
|
|||
func getChange(a, b ipld.Node) ([]*Change, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely encapsulated!
dagutils/diff.go
Outdated
// Diff returns a set of changes that transform node 'a' into node 'b' | ||
// Diff returns a set of changes that transform node 'a' into node 'b'. | ||
// It only traverses links in the following cases: | ||
// 1. two node's links number are greater then 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "then" -> "than"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG, forgive my frequent spelling mistakes. 😨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Stebalien Was that what you had in mind?
1628e97
to
df706f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 small things in sharness, then LGTM
test/sharness/t0052-object-diff.sh
Outdated
printf "" > diff_exp && | ||
test_cmp diff_exp diff_out | ||
' | ||
|
||
test_expect_success "diff (raw-leaves) against self (single file) is empty" ' | ||
ipfs object diff $SINGLE_FILE_RAW $SINGLE_FILE_RAW > diff_raw_out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing &&
test/sharness/t0052-object-diff.sh
Outdated
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 (raw-leaves) against self (empty dir) is empty" ' | ||
ipfs object diff $EMPTY_DIR_RAW $EMPTY_DIR_RAW > diff_raw_out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also missing &&
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
df706f4
to
c6daf93
Compare
@magik6k thx for your reply, I had fixed it. |
@Stebalien Was this pr what you had in mind? |
License: MIT
Signed-off-by: Overbool overbool.xu@gmail.com
Fixes #5470