From 76a189f544f99a1d0f5da799fa5025eee4ee88eb Mon Sep 17 00:00:00 2001 From: raghu <{ID}+{username}@users.noreply.github.com> Date: Tue, 2 Mar 2021 15:05:27 -0500 Subject: [PATCH 1/5] ddiff: add generator --- pkg/arvo/ted/ddiff.hoon | 297 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 pkg/arvo/ted/ddiff.hoon diff --git a/pkg/arvo/ted/ddiff.hoon b/pkg/arvo/ted/ddiff.hoon new file mode 100644 index 000000000..c408b42d3 --- /dev/null +++ b/pkg/arvo/ted/ddiff.hoon @@ -0,0 +1,297 @@ +/- spider +/+ strandio +=, strand=strand:spider +=, clay +^- thread:spider +|= arg=vase +=/ m (strand ,vase) +^- form:m +|^ +=+ !<([~ =a=path =b=path shallow=flag] arg) +=/ a-beam (need (de-beam a-path)) +=/ b-beam (need (de-beam b-path)) +;< a-dome=dome bind:m (get-from-clay a-beam dome %v) +;< b-dome=dome bind:m (get-from-clay b-beam dome %v) +;< diff=vase bind:m (diff-beams a-beam ank.a-dome b-beam ank.b-dome) +=/ diffs=(list diff-type) !<((list diff-type) diff) +%- pure:m +!> ^- tang +?: shallow + (format-shallow diffs q.a-beam q.b-beam) +(format-deep diffs q.a-beam q.b-beam) +:: +:: $diff-type: type for diffs produced. +:: 1. %txt-diff is a standard diff (i.e. for hoon and txt files) +:: 2. %directory-diff shows unique files between two directories +:: 3. %other is for files that don't use txt-diff - we just take +:: the mug of the files ++$ diff-type + :: path of the diffed beams + $: pax=path + $% [%txt-diff diff=(urge cord)] + [%directory-diff p=(list path) q=(list path)] + [%other p=@ q=@] + == + == +:: +diff-is-empty: check if a diff is empty (for two identical files) +:: +++ diff-is-empty + |= d=diff-type + ^- flag + ?: ?=([%txt-diff *] +.d) + :: levy produces & on empty lists + %+ levy + diff.d + |= u=(unce cord) + ^- flag + -:u + ?: ?=([%directory-diff *] +.d) + =(p.d q.d) + =(p.d q.d) +:: +get-file: retrieve a cage of a file from clay +:: +++ get-file + |= =beam + =/ m (strand ,cage) + ^- form:m + ;< =riot:clay bind:m + (warp:strandio p.beam q.beam ~ %sing %x r.beam s.beam) + ?~ riot + (strand-fail:strandio %file-not-found >s.beam< ~) + (pure:m r.u.riot) +:: +get-from-clay: retrieve other data from clay based on care +:: +++ get-from-clay + |* [=beam mol=mold =care] + =/ m (strand ,mol) + ^- form:m + ;< =riot:clay bind:m + (warp:strandio p.beam q.beam ~ %sing care r.beam s.beam) + ?~ riot + (strand-fail:strandio %file-not-found >s.beam< ~) + (pure:m !<(mol q.r.u.riot)) +:: +diff-beams: recursively diff two beams. produces a vase +:: of (list diff-type) +:: +++ diff-beams + =< + |= [a=beam a-ankh=ankh b=beam b-ankh=ankh] + =/ m (strand ,vase) + ^- form:m + ?> =(s.a s.b) + ;< hash-a=@ bind:m (get-from-clay a @ %z) + ;< hash-b=@ bind:m (get-from-clay b @ %z) + :: if the recursive hashes for each beam are the same we bail early + ?: =(hash-a hash-b) + (pure:m !>(*(list diff-type))) + :: vase of a (unit diff-type) + ;< file-diff=vase bind:m (diff-file-contents a a-ankh b b-ankh) + :: get distinct files along with shared files + =/ a-keys=(set @t) ~(key by dir.a-ankh) + =/ b-keys=(set @t) ~(key by dir.b-ankh) + :: unique children + =/ a-unique-children=(set @t) (~(dif in a-keys) b-keys) + =/ b-unique-children=(set @t) (~(dif in b-keys) a-keys) + =/ a-unique=(list path) (format-unique-children a a-ankh a-unique-children) + =/ b-unique=(list path) (format-unique-children b b-ankh b-unique-children) + =/ unique-diff=diff-type [s.a %directory-diff a-unique b-unique] + :: shared children + =/ find-common-diffs + |. + ^- form:m + =| acc=(list diff-type) + =/ common-children=(list @t) ~(tap in (~(int in a-keys) b-keys)) + |- + =* loop $ + ^- form:m + ?~ common-children + (pure:m !>(acc)) + =/ child=@t i.common-children + =/ new-a=beam a(s (snoc s.a child)) + =/ new-b=beam b(s (snoc s.b child)) + ;< res=vase bind:m + (diff-beams new-a (~(got by dir.a-ankh) child) new-b (~(got by dir.b-ankh) child)) + :: ;< introduces another $ so we use "loop" instead. + %= loop + acc (weld !<((list diff-type) res) acc) + common-children t.common-children + == + ;< common-diffs=vase bind:m (find-common-diffs) + %- pure:m + !> ^- (list diff-type) + %+ skip + ;: weld + (drop !<((unit diff-type) file-diff)) + [unique-diff ~] + !<((list diff-type) common-diffs) + == + diff-is-empty + |% + :: +format-unique-children: produce list of paths representing + :: files that are unique within a directory. + :: + ++ format-unique-children + =< + |= [bem=beam ank=ankh children=(set @t)] + ^- (list path) + %- ~(rep by dir.ank) + |= [[key=@t node=ankh] acc=(list path)] + ^- (list path) + ?. (~(has in children) key) + acc + (weld (get-all-paths node (snoc s.bem key)) acc) + |% + ++ get-all-paths + |= [ank=ankh cur-path=path] + ^- (list path) + :: check for terminal node + ?: =(~(wyt by dir.ank) 0) + ~[cur-path] + %- ~(rep by dir.ank) + |= [[key=@t node=ankh] acc=(list path)] + ^- (list path) + =/ new-path=path (snoc cur-path key) + =/ child-paths=(list path) (get-all-paths node new-path) + (weld child-paths acc) + -- + :: +diff-file-contents: diff two files at specified beams, + :: producing a vase of (unit diff-type) + ++ diff-file-contents + =< + |= [a=beam a-ankh=ankh b=beam b-ankh=ankh] + =/ m (strand ,vase) + ^- form:m + :: the files must be at the same path + ?> =(s.a s.b) + ?: =(fil.a-ankh fil.b-ankh) + (pure:m !>(*(unit diff-type))) + ?~ fil.a-ankh + :: only b has contents + %- pure:m + !> ^- (unit diff-type) + %- some + :+ s.a + %txt-diff + :_ ~ + ^- (unce cord) + :+ %| + ~ + ~[(format-file-content-missing s.b q.b)] + ?~ fil.b-ankh + :: only a has contents + %- pure:m + !> ^- (unit diff-type) + %- some + :+ s.a + %txt-diff + :_ ~ + ^- (unce cord) + :+ %| + ~[(format-file-content-missing s.a q.a)] + ~ + :: have two file contents - diff them + =/ mar=mark -:(flop s.a) + ;< =a=cage bind:m (get-file a) + ;< =b=cage bind:m (get-file b) + ;< =dais:clay bind:m (build-mark:strandio -.a mar) + :: for txt-diff we produce an actual diff with type (urge cord). + :: for all other marks we just take the mug) + %- pure:m + ?: =(form:dais %txt-diff) + !> ^- (unit diff-type) + %- some + :+ s.a + %txt-diff + !<((urge cord) (~(diff dais q.a-cage) q.b-cage)) + !> ^- (unit diff-type) + %- some + :+ s.a + %other + :: For some reason, vases for identical files on different desks + :: can sometimes have different types. for this reason, we only + :: take the mug of the data. + [(mug q.q.a-cage) (mug q.q.b-cage)] + |% + ++ format-file-content-missing + |= [p=path d=desk] + ^- cord + %- crip + ;: weld + "only " +

