Commits

Stefan Saasen committed 352f24e

Use Identity data type with Author|Commiter value constructors instead of separate data types

  • Participants
  • Parent commits f93d60e

Comments (0)

Files changed (1)

src/Git/Store/Object.hs

 module Git.Store.Object (
     parseTree
   , parseCommit
-  , parsePerson     -- Remove?
   , parseObject
   , toCommit
   , Commit(..)
   , sha             :: ObjectId
 } deriving (Eq, Show)
 
-data Author = Author B.ByteString B.ByteString deriving (Eq, Show)
-data Commiter = Commiter B.ByteString B.ByteString deriving (Eq, Show)
+data Identity = Author B.ByteString B.ByteString
+              | Commiter B.ByteString B.ByteString deriving (Eq, Show)
 
 data Tree = Tree {
     getObjectId :: ObjectId
     getTree        :: B.ByteString
   , getParents     :: [B.ByteString]
   , getSha         :: B.ByteString
-  , getAuthor      :: Author
-  , getCommiter    :: Commiter
+  , getAuthor      :: Identity
+  , getCommiter    :: Identity
   , getMessage     :: B.ByteString
 } deriving (Eq,Show)
 
          obj "tree"     = BTree
          obj "tag"      = BTag
          obj "blob"     = BBlob
-         obj _          = error "Invalid object type" -- FIXME Let the parser fail
+         obj _          = error "Invalid object type" -- The parser wouldn't get here anyway
 
 
 parseTree :: ObjectId -> C.ByteString -> Maybe Tree
     parents <- many' parseParentCommit
     author <- "author " .*> parsePerson
     space
-    _commiter <- "committer " .*> parsePerson
+    commiter <- "committer " .*> parsePerson
     space
     space
     message <- takeByteString
-    return $ Commit tree parents B.empty (Author (getPersonName author) (getPersonEmail author)) (Commiter "" "") message -- FIXME Use Commiter
+    let author'   = Author (getPersonName author) (getPersonEmail author)
+        commiter' = Commiter (getPersonName commiter) (getPersonEmail commiter)
+    return $ Commit tree parents B.empty author' commiter' message
 
 parseParentCommit :: Parser C.ByteString
 parseParentCommit = do