-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Correctly diff nested data structures #566
Conversation
While the current implementation of `fileset-diff` works well for diffing on scalar values, the semantics are not correct for diffing on nested structures. This small modification results in correct diffs.
Agreed! I started to add tests, but I'm new to boot, and it wasn't obvious to me how to run them. Any tips? |
I suppose exactly where to add them would be good to know too, my initial stab just picked a random test file. |
should run the tests. As for tests file, use whatever seems most appropriate, probably |
I tried |
Okay, I added tests. They pass when running |
From what I see we actually don't change the behavior for scalar comparison, am I right? |
Yes, that's correct |
This looks good to me, if you want to be super zealous you could add some edge case like empty maps or |
I'm feeling super zealous, I guess - tests added |
Awesome, I am not going to "push the button" here but very thorough job! |
Not sure what happened there, but tests are passing again |
🎉 🍾 |
yay! |
Summary
I would like to do
(boot.core/fileset-diff old-fs new-fs :foo)
, where the:foo
key is a nested data structure set on tmpfiles in the filesets, but this currently only works in some cases. While the current implementation offileset-diff
works well for diffing scalar values, the semantics are not correct for diffing nested structures. This small modification results in correct diffs for nested structures, which is useful when using custom tmpfile metadata.Explanation
The root of the problem is that, in
boot.tmpdir/diff*
, only the first two return values ofclojure.data/diff
are used to calculate changes. For scalars, this is all that's necessary, but nested compound data structures require the use of the third value as well. For example, if you were to diff the following metadata structures, the 3rd value comes into play:diff*
should return this in the:changed
fileset, but it currently registers as:removed
. A similar interaction results in nested key additions registering as:added
instead of:changed
.If the return value of
data/diff
is[x y z]
, then:changed
should include all paths that are in bothx
andy
, plus all keys that are inx
ory
(or both) and inz
. Following on from that,:added
and:removed
should not contain any paths that are in:changed
.