+ " in desk " + + " has file contents" + == + -- + -- +:: +format-directory-diff: helper for producing a tank based on +:: a %directory-diff +:: +++ format-directory-diff + |= [paths=(list path) =desk] + ^- tang + =/ prefix=tape ;:(weld "only in " (trip desk) ": ") + (turn paths |=(p=path >(weld prefix

)<)) +:: +format-shallow: converts a list of diff-type generated +:: between desks a and b into a tang in a shallow manner (just +:: listing files that differ). +:: +++ format-shallow +|= [diffs=(list diff-type) a=desk b=desk] + ^- tang + %+ reel + diffs + |= [d=diff-type acc=tang] + ^- tang + ?: ?=([%txt-diff *] +.d) + [`tank`>pax.d< acc] + ?: ?=([%other *] +.d) + [`tank`>pax.d< acc] + ?: ?=([%directory-diff *] +.d) + ;: weld + (format-directory-diff p.d a) + (format-directory-diff q.d b) + acc + == + !! +:: +format-deep: converts a list of diff-type generated +:: between desks a and b into a tang in a deep manner (preserving +:: diff information for files) +++ format-deep +|= [diffs=(list diff-type) a=desk b=desk] + ^- tang + %+ reel + diffs + |= [d=diff-type acc=tang] + ^- tang + ?: ?=([%txt-diff *] +.d) + :: TODO come up with some more readable formatting + :: super ugly when printed. + :- >pax.d< + %+ weld + (turn diff.d |=(u=(unce cord) >u<)) + acc + ?: ?=([%directory-diff *] +.d) + ;: weld + (format-directory-diff p.d a) + (format-directory-diff q.d b) + acc + == + ?: ?=([%other *] +.d) + :_ acc + :- %leaf + ;: weld + "file " + + " has mug " + + " on desk " + + " but mug " + + " on desk " + + == + !! +-- From c98e1df819f2f73ada8407d33a1feac4a5a2ceff Mon Sep 17 00:00:00 2001 From: raghu <{ID}+{username}@users.noreply.github.com> Date: Thu, 4 Mar 2021 16:57:41 -0500 Subject: [PATCH 2/5] dojo: print thread results as tang if they are tang --- pkg/arvo/app/dojo.hoon | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index 70e07d618..c06b86e50 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -1077,7 +1077,12 @@ :: %thread-done ?> ?=(^ poy) - (~(dy-hand dy u.poy(pux ~)) %noun q.cage.sign) + :: print the vase as a tang if it nests in tang + =/ =mark + ?: (~(nest ut -:!>(*tang)) | p.q.cage.sign) + %tang + %noun + (~(dy-hand dy u.poy(pux ~)) mark q.cage.sign) == :: %kick +>.$ From a7165e0f85972228af7d4e405431c2acaec18ff0 Mon Sep 17 00:00:00 2001 From: raghu <{ID}+{username}@users.noreply.github.com> Date: Fri, 5 Mar 2021 17:09:24 -0500 Subject: [PATCH 3/5] ddiff: c/r --- pkg/arvo/ted/ddiff.hoon | 181 +++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 87 deletions(-) diff --git a/pkg/arvo/ted/ddiff.hoon b/pkg/arvo/ted/ddiff.hoon index c408b42d3..ec9eadf7d 100644 --- a/pkg/arvo/ted/ddiff.hoon +++ b/pkg/arvo/ted/ddiff.hoon @@ -7,15 +7,20 @@ =/ m (strand ,vase) ^- form:m |^ -=+ !<([~ =a=path =b=path shallow=flag] arg) +:: workaround to make the shallow flag optional. if it's specified we +:: do require a non-empty path - however this shouldn't be called with +:: empty paths to begin with. +=+ !<([~ =a=path b=$~([/hi &] $^([(lest @ta) flag] path))] arg) +=/ [b-path=path shallow=flag] ?:(?=([^ *] b) b [`path`b |]) =/ a-beam (need (de-beam a-path)) =/ b-beam (need (de-beam b-path)) ;< a-dome=dome bind:m (get-from-clay a-beam dome %v) ;< b-dome=dome bind:m (get-from-clay b-beam dome %v) -;< diff=vase bind:m (diff-beams a-beam ank.a-dome b-beam ank.b-dome) -=/ diffs=(list diff-type) !<((list diff-type) diff) +;< diffs=(list diff-type) bind:m (diff-beams a-beam b-beam) %- pure:m !> ^- tang +:: our tang is built in reverse order +%- flop ?: shallow (format-shallow diffs q.a-beam q.b-beam) (format-deep diffs q.a-beam q.b-beam) @@ -26,8 +31,9 @@ :: 3. %other is for files that don't use txt-diff - we just take :: the mug of the files +$ diff-type - :: path of the diffed beams - $: pax=path + :: paths of the diffed beams + $: a=path + b=path $% [%txt-diff diff=(urge cord)] [%directory-diff p=(list path) q=(list path)] [%other p=@ q=@] @@ -37,17 +43,17 @@ :: ++ diff-is-empty |= d=diff-type + ^- flag + ?: ?=([%txt-diff *] +.+.d) + :: levy produces & on empty lists + %+ levy + diff.d + |= u=(unce cord) ^- flag - ?: ?=([%txt-diff *] +.d) - :: levy produces & on empty lists - %+ levy - diff.d - |= u=(unce cord) - ^- flag - -:u - ?: ?=([%directory-diff *] +.d) - =(p.d q.d) + -:u + ?: ?=([%directory-diff *] +.+.d) =(p.d q.d) + =(p.d q.d) :: +get-file: retrieve a cage of a file from clay :: ++ get-file @@ -75,26 +81,26 @@ :: ++ diff-beams =< - |= [a=beam a-ankh=ankh b=beam b-ankh=ankh] - =/ m (strand ,vase) + |= [a=beam b=beam] + =/ m (strand ,(list diff-type)) ^- form:m - ?> =(s.a s.b) ;< hash-a=@ bind:m (get-from-clay a @ %z) ;< hash-b=@ bind:m (get-from-clay b @ %z) :: if the recursive hashes for each beam are the same we bail early ?: =(hash-a hash-b) - (pure:m !>(*(list diff-type))) - :: vase of a (unit diff-type) - ;< file-diff=vase bind:m (diff-file-contents a a-ankh b b-ankh) + (pure:m *(list diff-type)) + ;< a-arch=arch bind:m (get-from-clay a arch %y) + ;< b-arch=arch bind:m (get-from-clay b arch %y) + ;< file-diff=(unit diff-type) bind:m (diff-file-contents a a-arch b b-arch) :: get distinct files along with shared files - =/ a-keys=(set @t) ~(key by dir.a-ankh) - =/ b-keys=(set @t) ~(key by dir.b-ankh) + =/ a-keys=(set @t) ~(key by dir.a-arch) + =/ b-keys=(set @t) ~(key by dir.b-arch) :: unique children =/ a-unique-children=(set @t) (~(dif in a-keys) b-keys) =/ b-unique-children=(set @t) (~(dif in b-keys) a-keys) - =/ a-unique=(list path) (format-unique-children a a-ankh a-unique-children) - =/ b-unique=(list path) (format-unique-children b b-ankh b-unique-children) - =/ unique-diff=diff-type [s.a %directory-diff a-unique b-unique] + ;< a-unique=(list path) bind:m (format-unique-children a a-arch a-unique-children) + ;< b-unique=(list path) bind:m (format-unique-children b b-arch b-unique-children) + =/ unique-diff=diff-type [s.a s.b %directory-diff a-unique b-unique] :: shared children =/ find-common-diffs |. @@ -105,25 +111,25 @@ =* loop $ ^- form:m ?~ common-children - (pure:m !>(acc)) + (pure:m acc) =/ child=@t i.common-children =/ new-a=beam a(s (snoc s.a child)) =/ new-b=beam b(s (snoc s.b child)) - ;< res=vase bind:m - (diff-beams new-a (~(got by dir.a-ankh) child) new-b (~(got by dir.b-ankh) child)) + ;< diffs=(list diff-type) bind:m + (diff-beams new-a new-b) :: ;< introduces another $ so we use "loop" instead. %= loop - acc (weld !<((list diff-type) res) acc) + acc (weld diffs acc) common-children t.common-children == - ;< common-diffs=vase bind:m (find-common-diffs) + ;< common-diffs=(list diff-type) bind:m (find-common-diffs) %- pure:m - !> ^- (list diff-type) + ^- (list diff-type) %+ skip ;: weld - (drop !<((unit diff-type) file-diff)) + (drop file-diff) [unique-diff ~] - !<((list diff-type) common-diffs) + common-diffs == diff-is-empty |% @@ -131,66 +137,62 @@ :: files that are unique within a directory. :: ++ format-unique-children - =< - |= [bem=beam ank=ankh children=(set @t)] - ^- (list path) - %- ~(rep by dir.ank) - |= [[key=@t node=ankh] acc=(list path)] - ^- (list path) - ?. (~(has in children) key) - acc - (weld (get-all-paths node (snoc s.bem key)) acc) - |% - ++ get-all-paths - |= [ank=ankh cur-path=path] - ^- (list path) - :: check for terminal node - ?: =(~(wyt by dir.ank) 0) - ~[cur-path] - %- ~(rep by dir.ank) - |= [[key=@t node=ankh] acc=(list path)] - ^- (list path) - =/ new-path=path (snoc cur-path key) - =/ child-paths=(list path) (get-all-paths node new-path) - (weld child-paths acc) - -- + |= [bem=beam ark=arch children=(set @t)] + =/ m (strand ,(list path)) + ^- form:m + =/ children=(list @t) ~(tap in children) + =| acc=(list path) + |- + =* loop $ + ^- form:m + ?~ children + (pure:m acc) + :: the %t care gives all paths with the specified prefix + ;< res=(list path) bind:m (get-from-clay bem(s (snoc s.bem i.children)) (list path) %t) + %= loop + acc (weld res acc) + children t.children + == :: +diff-file-contents: diff two files at specified beams, :: producing a vase of (unit diff-type) ++ diff-file-contents =< - |= [a=beam a-ankh=ankh b=beam b-ankh=ankh] - =/ m (strand ,vase) + |= [a=beam a-arch=arch b=beam b-arch=arch] + =/ m (strand ,(unit diff-type)) ^- form:m - :: the files must be at the same path - ?> =(s.a s.b) - ?: =(fil.a-ankh fil.b-ankh) - (pure:m !>(*(unit diff-type))) - ?~ fil.a-ankh + ?: =(fil.a-arch fil.b-arch) + (pure:m *(unit diff-type)) + ?~ fil.a-arch :: only b has contents %- pure:m - !> ^- (unit diff-type) + ^- (unit diff-type) %- some - :+ s.a + :^ s.a + s.b %txt-diff :_ ~ ^- (unce cord) :+ %| ~ ~[(format-file-content-missing s.b q.b)] - ?~ fil.b-ankh + ?~ fil.b-arch :: only a has contents %- pure:m - !> ^- (unit diff-type) + ^- (unit diff-type) %- some - :+ s.a + :^ s.a + s.b %txt-diff :_ ~ ^- (unce cord) :+ %| ~[(format-file-content-missing s.a q.a)] ~ - :: have two file contents - diff them + :: have two file contents - check that they have + :: the same mark. =/ mar=mark -:(flop s.a) + ?: !=(mar -:(flop s.b)) + (strand-fail:strandio %files-not-same-type >s.a< >s.b< ~) ;< =a=cage bind:m (get-file a) ;< =b=cage bind:m (get-file b) ;< =dais:clay bind:m (build-mark:strandio -.a mar) @@ -198,14 +200,16 @@ :: for all other marks we just take the mug) %- pure:m ?: =(form:dais %txt-diff) - !> ^- (unit diff-type) + ^- (unit diff-type) %- some - :+ s.a + :^ s.a + s.b %txt-diff !<((urge cord) (~(diff dais q.a-cage) q.b-cage)) - !> ^- (unit diff-type) + ^- (unit diff-type) %- some - :+ s.a + :^ s.a + s.b %other :: For some reason, vases for identical files on different desks :: can sometimes have different types. for this reason, we only @@ -225,6 +229,12 @@ == -- -- +:: +format-paths: helper to combine two paths into a tape +:: +++ format-paths + |= [a=path b=path] + ^- tape + ;:(weld " " ) :: +format-directory-diff: helper for producing a tank based on :: a %directory-diff :: @@ -244,11 +254,11 @@ diffs |= [d=diff-type acc=tang] ^- tang - ?: ?=([%txt-diff *] +.d) - [`tank`>pax.d< acc] - ?: ?=([%other *] +.d) - [`tank`>pax.d< acc] - ?: ?=([%directory-diff *] +.d) + ?: ?=([%txt-diff *] +.+.d) + [leaf+(format-paths a.d b.d) acc] + ?: ?=([%other *] +.+.d) + [leaf+(format-paths a.d b.d) acc] + ?: ?=([%directory-diff *] +.+.d) ;: weld (format-directory-diff p.d a) (format-directory-diff q.d b) @@ -265,25 +275,22 @@ diffs |= [d=diff-type acc=tang] ^- tang - ?: ?=([%txt-diff *] +.d) - :: TODO come up with some more readable formatting - :: super ugly when printed. - :- >pax.d< - %+ weld - (turn diff.d |=(u=(unce cord) >u<)) + ?: ?=([%txt-diff *] +.+.d) + :+ leaf+(format-paths a.d b.d) + >diff.d< acc - ?: ?=([%directory-diff *] +.d) + ?: ?=([%directory-diff *] +.+.d) ;: weld (format-directory-diff p.d a) (format-directory-diff q.d b) acc == - ?: ?=([%other *] +.d) + ?: ?=([%other *] +.+.d) :_ acc :- %leaf ;: weld "file " - + " has mug " " on desk " From 20bcb37989d1564bee29b35aea36c5d37f7e9c11 Mon Sep 17 00:00:00 2001 From: raghu <{ID}+{username}@users.noreply.github.com> Date: Tue, 9 Mar 2021 22:34:20 -0500 Subject: [PATCH 4/5] ddiff: always show full beam in diffs --- pkg/arvo/ted/ddiff.hoon | 53 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/pkg/arvo/ted/ddiff.hoon b/pkg/arvo/ted/ddiff.hoon index ec9eadf7d..e74caa15c 100644 --- a/pkg/arvo/ted/ddiff.hoon +++ b/pkg/arvo/ted/ddiff.hoon @@ -22,8 +22,8 @@ :: our tang is built in reverse order %- flop ?: shallow - (format-shallow diffs q.a-beam q.b-beam) -(format-deep diffs q.a-beam q.b-beam) + (format-shallow diffs a-beam b-beam) +(format-deep diffs a-beam b-beam) :: :: $diff-type: type for diffs produced. :: 1. %txt-diff is a standard diff (i.e. for hoon and txt files) @@ -229,35 +229,39 @@ == -- -- -:: +format-paths: helper to combine two paths into a tape +:: +format-beams: helper to combine two beams into a tank :: -++ format-paths - |= [a=path b=path] - ^- tape - ;:(weld " " ) +++ format-beams + |= [a=beam b=beam] + ^- tank + [%rose [" " ~ ~] ~[(smyt (en-beam a)) (smyt (en-beam b))]] :: +format-directory-diff: helper for producing a tank based on :: a %directory-diff :: ++ format-directory-diff - |= [paths=(list path) =desk] + |= [paths=(list path) =beam] ^- tang - =/ prefix=tape ;:(weld "only in " (trip desk) ": ") - (turn paths |=(p=path >(weld prefix

)<)) + =/ prefix=tape (weld "only in " <(en-beam beam)>) + %+ turn + paths + |= p=path + ^- tank + [%rose [": " ~ ~] [leaf+prefix (smyt p) ~]] :: +format-shallow: converts a list of diff-type generated :: between desks a and b into a tang in a shallow manner (just :: listing files that differ). :: ++ format-shallow -|= [diffs=(list diff-type) a=desk b=desk] +|= [diffs=(list diff-type) a=beam b=beam] ^- tang %+ reel diffs |= [d=diff-type acc=tang] ^- tang ?: ?=([%txt-diff *] +.+.d) - [leaf+(format-paths a.d b.d) acc] + [(format-beams a(s a.d) b(s b.d)) acc] ?: ?=([%other *] +.+.d) - [leaf+(format-paths a.d b.d) acc] + [(format-beams a(s a.d) b(s b.d)) acc] ?: ?=([%directory-diff *] +.+.d) ;: weld (format-directory-diff p.d a) @@ -269,14 +273,14 @@ :: between desks a and b into a tang in a deep manner (preserving :: diff information for files) ++ format-deep -|= [diffs=(list diff-type) a=desk b=desk] +|= [diffs=(list diff-type) a=beam b=beam] ^- tang %+ reel diffs |= [d=diff-type acc=tang] ^- tang ?: ?=([%txt-diff *] +.+.d) - :+ leaf+(format-paths a.d b.d) + :+ (format-beams a(s a.d) b(s b.d)) >diff.d< acc ?: ?=([%directory-diff *] +.+.d) @@ -286,19 +290,10 @@ acc == ?: ?=([%other *] +.+.d) - :_ acc - :- %leaf - ;: weld - "file " - - " has mug " - - " on desk " - - " but mug " - - " on desk " - - == + =/ a-tank=tank (smyt (en-beam a(s a.d))) + =/ b-tank=tank (smyt (en-beam b(s b.d))) + :+ [%rose [" " "files " ~] ~[a-tank b-tank]] + [%rose [" and " "have mugs: " ~] ~[leaf+ leaf+]] + acc !! -- From 60a2de143c57059a717823a6604efb7edb39f973 Mon Sep 17 00:00:00 2001 From: raghu <{ID}+{username}@users.noreply.github.com> Date: Fri, 19 Mar 2021 19:43:39 -0400 Subject: [PATCH 5/5] renaming ddiff to diff --- pkg/arvo/ted/ddiff.hoon | 299 ---------------------------------------- pkg/arvo/ted/diff.hoon | 293 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 281 insertions(+), 311 deletions(-) delete mode 100644 pkg/arvo/ted/ddiff.hoon diff --git a/pkg/arvo/ted/ddiff.hoon b/pkg/arvo/ted/ddiff.hoon deleted file mode 100644 index e74caa15c..000000000 --- a/pkg/arvo/ted/ddiff.hoon +++ /dev/null @@ -1,299 +0,0 @@ -/- spider -/+ strandio -=, strand=strand:spider -=, clay -^- thread:spider -|= arg=vase -=/ m (strand ,vase) -^- form:m -|^ -:: workaround to make the shallow flag optional. if it's specified we -:: do require a non-empty path - however this shouldn't be called with -:: empty paths to begin with. -=+ !<([~ =a=path b=$~([/hi &] $^([(lest @ta) flag] path))] arg) -=/ [b-path=path shallow=flag] ?:(?=([^ *] b) b [`path`b |]) -=/ a-beam (need (de-beam a-path)) -=/ b-beam (need (de-beam b-path)) -;< a-dome=dome bind:m (get-from-clay a-beam dome %v) -;< b-dome=dome bind:m (get-from-clay b-beam dome %v) -;< diffs=(list diff-type) bind:m (diff-beams a-beam b-beam) -%- pure:m -!> ^- tang -:: our tang is built in reverse order -%- flop -?: shallow - (format-shallow diffs a-beam b-beam) -(format-deep diffs a-beam b-beam) -:: -:: $diff-type: type for diffs produced. -:: 1. %txt-diff is a standard diff (i.e. for hoon and txt files) -:: 2. %directory-diff shows unique files between two directories -:: 3. %other is for files that don't use txt-diff - we just take -:: the mug of the files -+$ diff-type - :: paths of the diffed beams - $: a=path - b=path - $% [%txt-diff diff=(urge cord)] - [%directory-diff p=(list path) q=(list path)] - [%other p=@ q=@] - == - == -:: +diff-is-empty: check if a diff is empty (for two identical files) -:: -++ diff-is-empty - |= d=diff-type - ^- flag - ?: ?=([%txt-diff *] +.+.d) - :: levy produces & on empty lists - %+ levy - diff.d - |= u=(unce cord) - ^- flag - -:u - ?: ?=([%directory-diff *] +.+.d) - =(p.d q.d) - =(p.d q.d) -:: +get-file: retrieve a cage of a file from clay -:: -++ get-file - |= =beam - =/ m (strand ,cage) - ^- form:m - ;< =riot:clay bind:m - (warp:strandio p.beam q.beam ~ %sing %x r.beam s.beam) - ?~ riot - (strand-fail:strandio %file-not-found >s.beam< ~) - (pure:m r.u.riot) -:: +get-from-clay: retrieve other data from clay based on care -:: -++ get-from-clay - |* [=beam mol=mold =care] - =/ m (strand ,mol) - ^- form:m - ;< =riot:clay bind:m - (warp:strandio p.beam q.beam ~ %sing care r.beam s.beam) - ?~ riot - (strand-fail:strandio %file-not-found >s.beam< ~) - (pure:m !<(mol q.r.u.riot)) -:: +diff-beams: recursively diff two beams. produces a vase -:: of (list diff-type) -:: -++ diff-beams - =< - |= [a=beam b=beam] - =/ m (strand ,(list diff-type)) - ^- form:m - ;< hash-a=@ bind:m (get-from-clay a @ %z) - ;< hash-b=@ bind:m (get-from-clay b @ %z) - :: if the recursive hashes for each beam are the same we bail early - ?: =(hash-a hash-b) - (pure:m *(list diff-type)) - ;< a-arch=arch bind:m (get-from-clay a arch %y) - ;< b-arch=arch bind:m (get-from-clay b arch %y) - ;< file-diff=(unit diff-type) bind:m (diff-file-contents a a-arch b b-arch) - :: get distinct files along with shared files - =/ a-keys=(set @t) ~(key by dir.a-arch) - =/ b-keys=(set @t) ~(key by dir.b-arch) - :: unique children - =/ a-unique-children=(set @t) (~(dif in a-keys) b-keys) - =/ b-unique-children=(set @t) (~(dif in b-keys) a-keys) - ;< a-unique=(list path) bind:m (format-unique-children a a-arch a-unique-children) - ;< b-unique=(list path) bind:m (format-unique-children b b-arch b-unique-children) - =/ unique-diff=diff-type [s.a s.b %directory-diff a-unique b-unique] - :: shared children - =/ find-common-diffs - |. - ^- form:m - =| acc=(list diff-type) - =/ common-children=(list @t) ~(tap in (~(int in a-keys) b-keys)) - |- - =* loop $ - ^- form:m - ?~ common-children - (pure:m acc) - =/ child=@t i.common-children - =/ new-a=beam a(s (snoc s.a child)) - =/ new-b=beam b(s (snoc s.b child)) - ;< diffs=(list diff-type) bind:m - (diff-beams new-a new-b) - :: ;< introduces another $ so we use "loop" instead. - %= loop - acc (weld diffs acc) - common-children t.common-children - == - ;< common-diffs=(list diff-type) bind:m (find-common-diffs) - %- pure:m - ^- (list diff-type) - %+ skip - ;: weld - (drop file-diff) - [unique-diff ~] - common-diffs - == - diff-is-empty - |% - :: +format-unique-children: produce list of paths representing - :: files that are unique within a directory. - :: - ++ format-unique-children - |= [bem=beam ark=arch children=(set @t)] - =/ m (strand ,(list path)) - ^- form:m - =/ children=(list @t) ~(tap in children) - =| acc=(list path) - |- - =* loop $ - ^- form:m - ?~ children - (pure:m acc) - :: the %t care gives all paths with the specified prefix - ;< res=(list path) bind:m (get-from-clay bem(s (snoc s.bem i.children)) (list path) %t) - %= loop - acc (weld res acc) - children t.children - == - :: +diff-file-contents: diff two files at specified beams, - :: producing a vase of (unit diff-type) - ++ diff-file-contents - =< - |= [a=beam a-arch=arch b=beam b-arch=arch] - =/ m (strand ,(unit diff-type)) - ^- form:m - ?: =(fil.a-arch fil.b-arch) - (pure:m *(unit diff-type)) - ?~ fil.a-arch - :: only b has contents - %- pure:m - ^- (unit diff-type) - %- some - :^ s.a - s.b - %txt-diff - :_ ~ - ^- (unce cord) - :+ %| - ~ - ~[(format-file-content-missing s.b q.b)] - ?~ fil.b-arch - :: only a has contents - %- pure:m - ^- (unit diff-type) - %- some - :^ s.a - s.b - %txt-diff - :_ ~ - ^- (unce cord) - :+ %| - ~[(format-file-content-missing s.a q.a)] - ~ - :: have two file contents - check that they have - :: the same mark. - =/ mar=mark -:(flop s.a) - ?: !=(mar -:(flop s.b)) - (strand-fail:strandio %files-not-same-type >s.a< >s.b< ~) - ;< =a=cage bind:m (get-file a) - ;< =b=cage bind:m (get-file b) - ;< =dais:clay bind:m (build-mark:strandio -.a mar) - :: for txt-diff we produce an actual diff with type (urge cord). - :: for all other marks we just take the mug) - %- pure:m - ?: =(form:dais %txt-diff) - ^- (unit diff-type) - %- some - :^ s.a - s.b - %txt-diff - !<((urge cord) (~(diff dais q.a-cage) q.b-cage)) - ^- (unit diff-type) - %- some - :^ s.a - s.b - %other - :: For some reason, vases for identical files on different desks - :: can sometimes have different types. for this reason, we only - :: take the mug of the data. - [(mug q.q.a-cage) (mug q.q.b-cage)] - |% - ++ format-file-content-missing - |= [p=path d=desk] - ^- cord - %- crip - ;: weld - "only " -

