refactor and function name cleanup

(oops, I had a calcMerge and a calc_merge!)
This commit is contained in:
Joey Hess 2012-06-08 00:29:39 -04:00
parent 7d78cbf97c
commit d45a9a7831
5 changed files with 58 additions and 46 deletions

View file

@ -7,7 +7,7 @@
module Git.UnionMerge (
merge,
merge_index
mergeIndex
) where
import qualified Data.Text.Lazy as L
@ -32,40 +32,40 @@ import Git.FilePath
merge :: Ref -> Ref -> Repo -> IO ()
merge x y repo = do
h <- catFileStart repo
stream_update_index repo
[ ls_tree x repo
, merge_trees x y h repo
streamUpdateIndex repo
[ lsTree x repo
, mergeTrees x y h repo
]
catFileStop h
{- Merges a list of branches into the index. Previously staged changed in
{- Merges a list of branches into the index. Previously staged changes in
- the index are preserved (and participate in the merge). -}
merge_index :: CatFileHandle -> Repo -> [Ref] -> IO ()
merge_index h repo bs =
stream_update_index repo $ map (\b -> merge_tree_index b h repo) bs
mergeIndex :: CatFileHandle -> Repo -> [Ref] -> IO ()
mergeIndex h repo bs =
streamUpdateIndex repo $ map (\b -> mergeTreeIndex b h repo) bs
{- For merging two trees. -}
merge_trees :: Ref -> Ref -> CatFileHandle -> Repo -> Streamer
merge_trees (Ref x) (Ref y) h = calc_merge h $ "diff-tree":diff_opts ++ [x, y]
mergeTrees :: Ref -> Ref -> CatFileHandle -> Repo -> Streamer
mergeTrees (Ref x) (Ref y) h = doMerge h $ "diff-tree":diffOpts ++ [x, y]
{- For merging a single tree into the index. -}
merge_tree_index :: Ref -> CatFileHandle -> Repo -> Streamer
merge_tree_index (Ref x) h = calc_merge h $
"diff-index" : diff_opts ++ ["--cached", x]
mergeTreeIndex :: Ref -> CatFileHandle -> Repo -> Streamer
mergeTreeIndex (Ref x) h = doMerge h $
"diff-index" : diffOpts ++ ["--cached", x]
diff_opts :: [String]
diff_opts = ["--raw", "-z", "-r", "--no-renames", "-l0"]
diffOpts :: [String]
diffOpts = ["--raw", "-z", "-r", "--no-renames", "-l0"]
{- Calculates how to perform a merge, using git to get a raw diff,
- and generating update-index input. -}
calc_merge :: CatFileHandle -> [String] -> Repo -> Streamer
calc_merge ch differ repo streamer = gendiff >>= go
{- Streams update-index changes to perform a merge,
- using git to get a raw diff. -}
doMerge :: CatFileHandle -> [String] -> Repo -> Streamer
doMerge ch differ repo streamer = gendiff >>= go
where
gendiff = pipeNullSplit (map Param differ) repo
go [] = noop
go (info:file:rest) = mergeFile info file ch repo >>=
maybe (go rest) (\l -> streamer l >> go rest)
go (_:[]) = error "calc_merge parse error"
go (_:[]) = error $ "parse error " ++ show differ
{- Given an info line from a git raw diff, and the filename, generates
- a line suitable for update-index that union merges the two sides of the
@ -81,7 +81,8 @@ mergeFile info file h repo = case filter (/= nullSha) [Ref asha, Ref bsha] of
[_colonmode, _bmode, asha, bsha, _status] = words info
getcontents s = map L.unpack . L.lines .
L.decodeUtf8 <$> catObject h s
use sha = return $ Just $ update_index_line sha FileBlob $ asTopFilePath file
use sha = return $ Just $
updateIndexLine sha FileBlob $ asTopFilePath file
{- Calculates a union merge between a list of refs, with contents.
-