From 0cbab5de657e025057dd10b087a874d6b3a7b13e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Dec 2011 00:48:25 -0400 Subject: refactor --- Git/UnionMerge.hs | 20 ++++++++++++-------- 1 file 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 -- cgit v1.2.3