urbit/pkg/arvo/gen/story-read.hoon

122 lines
5.5 KiB
Plaintext
Raw Normal View History

2022-02-19 01:40:55 +03:00
:: story: log commits in order
2022-01-21 19:50:42 +03:00
::
::::
::
/- *story
/+ lib=story
2022-01-21 19:50:42 +03:00
:- %say
|= $: [now=@da eny=@uvJ bec=beak]
[[~] =desk ~]
2022-01-21 19:50:42 +03:00
==
|^
=/ our p.bec
=? desk =(*^desk desk) q.bec :: use current desk if user didn't provide
=/ cas=case r.bec :: use case from beak
?: !(~(has in .^((set ^desk) %cd /(scot %p our)/$/(scot %da now))) desk)
tang+[leaf+"Error: desk {<desk>} does not exist." ~]
=/ pax /(scot %p our)/[desk]/(scot cas)/story
?: !.^(? %cu pax) tang+['Error: No story file found. Please use |story-init to create one.' ~]
=/ tale .^(story %cx pax)
=/ current-tako .^(tako:clay %cs /(scot %p our)/[desk]/(scot cas)/tako/~)
=/ current-yaki .^(yaki:clay %cs /(scot %p our)/[desk]/(scot cas)/yaki/(scot %uv current-tako))
2022-01-21 19:50:42 +03:00
:- %tang
2022-02-26 02:27:54 +03:00
(story-read [our desk cas] current-yaki tale)
2022-01-21 19:50:42 +03:00
::::
:: Remarks:
::
2022-02-26 02:27:54 +03:00
:: There are two recursions in the logging process:
2022-01-21 19:50:42 +03:00
:: 1. the outer loop, `commit-loop` which threads downwards into each commit by ancestor
:: 2. the inner loop, `ancestor-loop`, which threads left-to-right on reverse-ancestors
::
2022-02-26 02:27:54 +03:00
:: +story-read outputs a tang with the least-recent commits at the head of the list,
:: even though we want most-recent commits to end up printing first.
:: But because dojo prints tangs in reverse, we don't flop the results
2022-01-21 19:50:42 +03:00
::::
2022-02-26 02:27:54 +03:00
++ story-read
|= [[our=ship syd=^desk cas=case] current-commit=yaki:clay tale=story]
2022-01-21 19:50:42 +03:00
^- tang
%- head :: result from state
2022-01-21 19:50:42 +03:00
=| state=[result=tang mergebase=(unit tako:clay)]
|-
^- _state
=* commit-loop $
=/ reverse-ancestors (flop p.current-commit)
|-
=* ancestor-loop $
?- reverse-ancestors
~
:: stop here and return the current message
=/ msg=(list cord) (msg-from-commit current-commit tale)
[(weld msg result.state) mergebase=~]
2022-01-21 19:50:42 +03:00
::
[tako:clay ~]
=/ parent=tako:clay i.reverse-ancestors
=/ parent-commit .^(yaki:clay %cs /(scot %p our)/[syd]/(scot cas)/yaki/(scot %uv parent))
=/ msg (msg-from-commit current-commit tale)
:: If there is a mergebase and we are visting it right now:
:: stop here and clear the mergebase.
:: skip adding the mergebase's msg itself because it will be added through the other branch
:: Otherwise, record the current message if exists
2022-01-21 19:50:42 +03:00
?: ?&(?=(^ mergebase.state) =(u.mergebase.state r.current-commit))
[result=result.state mergebase=~]
commit-loop(current-commit parent-commit, result.state (weld msg result.state))
2022-01-21 19:50:42 +03:00
::
[tako:clay tako:clay ~]
::
:: mainline: ultimate base chain
:: nowline: relative mainline
2022-01-21 19:50:42 +03:00
:: sideline: side-chain, featurebranch
::
:: From the context of e, commit c is on its relative mainline, or nowline, while commit d is on its sideline
:: %base a--b-------------X :: mainline
:: %new \--c------e--/ :: nowline
:: %new2 \--d--/ :: sideline
::
::
=/ sideline=tako:clay i.reverse-ancestors
=/ mainline=tako:clay i.t.reverse-ancestors
=/ mergebases .^((list tako:clay) %cs /(scot %p our)/[syd]/(scot cas)/base-tako/(scot %uv mainline)/(scot %uv sideline)) :: XX base-tako ignores beak
2022-01-21 19:50:42 +03:00
=/ next-mergebase=(unit tako:clay) ?~(mergebases ~ (some i.mergebases)) :: take the first valid mergebase (by convention) if exists, else none
:: ~& "Debug: Mergebase is null? {<=(~ next-mergebase)>}"
=/ sideline-commit=yaki:clay .^(yaki:clay %cs /(scot %p our)/[syd]/(scot cas)/yaki/(scot %uv sideline))
=/ mainline-commit=yaki:clay .^(yaki:clay %cs /(scot %p our)/[syd]/(scot cas)/yaki/(scot %uv mainline))
=/ msg=(list cord) (msg-from-commit current-commit tale)
2022-01-21 19:50:42 +03:00
::
:: 1 - process current commit
:: 2 - recur and queue processing on all commits on the sideline
:: 3 - recur and queue processing on all commits on the mainline
::
:: Because mainline messages are cons'd to result last, they are
:: (by definition) towards the less recent side of the resulting flopped list
2022-01-21 19:50:42 +03:00
::
=. state [result=(weld msg result.state) mergebase=next-mergebase] :: 1
2022-03-11 18:48:35 +03:00
=. state commit-loop(current-commit sideline-commit) :: 2
=. state commit-loop(current-commit mainline-commit) :: 3
2022-01-21 19:50:42 +03:00
state
::
[tako:clay tako:clay tako:clay *]
~& "in 3+ ancestor commit"
=/ sideline=tako:clay i.reverse-ancestors
=/ nowline=tako:clay i.t.reverse-ancestors
=/ mergebases .^((list tako:clay) %cs /(scot %p our)/[syd]/(scot cas)/base-tako/(scot %uv nowline)/(scot %uv sideline))
2022-01-21 19:50:42 +03:00
=/ next-mergebase=(unit tako:clay) ?~(mergebases ~ (some i.mergebases)) :: take the first valid mergebase (by convention) if exists, else none
=/ sideline-commit=yaki:clay .^(yaki:clay %cs /(scot %p our)/[syd]/(scot cas)/yaki/(scot %uv sideline))
2022-01-21 19:50:42 +03:00
=. mergebase.state next-mergebase
=. state commit-loop(current-commit sideline-commit) :: traverse downwards
=. state ancestor-loop(reverse-ancestors t.reverse-ancestors) :: traverse rightwards
2022-01-21 19:50:42 +03:00
state
==
::
++ msg-from-commit
|= [commit=yaki:clay tale=story]
^- (list cord)
=/ proses (~(get by tale) r.commit)
?~ proses ~
%- flop :: fix formatting reversal in dojo
%- to-wain:format
%- crip
;: welp
(tako-to-text:lib r.commit)
(proses-to-text:lib u.proses)
==
2022-01-21 19:50:42 +03:00
--