aboutsummaryrefslogtreecommitdiff
path: root/Git/UnionMerge.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-12 00:48:25 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-12 00:48:25 -0400
commit0cbab5de657e025057dd10b087a874d6b3a7b13e (patch)
tree3f5f6a88c065650ca9daa8663e206bd464b53d6e /Git/UnionMerge.hs
parentb9ac5854549636493449fea6830364a01159fbf6 (diff)
refactor
Diffstat (limited to 'Git/UnionMerge.hs')
-rw-r--r--Git/UnionMerge.hs20
1 files changed, 12 insertions, 8 deletions
diff --git a/Git/UnionMerge.hs b/Git/UnionMerge.hs
index 27113c85a..89fcf83e0 100644
--- a/Git/UnionMerge.hs
+++ b/Git/UnionMerge.hs
@@ -105,20 +105,24 @@ mergeFile info file h repo = case filter (/= nullsha) [Ref asha, Ref bsha] of
[] -> return Nothing
(sha:[]) -> return $ Just $ update_index_line sha file
(sha:shas) -> do
- origcontent <- L.lines <$> catObject h sha
- content <- map L.lines <$> mapM (catObject h) shas
- let newcontent = nub $ concat $ origcontent:content
- newsha <- if (newcontent == origcontent)
- then return sha
- else hashObject (L.unlines $ newcontent) repo
+ newsha <- maybe (return sha) (hashObject repo . L.unlines) =<<
+ unionmerge
+ <$> (L.lines <$> catObject h sha)
+ <*> (map L.lines <$> mapM (catObject h) shas)
return $ Just $ update_index_line newsha file
where
[_colonmode, _bmode, asha, bsha, _status] = words info
nullsha = Ref $ replicate shaSize '0'
+ unionmerge origcontent content
+ | newcontent == origcontent = Nothing
+ | otherwise = Just newcontent
+ where
+ newcontent = nub $ concat $ origcontent:content
+
{- Injects some content into git, returning its Sha. -}
-hashObject :: L.ByteString -> Repo -> IO Sha
-hashObject content repo = getSha subcmd $ do
+hashObject :: Repo -> L.ByteString -> IO Sha
+hashObject repo content = getSha subcmd $ do
(h, s) <- pipeWriteRead (map Param params) content repo
L.length s `seq` do
forceSuccess h