Skip to content

Commit 638dfc2

Browse files
committed
Finish implementing more commit comments
1 parent cc371a0 commit 638dfc2

File tree

7 files changed

+56
-43
lines changed

7 files changed

+56
-43
lines changed

codebase2/codebase-sqlite/U/Codebase/Sqlite/HistoryComment.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ module U.Codebase.Sqlite.HistoryComment (HistoryComment (..)) where
22

33
import Data.Text (Text)
44

5-
data HistoryComment id = HistoryComment
5+
data HistoryComment causal id
6+
= HistoryComment
67
{ author :: Text,
78
subject :: Text,
89
content :: Text,
10+
causal :: causal,
911
commentId :: id
1012
}
1113
deriving (Show, Eq, Functor)

codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,42 +4044,42 @@ saveSquashResult bhId chId =
40444044

40454045
getLatestCausalComment ::
40464046
CausalHashId ->
4047-
Transaction (Maybe (HistoryComment HistoryCommentId))
4047+
Transaction (Maybe (HistoryComment CausalHashId HistoryCommentId))
40484048
getLatestCausalComment causalHashId =
4049-
queryMaybeRow @(Text, Text, Text, HistoryCommentId)
4049+
queryMaybeRow @(HistoryCommentId, CausalHashId, Text, Text, Text)
40504050
[sql|
4051-
SELECT cc.id, ccr.contents
4052-
FROM change_comments AS cc
4053-
JOIN change_comment_revisions AS ccr ON cc.id = ccr.comment_id
4051+
SELECT cc.id, cc.causal_hash_id, cc.author, ccr.subject, ccr.contents
4052+
FROM history_comments AS cc
4053+
JOIN history_comment_revisions AS ccr ON cc.id = ccr.comment_id
40544054
WHERE cc.causal_hash_id = :causalHashId
40554055
ORDER BY ccr.created_at DESC
40564056
LIMIT 1
40574057
|]
4058-
<&> fmap \(author, subject, content, commentId) ->
4059-
HistoryComment {author, subject, content, commentId}
4058+
<&> fmap \(commentId, causal, author, subject, content) ->
4059+
HistoryComment {author, subject, content, commentId, causal}
40604060

4061-
commentOnCausal :: AuthorName -> CausalHashId -> Text -> Transaction ()
4062-
commentOnCausal authorName causalHashId contents = do
4061+
commentOnCausal :: HistoryComment CausalHashId () -> Transaction ()
4062+
commentOnCausal HistoryComment {author, content, subject, causal = causalHashId} = do
40634063
mayExistingCommentId <-
40644064
queryMaybeCol @HistoryCommentId
40654065
[sql|
40664066
SELECT id
4067-
FROM change_comments
4067+
FROM history_comments
40684068
WHERE causal_hash_id = :causalHashId
40694069
|]
40704070
commentId <- case mayExistingCommentId of
40714071
Nothing ->
40724072
queryOneCol @HistoryCommentId
40734073
[sql|
4074-
INSERT INTO change_comments (author, causal_hash_id, created_at)
4075-
VALUES (:authorName, :causalHashId, strftime('%s', 'now', 'subsec'))
4074+
INSERT INTO history_comments (author, causal_hash_id, created_at)
4075+
VALUES (:author, :causalHashId, strftime('%s', 'now', 'subsec'))
40764076
RETURNING id
40774077
|]
40784078
Just cid -> pure cid
40794079
execute
40804080
[sql|
4081-
INSERT INTO change_comment_revisions (comment_id, contents, created_at)
4082-
VALUES (:commentId, :contents, strftime('%s', 'now', 'subsec'))
4081+
INSERT INTO history_comment_revisions (comment_id, subject, contents, created_at)
4082+
VALUES (:commentId, :subject, :content, strftime('%s', 'now', 'subsec'))
40834083
|]
40844084

40854085
getAuthorName :: Transaction (Maybe AuthorName)

codebase2/codebase-sqlite/sql/020-add-history-comments.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ CREATE TABLE config (
44
value TEXT NOT NULL
55
);
66

7-
-- Add tables for storing change comments
7+
-- Add tables for storing history comments
88
-- These tables deliberately contain less information than we'll probably need, with the
99
-- plan that we'll migrate them and add new features on the way.
1010

