Rename hashes to HistoryCommentHash · JavaDerek/unison@d0f702b · GitHub
Skip to content

Commit d0f702b

Browse files
committed
Rename hashes to HistoryCommentHash
1 parent 8b25fe2 commit d0f702b

4 files changed

Lines changed: 75 additions & 69 deletions

File tree

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

Lines changed: 9 additions & 9 deletions

‎codebase2/core/U/Codebase/HashTags.hs‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ newtype CausalHash = CausalHash {unCausalHash :: Hash}
1818
newtype PatchHash = PatchHash {unPatchHash :: Hash}
1919
deriving stock (Eq, Ord)
2020

21-
newtype CommentHash = CommentHash {unCommentHash :: Hash}
21+
newtype HistoryCommentHash = HistoryCommentHash {unHistoryCommentHash :: Hash}
2222
deriving stock (Eq, Ord)
2323

24-
newtype CommentRevisionHash = CommentRevisionHash {unCommentRevisionHash :: Hash}
24+
newtype HistoryCommentRevisionHash = HistoryCommentRevisionHash {unHistoryCommentRevisionHash :: Hash}
2525
deriving stock (Eq, Ord)
2626

2727
instance Show ComponentHash where
@@ -36,11 +36,11 @@ instance Show CausalHash where
3636
instance Show PatchHash where
3737
show h = "PatchHash (" ++ show (unPatchHash h) ++ ")"
3838

39-
instance Show CommentHash where
40-
show h = "CommentHash (" ++ show (unCommentHash h) ++ ")"
39+
instance Show HistoryCommentHash where
40+
show h = "HistoryCommentHash (" ++ show (unHistoryCommentHash h) ++ ")"
4141

42-
instance Show CommentRevisionHash where
43-
show h = "CommentRevisionHash (" ++ show (unCommentRevisionHash h) ++ ")"
42+
instance Show HistoryCommentRevisionHash where
43+
show h = "HistoryCommentRevisionHash (" ++ show (unHistoryCommentRevisionHash h) ++ ")"
4444

4545
instance From ComponentHash Text where
4646
from = from @Hash @Text . unComponentHash
@@ -54,11 +54,11 @@ instance From CausalHash Text where
5454
instance From PatchHash Text where
5555
from = from @Hash @Text . unPatchHash
5656

57-
instance From CommentHash Text where
58-
from = from @Hash @Text . unCommentHash
57+
instance From HistoryCommentHash Text where
58+
from = from @Hash @Text . unHistoryCommentHash
5959

60-
instance From CommentRevisionHash Text where
61-
from = from @Hash @Text . unCommentRevisionHash
60+
instance From HistoryCommentRevisionHash Text where
61+
from = from @Hash @Text . unHistoryCommentRevisionHash
6262

6363
instance From ComponentHash Hash
6464

@@ -68,9 +68,9 @@ instance From CausalHash Hash
6868

6969
instance From PatchHash Hash
7070

71-
instance From CommentHash Hash
71+
instance From HistoryCommentHash Hash
7272

73-
instance From CommentRevisionHash Hash
73+
instance From HistoryCommentRevisionHash Hash
7474

7575
instance From Hash ComponentHash
7676

@@ -80,9 +80,9 @@ instance From Hash CausalHash
8080

8181
instance From Hash PatchHash
8282

83-
instance From Hash CommentHash
83+
instance From Hash HistoryCommentHash
8484

85-
instance From Hash CommentRevisionHash
85+
instance From Hash HistoryCommentRevisionHash
8686

8787
instance From ComponentHash Hash32 where
8888
from = from @Hash @Hash32 . unComponentHash
@@ -108,8 +108,8 @@ instance From Hash32 CausalHash where
108108
instance From Hash32 PatchHash where
109109
from = PatchHash . from @Hash32 @Hash
110110

111-
instance From CommentHash Hash32 where
112-
from = from @Hash @Hash32 . unCommentHash
111+
instance From HistoryCommentHash Hash32 where
112+
from = from @Hash @Hash32 . unHistoryCommentHash
113113

