{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
module Data.Git.Types
( Date
, utcTimeToDate
, Mode(..)
, pattern BlobMode, pattern ExecMode, pattern TreeMode, pattern LinkMode, pattern SubmMode
, Contact(..)
, makeContact
, makeContact'
, GitT()
, Git()
)
where
import qualified Data.ByteString as B
import Data.Git.Formats
import Data.Git.Internal.Types
import Data.Time
import Data.Time.Clock.POSIX
import Data.Word
type Date = (Int, B.ByteString)
utcTimeToDate :: UTCTime -> Date
utcTimeToDate t = (truncate $ utcTimeToPOSIXSeconds t, "+0000")
data Contact = Contact { contactName, contactEmail :: SafeString }
deriving (Eq, Ord, Show)
makeContact' :: B.ByteString -> B.ByteString -> Maybe Contact
makeContact' name email = Contact <$> safeString name <*> safeString email
makeContact :: B.ByteString -> B.ByteString -> Contact
makeContact name email = maybe (error "illegal contact string") id $ makeContact' name email
newtype Mode = BareMode Word32
deriving (Eq, Ord, Show)
pattern BlobMode :: Mode
pattern ExecMode :: Mode
pattern TreeMode :: Mode
pattern SubmMode :: Mode
pattern LinkMode :: Mode
pattern BlobMode = BareMode 0o100644
pattern ExecMode = BareMode 0o100755
pattern TreeMode = BareMode 0o040000
pattern SubmMode = BareMode 0o160000
pattern LinkMode = BareMode 0o120000
type Git a = GitT IO a