From 907c7138cb07cb5b7f379ad9bbd64baabea57766 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez <vincent@typed.io> Date: Fri, 24 Aug 2018 20:29:23 +0100 Subject: [PATCH] improve types (more strictness, newtype instead of data) --- Data/Git/Types.hs | 40 ++++++++++++++++++++-------------------- git.cabal | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Data/Git/Types.hs b/Data/Git/Types.hs index c9da664..db0b94f 100644 --- a/Data/Git/Types.hs +++ b/Data/Git/Types.hs @@ -69,8 +69,8 @@ data ObjectType = -- | Git time is number of seconds since unix epoch in the UTC zone with -- the current timezone associated data GitTime = GitTime - { gitTimeUTC :: Elapsed - , gitTimeTimezone :: TimezoneOffset + { gitTimeUTC :: !Elapsed + , gitTimeTimezone :: !TimezoneOffset } deriving (Eq) instance Timeable GitTime where @@ -177,46 +177,46 @@ type TreeEnt hash = (ModePerm,EntName,Ref hash) -- FIXME: should be a string, but I don't know if the data is stored -- consistantly in one encoding (UTF8) data Person = Person - { personName :: ByteString - , personEmail :: ByteString - , personTime :: GitTime + { personName :: !ByteString + , personEmail :: !ByteString + , personTime :: !GitTime } deriving (Show,Eq) -- | Represent a root tree with zero to many tree entries. -data Tree hash = Tree { treeGetEnts :: [TreeEnt hash] } deriving (Show,Eq) +newtype Tree hash = Tree { treeGetEnts :: [TreeEnt hash] } deriving (Show,Eq) -- | Represent a binary blob. -data Blob hash = Blob { blobGetContent :: L.ByteString } deriving (Show,Eq) +newtype Blob hash = Blob { blobGetContent :: L.ByteString } deriving (Show,Eq) -- | Represent a commit object. data Commit hash = Commit - { commitTreeish :: Ref hash + { commitTreeish :: !(Ref hash) , commitParents :: [Ref hash] - , commitAuthor :: Person - , commitCommitter :: Person + , commitAuthor :: !Person + , commitCommitter :: !Person , commitEncoding :: Maybe ByteString , commitExtras :: [CommitExtra] - , commitMessage :: ByteString + , commitMessage :: !ByteString } deriving (Show,Eq) data CommitExtra = CommitExtra - { commitExtraKey :: ByteString - , commitExtraValue :: ByteString + { commitExtraKey :: !ByteString + , commitExtraValue :: !ByteString } deriving (Show,Eq) -- | Represent a signed tag. data Tag hash = Tag - { tagRef :: Ref hash - , tagObjectType :: ObjectType - , tagBlob :: ByteString - , tagName :: Person - , tagS :: ByteString + { tagRef :: !(Ref hash) + , tagObjectType :: !ObjectType + , tagBlob :: !ByteString + , tagName :: !Person + , tagS :: !ByteString } deriving (Show,Eq) -- | Delta pointing to an offset. -data DeltaOfs hash = DeltaOfs Word64 Delta +data DeltaOfs hash = DeltaOfs !Word64 !Delta deriving (Show,Eq) -- | Delta pointing to a ref. -data DeltaRef hash = DeltaRef (Ref hash) Delta +data DeltaRef hash = DeltaRef !(Ref hash) !Delta deriving (Show,Eq) diff --git a/git.cabal b/git.cabal index 355dd20..f71f08c 100644 --- a/git.cabal +++ b/git.cabal @@ -27,6 +27,7 @@ extra-source-files: tests/*.hs Library Build-Depends: base >= 4 && < 5 + , basement , bytestring >= 0.9 , byteable , containers -- GitLab