114-
instance From CommentRevisionHash Hash32 where
115-
from = from @Hash @Hash32 . unCommentRevisionHash
114+
instance From HistoryCommentRevisionHash Hash32 where
115+
from = from @Hash @Hash32 . unHistoryCommentRevisionHash

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

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
{-# OPTIONS_GHC -Wno-orphans #-}
2-
31
module Unison.Codebase.Editor.HandleInput.HistoryComment (handleHistoryComment) where
42

53
import Control.Monad.Reader
6-
import Crypto.Hash qualified as CH
7-
import Data.ByteArray qualified as BA
8-
import Data.ByteString.Builder qualified as Builder
9-
import Data.ByteString.Lazy.Char8 qualified as BL
104
import Data.Text qualified as Text
11-
import Data.Text.Encoding qualified as Text
125
import Data.Text.IO qualified as Text
13-
import Data.Time (UTCTime)
146
import Data.Time.Clock.POSIX qualified as Time
157
import Text.RawString.QQ (r)
168
import U.Codebase.Config qualified as Config
17-
import U.Codebase.HashTags (CausalHash, CommentHash (..), CommentRevisionHash (..))
189
import U.Codebase.Sqlite.Queries qualified as Q
1910
import Unison.Auth.CredentialManager qualified as CredMan
2011
import Unison.Auth.PersonalKey qualified as PK
@@ -25,14 +16,14 @@ import Unison.Cli.ProjectUtils qualified as ProjectUtils
2516
import Unison.Codebase.Branch qualified as Branch
2617
import Unison.Codebase.Editor.Input (BranchId2)
2718
import Unison.Codebase.Editor.Output (Output (..))
19+
import Unison.Codebase.HistoryComments.Hashing
20+
( hashHistoryComment,
21+
hashHistoryCommentRevision,
22+
)
2823
import Unison.Codebase.Path qualified as Path
2924
import Unison.CommandLine.BranchRelativePath (BranchRelativePath (..))
3025
import Unison.Core.Project (ProjectAndBranch (..))
31-
import Unison.Hash (Hash)
32-
import Unison.Hash qualified as Hash
33-
import Unison.Hashing.V2 (ContentAddressable (..))
3426
import Unison.HistoryComment (HistoryComment (..), HistoryCommentRevision (..))
35-
import Unison.KeyThumbprint (KeyThumbprint (..))
3627
import Unison.Prelude
3728
import UnliftIO qualified
3829
import UnliftIO.Directory (findExecutable)
@@ -87,28 +78,26 @@ handleHistoryComment mayThingToAnnotate mayMessage = do
8778
Just (subject, content) -> do
8879
createdAt <- liftIO $ Time.getCurrentTime
8980
let historyComment =
90-
HistoryComment
91-
{ author =
92-
Config.unAuthorName authorName,
93-
commentId = (),
94-
causal = causalHash,
95-
createdAt,
96-
authorThumbprint
97-
}
98-
let commentHash = CommentHash $ contentHash historyComment
81+
hashHistoryComment $
82+
HistoryComment
83+
{ author =
84+
Config.unAuthorName authorName,
85+
commentId = (),
86+
causal = causalHash,
87+
createdAt,
88+
authorThumbprint
89+
}
9990
let historyCommentRevision =
100-
HistoryCommentRevision
101-
{ revisionId = (),
102-
subject,
103-
content,
104-
createdAt,
105-
comment = commentHash
106-
}
107-
let commentRevisionHash = CommentRevisionHash $ contentHash historyComment
108-
let hashedComment =
109-
historyCommentRevision {revisionId = commentRevisionHash, comment = historyComment {commentId = commentHash, causal = causalHashId}}
110-
111-
Cli.runTransaction $ Q.commentOnCausal hashedComment
91+
hashHistoryCommentRevision $
92+
HistoryCommentRevision
93+
{ revisionId = (),
94+
subject,
95+
content,
96+
createdAt,
97+
comment = historyComment.commentId
98+
}
99+
let historyComment' = historyComment {causal = causalHashId}
100+
Cli.runTransaction $ Q.commentOnCausal $ historyCommentRevision {comment = historyComment'}
112101
Cli.respond $ CommentedSuccessfully
113102
Nothing -> Cli.respond $ CommentAborted
114103
where

‎unison-cli/src/Unison/Codebase/HistoryComments/Hashing.hs‎

Lines changed: 25 additions & 8 deletions

0 commit comments

Comments
 (0)