11-
CREATE TABLE change_comments (
11+
CREATE TABLE history_comments (
1212
id INTEGER PRIMARY KEY,
1313
causal_hash_id INTEGER REFERENCES hash(id) NOT NULL,
1414
author TEXT NOT NULL,
@@ -19,10 +19,11 @@ CREATE TABLE change_comments (
1919
created_at TEXT NOT NULL
2020
);
2121

22-
CREATE INDEX change_comments_by_causal_hash_id ON change_comments(causal_hash_id, created_at DESC);
22+
CREATE INDEX history_comments_by_causal_hash_id ON history_comments(causal_hash_id, created_at DESC);
2323

24-
CREATE TABLE change_comment_revisions (
25-
comment_id INTEGER REFERENCES change_comments(id),
24+
CREATE TABLE history_comment_revisions (
25+
comment_id INTEGER REFERENCES history_comments(id),
26+
subject TEXT NOT NULL,
2627
contents TEXT NOT NULL,
2728

2829
-- Remember that SQLITE doesn't have any actual 'time' type,
@@ -35,4 +36,4 @@ CREATE TABLE change_comment_revisions (
3536
hidden BOOL NOT NULL DEFAULT FALSE
3637
);
3738

38-
CREATE INDEX change_comment_revisions_by_comment_id_and_created_at ON change_comment_revisions(comment_id, created_at DESC);
39+
CREATE INDEX history_comment_revisions_by_comment_id_and_created_at ON history_comment_revisions(comment_id, created_at DESC);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Unison.Codebase.Editor.HandleInput.History (handleHistory) where
22

33
import Data.Map qualified as Map
44
import U.Codebase.HashTags
5-
import U.Codebase.Sqlite.HistoryComment (HistoryComment)
5+
import U.Codebase.Sqlite.HistoryComment (HistoryComment (..))
66
import U.Codebase.Sqlite.Queries qualified as Q
77
import Unison.Cli.Monad qualified as Cli
88
import Unison.Cli.MonadUtils qualified as Cli
@@ -30,7 +30,7 @@ handleHistory resultsCap diffCap from = do
3030
history <- doHistory schLength 0 branch []
3131
Cli.respondNumbered history
3232
where
33-
doHistory :: Int -> Int -> Branch IO -> [(CausalHash, Maybe (HistoryComment ()), Names.Diff)] -> Cli.Cli NumberedOutput
33+
doHistory :: Int -> Int -> Branch IO -> [(CausalHash, Maybe (HistoryComment () ()), Names.Diff)] -> Cli.Cli NumberedOutput
3434
doHistory schLength !n b acc =
3535
if maybe False (n >=) resultsCap
3636
then do
@@ -49,8 +49,8 @@ handleHistory resultsCap diffCap from = do
4949
mayComment <- getComment causalHash
5050
let elem = (causalHash, mayComment, Branch.namesDiff b' b)
5151
doHistory schLength (n + 1) b' (elem : acc)
52-
getComment :: CausalHash -> Cli.Cli (Maybe (HistoryComment ()))
52+
getComment :: CausalHash -> Cli.Cli (Maybe (HistoryComment () ()))
5353
getComment ch = Cli.runTransaction $ do
5454
causalHashId <- Q.expectCausalHashIdByCausalHash ch
5555
Q.getLatestCausalComment causalHashId
56-
<&> fmap void
56+
<&> fmap \hc -> hc {causal = (), commentId = ()}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Unison.Codebase.Editor.HandleInput.HistoryComment (handleHistoryComment)
33
import Data.Text qualified as Text
44
import Data.Text.IO qualified as Text
55
import Text.RawString.QQ (r)
6+
import U.Codebase.Config qualified as Config
67
import U.Codebase.Sqlite.HistoryComment (HistoryComment (..))
78
import U.Codebase.Sqlite.Queries qualified as Q
89
import Unison.Cli.Monad (Cli)
@@ -54,8 +55,9 @@ handleHistoryComment mayThingToAnnotate = do
5455
mayNewMessage <- liftIO (editMessage (Just populatedMsg))
5556
case mayNewMessage of
5657
Nothing -> Cli.respond $ CommentAborted
57-
Just newMessage -> do
58-
Cli.runTransaction $ Q.commentOnCausal authorName causalHashId newMessage
58+
Just (subject, content) -> do
59+
let historyComment = HistoryComment {author = Config.unAuthorName authorName, subject, content, commentId = (), causal = causalHashId}
60+
Cli.runTransaction $ Q.commentOnCausal historyComment
5961
Cli.respond $ CommentedSuccessfully
6062
where
6163
commentInstructions =
@@ -84,7 +86,7 @@ getEditorProgram = runMaybeT $ do
8486

8587
-- | Trigger the user's preferred editing workflow to edit a message, using the provided message to pre-populate the editor.
8688
-- Returns Nothing if the editor was closed with a non-zero exit code, or the message is empty.
87-
editMessage :: (MonadUnliftIO m) => Maybe Text -> m (Maybe Text)
89+
editMessage :: (MonadUnliftIO m) => Maybe Text -> m (Maybe (Text, Text))
8890
editMessage initialMessage = runMaybeT do
8991
editorProg <- MaybeT getEditorProgram
9092
MaybeT $ UnliftIO.withSystemTempFile "ucm-history-comment" $ \tempFilePath tempHandle -> runMaybeT do
@@ -103,4 +105,8 @@ editMessage initialMessage = runMaybeT do
103105
& Text.unlines
104106
& Text.strip
105107
guard $ not (Text.null cleanedResult)
106-
pure cleanedResult
108+
let (subject, contents) =
109+
case Text.lines cleanedResult of
110+
[] -> ("", "")
111+
(s : rest) -> (Text.strip s, Text.strip $ Text.unlines rest)
112+
pure (subject, contents)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ data NumberedOutput
131131
History
132132
(Maybe Int) -- Amount of history to print
133133
HashLength
134-
[(CausalHash, Maybe (HistoryComment ()), Names.Diff)]
135-
(Maybe (HistoryComment ()), HistoryTail) -- 'origin point' of this view of history.
134+
[(CausalHash, Maybe (HistoryComment () ()), Names.Diff)]
135+
(Maybe (HistoryComment () ()), HistoryTail) -- 'origin point' of this view of history.
136136
| ListProjects [Sqlite.Project]
137137
| ListBranches ProjectName [(ProjectBranchName, [(URI, ProjectName, ProjectBranchName)])]
138138
| AmbiguousSwitch ProjectName (ProjectAndBranch ProjectName ProjectBranchName)

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,20 @@ notifyNumbered = \case
302302
reversedHistory = reverse history
303303
showNum :: Int -> Pretty
304304
showNum n = P.shown n <> ". "
305-
displayComment :: Bool -> Maybe (HistoryComment ()) -> [Pretty]
305+
displayComment :: Bool -> Maybe (HistoryComment () ()) -> [Pretty]
306306
displayComment prefixSpacer mayComment = case mayComment of
307307
Nothing -> []
308308
Just (HistoryComment {author, subject, content}) ->
309309
Monoid.whenM prefixSpacer [""]
310-
<> [ P.bold (P.text author),
311-
P.indent (P.blue (P.text "> ")) (P.yellow $ P.text subject),
312-
P.indent (P.blue (P.text "> ")) (P.text content),
313-
""
310+
<> [P.bold (P.text $ "" <> author <> " 💬")]
311+
<> [ P.indent (P.blue " > ") (P.yellow $ P.text subject)
312+
]
313+
<> Monoid.whenM
314+
(not (Text.null content))
315+
[ (P.blue " > "),
316+
P.indent (P.blue " > ") (P.text content)
317+
]
318+
<> [ ""
314319
]
315320
handleTail :: Int -> (Pretty, [CausalHash])
316321
handleTail n = case tail of
@@ -913,20 +918,19 @@ notifyUser dir issueFn = \case
913918
-- defs in the codebase. In some cases it's fine for bindings to
914919
-- shadow codebase names, but you don't want it to capture them in
915920
-- the decompiled output.
916-
917921
let prettyBindings =
918922
P.bracket . P.lines $
919923
P.wrap "The watch expression(s) reference these definitions:"
920924
: ""
921925
: [ P.syntaxToColor $ TermPrinter.prettyBinding ppe (HQ.unsafeFromVar v) b
922-
| (v, b) <- bindings
926+
| (v, b) <- bindings
923927
]
924928
prettyWatches =
925929
P.sep
926930
"\n\n"
927931
[ watchPrinter fileContents ppe ann kind evald isCacheHit
928-
| (ann, kind, evald, isCacheHit) <-
929-
sortOn (\(a, _, _, _) -> a) . toList $ watches
932+
| (ann, kind, evald, isCacheHit) <-
933+
sortOn (\(a, _, _, _) -> a) . toList $ watches
930934
]
931935
in -- todo: use P.nonempty
932936
pure $
@@ -3584,13 +3588,13 @@ listOfDefinitions' fscope ppe detailed results =
35843588
-- where sigs0 = (\(name, _, typ) -> (name, typ)) <$> terms
35853589
termsWithMissingTypes =
35863590
[ (name, Reference.idToShortHash r)
3587-
| SR'.Tm name Nothing (Referent.Ref (Reference.DerivedId r)) _ <- results
3591+
| SR'.Tm name Nothing (Referent.Ref (Reference.DerivedId r)) _ <- results
35883592
]
35893593
missingTypes =
35903594
nubOrdOn snd $
35913595
[(name, r) | SR'.Tp name (MissingObject r) _ _ <- results]
35923596
<> [ (name, Reference.toShortHash r)
3593-
| SR'.Tm name Nothing (Referent.toTypeReference -> Just r) _ <- results
3597+
| SR'.Tm name Nothing (Referent.toTypeReference -> Just r) _ <- results
35943598
]
35953599
missingBuiltins =
35963600
results >>= \case
@@ -3744,7 +3748,7 @@ prettyDiff diff =
37443748
P.column2 $
37453749
(P.hiBlack "Original name", P.hiBlack "New name(s)")
37463750
: [ (prettyName n, P.sep " " (prettyName <$> ns))
3747-
| (n, ns) <- copied
3751+
| (n, ns) <- copied
37483752
]
37493753
]
37503754
else mempty

0 commit comments

Comments
 (0)