module Data.Git.Types
(
ObjectType(..)
, Tree(..)
, Commit(..)
, CommitExtra(..)
, Blob(..)
, Tag(..)
, Person(..)
, GitTime(..)
, toUTCTime
, toPOSIXTime
, DeltaOfs(..)
, DeltaRef(..)
, TreeEnt
) where
import Data.Word
import Data.Monoid
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as L
import Data.Git.Ref
import Data.Git.Delta
import Data.Time.Clock
import Data.Time.Clock.POSIX
data ObjectType =
TypeTree
| TypeBlob
| TypeCommit
| TypeTag
| TypeDeltaOff
| TypeDeltaRef
deriving (Show,Eq)
data GitTime = GitTime Integer Int
deriving (Show,Eq)
toUTCTime :: GitTime -> UTCTime
toUTCTime (GitTime seconds _) = posixSecondsToUTCTime $ fromIntegral seconds
toPOSIXTime :: GitTime -> POSIXTime
toPOSIXTime = utcTimeToPOSIXSeconds . toUTCTime
instance Enum ObjectType where
fromEnum TypeCommit = 0x1
fromEnum TypeTree = 0x2
fromEnum TypeBlob = 0x3
fromEnum TypeTag = 0x4
fromEnum TypeDeltaOff = 0x6
fromEnum TypeDeltaRef = 0x7
toEnum 0x1 = TypeCommit
toEnum 0x2 = TypeTree
toEnum 0x3 = TypeBlob
toEnum 0x4 = TypeTag
toEnum 0x6 = TypeDeltaOff
toEnum 0x7 = TypeDeltaRef
toEnum n = error ("not a valid object: " ++ show n)
type TreeEnt = (Int,ByteString,Ref)
data Person = Person
{ personName :: ByteString
, personEmail :: ByteString
, personTime :: GitTime
} deriving (Show,Eq)
data Tree = Tree { treeGetEnts :: [TreeEnt] } deriving (Show,Eq)
instance Monoid Tree where
mempty = Tree []
mappend (Tree e1) (Tree e2) = Tree (e1 ++ e2)
mconcat trees = Tree $ concatMap treeGetEnts trees
data Blob = Blob { blobGetContent :: L.ByteString } deriving (Show,Eq)
data Commit = Commit
{ commitTreeish :: Ref
, commitParents :: [Ref]
, commitAuthor :: Person
, commitCommitter :: Person
, commitEncoding :: Maybe ByteString
, commitExtras :: [CommitExtra]
, commitMessage :: ByteString
} deriving (Show,Eq)
data CommitExtra = CommitExtra
{ commitExtraKey :: ByteString
, commitExtraValue :: ByteString
} deriving (Show,Eq)
data Tag = Tag
{ tagRef :: Ref
, tagObjectType :: ObjectType
, tagBlob :: ByteString
, tagName :: Person
, tagS :: ByteString
} deriving (Show,Eq)
data DeltaOfs = DeltaOfs Word64 Delta
deriving (Show,Eq)
data DeltaRef = DeltaRef Ref Delta
deriving (Show,Eq)