summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-03-11 12:47:14 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-03-11 12:47:14 -0400
commit30a5b59abe5c54cc0afbe27f8da3ba8be55b3847 (patch)
treee9778046dd485eb8dd27fae3e9fde754f07dadd8 /Git
parentb15ce31aa84ac2ae3d78e82868fb6065f15c99a4 (diff)
extract commit parent(s)
Diffstat (limited to 'Git')
-rw-r--r--Git/CatFile.hs8
-rw-r--r--Git/Types.hs1
2 files changed, 6 insertions, 3 deletions
diff --git a/Git/CatFile.hs b/Git/CatFile.hs
index 455f192a0..d6f7707bc 100644
--- a/Git/CatFile.hs
+++ b/Git/CatFile.hs
@@ -125,15 +125,17 @@ catCommit h commitref = go <$> catObjectDetails h commitref
parseCommit :: L.ByteString -> Maybe Commit
parseCommit b = Commit
<$> (extractSha . L8.unpack =<< field "tree")
+ <*> (mapMaybe (extractSha . L8.unpack) <$> fields "parent")
<*> (parsemetadata <$> field "author")
<*> (parsemetadata <$> field "committer")
<*> Just (L8.unpack $ L.intercalate (L.singleton nl) message)
where
- field n = M.lookup (fromString n) fields
- fields = M.fromList ((map breakfield) header)
+ field n = headMaybe =<< fields n
+ fields n = M.lookup (fromString n) fieldmap
+ fieldmap = M.fromListWith (++) ((map breakfield) header)
breakfield l =
let (k, sp_v) = L.break (== sp) l
- in (k, L.drop 1 sp_v)
+ in (k, [L.drop 1 sp_v])
(header, message) = separate L.null ls
ls = L.split nl b
diff --git a/Git/Types.hs b/Git/Types.hs
index 4fa49be5c..44135738d 100644
--- a/Git/Types.hs
+++ b/Git/Types.hs
@@ -105,6 +105,7 @@ fromBlobType SymlinkBlob = 0o120000
data Commit = Commit
{ commitTree :: Sha
+ , commitParent :: [Sha]
, commitAuthorMetaData :: CommitMetaData
, commitCommitterMetaData :: CommitMetaData
, commitMessage :: String