- " in desk " - - " has file contents" - == - -- - -- -:: +format-beams: helper to combine two beams into a tank -:: -++ format-beams - |= [a=beam b=beam] - ^- tank - [%rose [" " ~ ~] ~[(smyt (en-beam a)) (smyt (en-beam b))]] -:: +format-directory-diff: helper for producing a tank based on -:: a %directory-diff -:: -++ format-directory-diff - |= [paths=(list path) =beam] - ^- tang - =/ prefix=tape (weld "only in " <(en-beam beam)>) - %+ turn - paths - |= p=path - ^- tank - [%rose [": " ~ ~] [leaf+prefix (smyt p) ~]] -:: +format-shallow: converts a list of diff-type generated -:: between desks a and b into a tang in a shallow manner (just -:: listing files that differ). -:: -++ format-shallow -|= [diffs=(list diff-type) a=beam b=beam] - ^- tang - %+ reel - diffs - |= [d=diff-type acc=tang] - ^- tang - ?: ?=([%txt-diff *] +.+.d) - [(format-beams a(s a.d) b(s b.d)) acc] - ?: ?=([%other *] +.+.d) - [(format-beams a(s a.d) b(s b.d)) acc] - ?: ?=([%directory-diff *] +.+.d) - ;: weld - (format-directory-diff p.d a) - (format-directory-diff q.d b) - acc - == - !! -:: +format-deep: converts a list of diff-type generated -:: between desks a and b into a tang in a deep manner (preserving -:: diff information for files) -++ format-deep -|= [diffs=(list diff-type) a=beam b=beam] - ^- tang - %+ reel - diffs - |= [d=diff-type acc=tang] - ^- tang - ?: ?=([%txt-diff *] +.+.d) - :+ (format-beams a(s a.d) b(s b.d)) - >diff.d< - acc - ?: ?=([%directory-diff *] +.+.d) - ;: weld - (format-directory-diff p.d a) - (format-directory-diff q.d b) - acc - == - ?: ?=([%other *] +.+.d) - =/ a-tank=tank (smyt (en-beam a(s a.d))) - =/ b-tank=tank (smyt (en-beam b(s b.d))) - :+ [%rose [" " "files " ~] ~[a-tank b-tank]] - [%rose [" and " "have mugs: " ~] ~[leaf+ leaf+]] - acc - !! --- diff --git a/pkg/arvo/ted/diff.hoon b/pkg/arvo/ted/diff.hoon index b69fcb72d..e74caa15c 100644 --- a/pkg/arvo/ted/diff.hoon +++ b/pkg/arvo/ted/diff.hoon @@ -1,30 +1,299 @@ /- spider /+ strandio =, strand=strand:spider +=, clay ^- thread:spider |= arg=vase =/ m (strand ,vase) ^- form:m |^ -=+ !<([~ =a=path =b=path] arg) -=/ a-mark=mark -:(flop a-path) -=/ b-mark=mark -:(flop b-path) -?. =(a-mark b-mark) - (strand-fail:strandio %files-not-same-type ~) +:: workaround to make the shallow flag optional. if it's specified we +:: do require a non-empty path - however this shouldn't be called with +:: empty paths to begin with. +=+ !<([~ =a=path b=$~([/hi &] $^([(lest @ta) flag] path))] arg) +=/ [b-path=path shallow=flag] ?:(?=([^ *] b) b [`path`b |]) =/ a-beam (need (de-beam a-path)) -;< =a=cage bind:m (get-file a-path) -;< =b=cage bind:m (get-file b-path) -;< =dais:clay bind:m (build-mark:strandio -.a-beam a-mark) -(pure:m (~(diff dais q.a-cage) q.b-cage)) +=/ b-beam (need (de-beam b-path)) +;< a-dome=dome bind:m (get-from-clay a-beam dome %v) +;< b-dome=dome bind:m (get-from-clay b-beam dome %v) +;< diffs=(list diff-type) bind:m (diff-beams a-beam b-beam) +%- pure:m +!> ^- tang +:: our tang is built in reverse order +%- flop +?: shallow + (format-shallow diffs a-beam b-beam) +(format-deep diffs a-beam b-beam) +:: +:: $diff-type: type for diffs produced. +:: 1. %txt-diff is a standard diff (i.e. for hoon and txt files) +:: 2. %directory-diff shows unique files between two directories +:: 3. %other is for files that don't use txt-diff - we just take +:: the mug of the files ++$ diff-type + :: paths of the diffed beams + $: a=path + b=path + $% [%txt-diff diff=(urge cord)] + [%directory-diff p=(list path) q=(list path)] + [%other p=@ q=@] + == + == +:: +diff-is-empty: check if a diff is empty (for two identical files) +:: +++ diff-is-empty + |= d=diff-type + ^- flag + ?: ?=([%txt-diff *] +.+.d) + :: levy produces & on empty lists + %+ levy + diff.d + |= u=(unce cord) + ^- flag + -:u + ?: ?=([%directory-diff *] +.+.d) + =(p.d q.d) + =(p.d q.d) +:: +get-file: retrieve a cage of a file from clay :: ++ get-file - |= =path + |= =beam =/ m (strand ,cage) ^- form:m - =/ beam (need (de-beam path)) ;< =riot:clay bind:m (warp:strandio p.beam q.beam ~ %sing %x r.beam s.beam) ?~ riot - (strand-fail:strandio %file-not-found >path< ~) + (strand-fail:strandio %file-not-found >s.beam< ~) (pure:m r.u.riot) +:: +get-from-clay: retrieve other data from clay based on care +:: +++ get-from-clay + |* [=beam mol=mold =care] + =/ m (strand ,mol) + ^- form:m + ;< =riot:clay bind:m + (warp:strandio p.beam q.beam ~ %sing care r.beam s.beam) + ?~ riot + (strand-fail:strandio %file-not-found >s.beam< ~) + (pure:m !<(mol q.r.u.riot)) +:: +diff-beams: recursively diff two beams. produces a vase +:: of (list diff-type) +:: +++ diff-beams + =< + |= [a=beam b=beam] + =/ m (strand ,(list diff-type)) + ^- form:m + ;< hash-a=@ bind:m (get-from-clay a @ %z) + ;< hash-b=@ bind:m (get-from-clay b @ %z) + :: if the recursive hashes for each beam are the same we bail early + ?: =(hash-a hash-b) + (pure:m *(list diff-type)) + ;< a-arch=arch bind:m (get-from-clay a arch %y) + ;< b-arch=arch bind:m (get-from-clay b arch %y) + ;< file-diff=(unit diff-type) bind:m (diff-file-contents a a-arch b b-arch) + :: get distinct files along with shared files + =/ a-keys=(set @t) ~(key by dir.a-arch) + =/ b-keys=(set @t) ~(key by dir.b-arch) + :: unique children + =/ a-unique-children=(set @t) (~(dif in a-keys) b-keys) + =/ b-unique-children=(set @t) (~(dif in b-keys) a-keys) + ;< a-unique=(list path) bind:m (format-unique-children a a-arch a-unique-children) + ;< b-unique=(list path) bind:m (format-unique-children b b-arch b-unique-children) + =/ unique-diff=diff-type [s.a s.b %directory-diff a-unique b-unique] + :: shared children + =/ find-common-diffs + |. + ^- form:m + =| acc=(list diff-type) + =/ common-children=(list @t) ~(tap in (~(int in a-keys) b-keys)) + |- + =* loop $ + ^- form:m + ?~ common-children + (pure:m acc) + =/ child=@t i.common-children + =/ new-a=beam a(s (snoc s.a child)) + =/ new-b=beam b(s (snoc s.b child)) + ;< diffs=(list diff-type) bind:m + (diff-beams new-a new-b) + :: ;< introduces another $ so we use "loop" instead. + %= loop + acc (weld diffs acc) + common-children t.common-children + == + ;< common-diffs=(list diff-type) bind:m (find-common-diffs) + %- pure:m + ^- (list diff-type) + %+ skip + ;: weld + (drop file-diff) + [unique-diff ~] + common-diffs + == + diff-is-empty + |% + :: +format-unique-children: produce list of paths representing + :: files that are unique within a directory. + :: + ++ format-unique-children + |= [bem=beam ark=arch children=(set @t)] + =/ m (strand ,(list path)) + ^- form:m + =/ children=(list @t) ~(tap in children) + =| acc=(list path) + |- + =* loop $ + ^- form:m + ?~ children + (pure:m acc) + :: the %t care gives all paths with the specified prefix + ;< res=(list path) bind:m (get-from-clay bem(s (snoc s.bem i.children)) (list path) %t) + %= loop + acc (weld res acc) + children t.children + == + :: +diff-file-contents: diff two files at specified beams, + :: producing a vase of (unit diff-type) + ++ diff-file-contents + =< + |= [a=beam a-arch=arch b=beam b-arch=arch] + =/ m (strand ,(unit diff-type)) + ^- form:m + ?: =(fil.a-arch fil.b-arch) + (pure:m *(unit diff-type)) + ?~ fil.a-arch + :: only b has contents + %- pure:m + ^- (unit diff-type) + %- some + :^ s.a + s.b + %txt-diff + :_ ~ + ^- (unce cord) + :+ %| + ~ + ~[(format-file-content-missing s.b q.b)] + ?~ fil.b-arch + :: only a has contents + %- pure:m + ^- (unit diff-type) + %- some + :^ s.a + s.b + %txt-diff + :_ ~ + ^- (unce cord) + :+ %| + ~[(format-file-content-missing s.a q.a)] + ~ + :: have two file contents - check that they have + :: the same mark. + =/ mar=mark -:(flop s.a) + ?: !=(mar -:(flop s.b)) + (strand-fail:strandio %files-not-same-type >s.a< >s.b< ~) + ;< =a=cage bind:m (get-file a) + ;< =b=cage bind:m (get-file b) + ;< =dais:clay bind:m (build-mark:strandio -.a mar) + :: for txt-diff we produce an actual diff with type (urge cord). + :: for all other marks we just take the mug) + %- pure:m + ?: =(form:dais %txt-diff) + ^- (unit diff-type) + %- some + :^ s.a + s.b + %txt-diff + !<((urge cord) (~(diff dais q.a-cage) q.b-cage)) + ^- (unit diff-type) + %- some + :^ s.a + s.b + %other + :: For some reason, vases for identical files on different desks + :: can sometimes have different types. for this reason, we only + :: take the mug of the data. + [(mug q.q.a-cage) (mug q.q.b-cage)] + |% + ++ format-file-content-missing + |= [p=path d=desk] + ^- cord + %- crip + ;: weld + "only " +

