mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 00:13:12 +03:00
story: diff: use dif-ju and uni-ju
This commit is contained in:
parent
68da061f47
commit
9afc2b8258
@ -8,102 +8,29 @@
|
||||
|%
|
||||
++ form %story-diff
|
||||
++ diff
|
||||
:: diff between given story, tale and another story, tory
|
||||
|= tory=story
|
||||
^- story-diff
|
||||
:: Given tory (new story),
|
||||
:: tale (old story),
|
||||
::
|
||||
:: the map of additions is defined as:
|
||||
:: any entries that are present in the new story but not in the old one,
|
||||
:: in conjunction with any additions to the set of proses for existing keys
|
||||
::
|
||||
:: given shared-keys := keys-new AND keys-old
|
||||
:: entry-additions = (new-story - old-story) :: entries present in new-story but not in old-story
|
||||
:: prose-additions = :: for the entries that are present in both, the values only contain proses not found in old-story
|
||||
:: for key in shared-keys, val-new in new-story, val-old in old-story:
|
||||
:: [key (val-new - val-old)]
|
||||
:: additions = entry-additions UNION prose-additions
|
||||
::
|
||||
:: deletions is the same thing, but with new and old swapped.
|
||||
:: (so anything not in the new but still in the old)
|
||||
::
|
||||
=/ entry-additions (~(dif by tory) tale) :: tory(new) - tale(old)
|
||||
=/ entry-deletions (~(dif by tale) tory) :: tale(old) - tory(new)
|
||||
::
|
||||
:: a map with only those kv-pairs that are in both tory and tale.
|
||||
:: used to filter out any entries that were not in one or the other while calculating the set differences
|
||||
:: we keep it as a map so that it can be used in int by
|
||||
:: but we discard all of its values because we overwrite them in the next step
|
||||
::
|
||||
=/ entries-both (~(int by tale) tory)
|
||||
::
|
||||
:: A - all entries in (tory(new) - tale(old)) + all entries in (tale(old) - tory(new)), but,
|
||||
:: if the key of an entry is present in both, the final value of that entry will be (val:tory(new) - val:tale(tale))
|
||||
:: B - only those entries in A whose keys are present in both tory(new) and tale(old)
|
||||
::
|
||||
=/ prose-additions
|
||||
%- ~(int by entries-both) :: B
|
||||
%- (~(uno by tory) tale) :: A
|
||||
|= [k=tako:clay proses-tory=(set prose) proses-tale=(set prose)]
|
||||
^- (set prose)
|
||||
(~(dif in proses-tory) proses-tale)
|
||||
::
|
||||
=/ prose-deletions
|
||||
%- ~(int by entries-both)
|
||||
%- (~(uno by tale) tory)
|
||||
|= [k=tako:clay proses-tale=(set prose) proses-tory=(set prose)]
|
||||
^- (set prose)
|
||||
(~(dif in proses-tale) proses-tory)
|
||||
::
|
||||
:: invariant (~(int by entry-additions) prose-additions) = ~
|
||||
:: and vice versa for deletions
|
||||
:: =/ additions=story (~(uni by entry-additions) prose-additions)
|
||||
:: =/ deletions=story (~(uni by entry-deletions) prose-deletions)
|
||||
[[entry-additions prose-additions] [entry-deletions prose-deletions]]
|
||||
:: Given new story (tory), old story (tale), compute the diff
|
||||
:: additions = new - old
|
||||
:: deletions = old - new
|
||||
[(dif-ju tory tale) (dif-ju tale tory)]
|
||||
++ pact
|
||||
:: given tale=story, compute the new story after applying the given dif
|
||||
|= dif=story-diff
|
||||
:: compute the new story after applying dif to tale
|
||||
^- story
|
||||
:: XX code clean up: better way to declare vars
|
||||
=/ [[entry-additions=story prose-additions=story] [entry-deletions=story prose-deletions=story]] dif
|
||||
=. tale (~(uni by tale) entry-additions) :: add completely new entries
|
||||
=. tale :: add new proses to existing entries
|
||||
%- (~(uno by tale) prose-additions)
|
||||
|= [k=tako:clay proses-tale=(set prose) proses-additions=(set prose)]
|
||||
^- (set prose)
|
||||
(~(uni in proses-tale) proses-additions)
|
||||
::
|
||||
=. tale (~(dif by tale) entry-deletions) :: remove any entries which should not be present
|
||||
=. tale :: remove any proses from existing entries
|
||||
%- ~(urn by tale)
|
||||
|= [k=tako:clay proses=(set prose)]
|
||||
^- (set prose)
|
||||
:: This works because get:ju returns the empty set if the key isn't found
|
||||
=/ proses-del=(set prose) (~(get ju prose-deletions) k)
|
||||
(~(dif in proses) proses-del)
|
||||
::
|
||||
=. tale (uni-ju tale additions.dif)
|
||||
=. tale (dif-ju tale deletions.dif)
|
||||
tale
|
||||
++ join
|
||||
|= [ali=story-diff bob=story-diff]
|
||||
^- (unit story-diff)
|
||||
=/ joined-entry-adds (~(uni by entry-additions.additions.ali) entry-additions.additions.bob)
|
||||
=/ joined-proses-adds
|
||||
%- (~(uno by prose-additions.additions.ali) prose-additions.additions.bob)
|
||||
|= [k=tako:clay proses-a=(set prose) proses-b=(set prose)]
|
||||
^- (set prose)
|
||||
(~(uni in proses-a) proses-b)
|
||||
=/ joined-additions (uni-ju additions.ali additions.bob)
|
||||
=/ joined-deletions (uni-ju deletions.ali deletions.bob)
|
||||
::
|
||||
=/ joined-entry-dels (~(uni by entry-deletions.deletions.ali) entry-deletions.deletions.bob)
|
||||
=/ joined-deletion-dels
|
||||
%- (~(uno by prose-deletions.deletions.ali) prose-deletions.deletions.bob)
|
||||
|= [k=tako:clay proses-a=(set prose) proses-b=(set prose)]
|
||||
^- (set prose)
|
||||
(~(uni in proses-a) proses-b)
|
||||
:: in a true join, we'd do an intersection and see if the vals are not exactly the same
|
||||
:: which means we have a conflict, then we'd produce null, kick the flow to mash
|
||||
%- some
|
||||
[[joined-entry-adds joined-proses-adds] [joined-entry-dels joined-deletion-dels]]
|
||||
[joined-additions joined-deletions]
|
||||
++ mash
|
||||
:: called by meld, force merge, annotating conflicts
|
||||
|= $: [als=ship ald=desk ali=story-diff]
|
||||
|
Loading…
Reference in New Issue
Block a user