Skip to content

Commit 8065abc

Browse files
committed
Ensure we show messages on the final causal
1 parent f5cecd1 commit 8065abc

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

unison-cli/src/Unison/Codebase/Editor/HandleInput/History.hs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@ handleHistory resultsCap diffCap from = do
3232
doHistory :: Int -> Int -> Branch IO -> [(CausalHash, Maybe Text, Names.Diff)] -> Cli.Cli NumberedOutput
3333
doHistory schLength !n b acc =
3434
if maybe False (n >=) resultsCap
35-
then pure (History diffCap schLength acc (PageEnd (Branch.headHash b) n))
35+
then do
36+
mayComment <- getComment $ Branch.headHash b
37+
pure (History diffCap schLength acc (mayComment, PageEnd (Branch.headHash b) n))
3638
else case Branch._history b of
37-
Causal.One {} -> pure (History diffCap schLength acc (EndOfLog $ Branch.headHash b))
38-
Causal.Merge _ _ _ tails ->
39-
pure (History diffCap schLength acc (MergeTail (Branch.headHash b) $ Map.keys tails))
39+
Causal.One {} -> do
40+
mayComment <- getComment $ Branch.headHash b
41+
pure (History diffCap schLength acc (mayComment, EndOfLog $ Branch.headHash b))
42+
Causal.Merge _ _ _ tails -> do
43+
mayComment <- getComment $ Branch.headHash b
44+
pure (History diffCap schLength acc (mayComment, MergeTail (Branch.headHash b) $ Map.keys tails))
4045
Causal.Cons _ _ _ tail -> do
4146
b' <- liftIO $ fmap Branch.Branch $ snd tail
4247
let causalHash = Branch.headHash b
43-
mayComment <- Cli.runTransaction $ do
44-
causalHashId <- Q.expectCausalHashIdByCausalHash causalHash
45-
fmap snd <$> Q.getLatestCausalAnnotation causalHashId
48+
mayComment <- getComment causalHash
4649
let elem = (causalHash, mayComment, Branch.namesDiff b' b)
4750
doHistory schLength (n + 1) b' (elem : acc)
51+
getComment ch = Cli.runTransaction $ do
52+
causalHashId <- Q.expectCausalHashIdByCausalHash ch
53+
fmap snd <$> Q.getLatestCausalAnnotation causalHashId

unison-cli/src/Unison/Codebase/Editor/Output.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ data NumberedOutput
134134
(Maybe Int) -- Amount of history to print
135135
HashLength
136136
[(CausalHash, Maybe Text {- change comments -}, Names.Diff)]
137-
HistoryTail -- 'origin point' of this view of history.
137+
(Maybe Text, HistoryTail) -- 'origin point' of this view of history.
138138
| ListProjects [Sqlite.Project]
139139
| ListBranches ProjectName [(ProjectBranchName, [(URI, ProjectName, ProjectBranchName)])]
140140
| AmbiguousSwitch ProjectName (ProjectAndBranch ProjectName ProjectBranchName)

unison-cli/src/Unison/CommandLine/OutputMessages.hs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -319,33 +319,40 @@ notifyNumbered = \case
319319
reversedHistory = reverse history
320320
showNum :: Int -> Pretty
321321
showNum n = P.shown n <> ". "
322+
displayComment prefixSpacer mayComment = case mayComment of
323+
Nothing -> []
324+
Just comment ->
325+
Monoid.whenM prefixSpacer [""] <> [P.indentN 2 (P.yellow $ P.text comment) <> P.newline]
322326
handleTail :: Int -> (Pretty, [CausalHash])
323327
handleTail n = case tail of
324-
E.EndOfLog h ->
325-
( P.lines
328+
(mayComment, E.EndOfLog h) ->
329+
( P.lines $
326330
[ "" <> showNum n <> prettySCH (toSCH h) <> " (start of history)"
327-
],
331+
]
332+
<> displayComment True mayComment,
328333
[h]
329334
)
330-
E.MergeTail h hs ->
331-
( P.lines
335+
(mayComment, E.MergeTail h hs) ->
336+
( P.lines $
332337
[ P.wrap $ "This segment of history starts with a merge." <> ex,
333338
"",
334-
"" <> showNum n <> prettySCH (toSCH h),
335-
"",
336-
P.lines (hs & imap \i h -> showNum (n + 1 + i) <> prettySCH (toSCH h))
337-
],
339+
"" <> showNum n <> prettySCH (toSCH h)
340+
]
341+
<> displayComment True mayComment
342+
<> [ "",
343+
P.lines (hs & imap \i h -> showNum (n + 1 + i) <> prettySCH (toSCH h))
344+
],
338345
h : hs
339346
)
340-
E.PageEnd h _n ->
341-
( P.lines
347+
(mayComment, E.PageEnd h _n) ->
348+
( P.lines $
342349
[ P.wrap $ "There's more history before the versions shown here." <> ex,
343350
"",
344351
dots,
345352
"",
346-
"" <> showNum n <> prettySCH (toSCH h),
347-
""
348-
],
353+
"" <> showNum n <> prettySCH (toSCH h)
354+
]
355+
<> displayComment True mayComment,
349356
[h]
350357
)
351358
dots = ""
@@ -354,12 +361,7 @@ notifyNumbered = \case
354361
[ "" <> showNum i <> prettySCH sch,
355362
""
356363
]
357-
<> case mayComment of
358-
Nothing -> []
359-
Just comment ->
360-
[ P.indentN 2 (P.yellow $ P.text comment),
361-
""
362-
]
364+
<> displayComment False mayComment
363365
<> [ P.indentN 2 $ prettyDiff diff
364366
]
365367
ex =

0 commit comments

Comments
 (0)