+ " in desk " + + " has file contents" + == + -- + -- +:: +format-beams: helper to combine two beams into a tank +:: +++ format-beams + |= [a=beam b=beam] + ^- tank + [%rose [" " ~ ~] ~[(smyt (en-beam a)) (smyt (en-beam b))]] +:: +format-directory-diff: helper for producing a tank based on +:: a %directory-diff +:: +++ format-directory-diff + |= [paths=(list path) =beam] + ^- tang + =/ prefix=tape (weld "only in " <(en-beam beam)>) + %+ turn + paths + |= p=path + ^- tank + [%rose [": " ~ ~] [leaf+prefix (smyt p) ~]] +:: +format-shallow: converts a list of diff-type generated +:: between desks a and b into a tang in a shallow manner (just +:: listing files that differ). +:: +++ format-shallow +|= [diffs=(list diff-type) a=beam b=beam] + ^- tang + %+ reel + diffs + |= [d=diff-type acc=tang] + ^- tang + ?: ?=([%txt-diff *] +.+.d) + [(format-beams a(s a.d) b(s b.d)) acc] + ?: ?=([%other *] +.+.d) + [(format-beams a(s a.d) b(s b.d)) acc] + ?: ?=([%directory-diff *] +.+.d) + ;: weld + (format-directory-diff p.d a) + (format-directory-diff q.d b) + acc + == + !! +:: +format-deep: converts a list of diff-type generated +:: between desks a and b into a tang in a deep manner (preserving +:: diff information for files) +++ format-deep +|= [diffs=(list diff-type) a=beam b=beam] + ^- tang + %+ reel + diffs + |= [d=diff-type acc=tang] + ^- tang + ?: ?=([%txt-diff *] +.+.d) + :+ (format-beams a(s a.d) b(s b.d)) + >diff.d< + acc + ?: ?=([%directory-diff *] +.+.d) + ;: weld + (format-directory-diff p.d a) + (format-directory-diff q.d b) + acc + == + ?: ?=([%other *] +.+.d) + =/ a-tank=tank (smyt (en-beam a(s a.d))) + =/ b-tank=tank (smyt (en-beam b(s b.d))) + :+ [%rose [" " "files " ~] ~[a-tank b-tank]] + [%rose [" and " "have mugs: " ~] ~[leaf+ leaf+]] + acc + !! --