Sped up git-annex merge by using git hash-object --batch.

This does mean that it has to write out temp files containing updated
objects for the merge. So may use more disk space, and disk IO, but that
should generally win out over needing to launch N separate
git hash-object processes.
This commit is contained in:
Joey Hess 2016-03-14 16:23:22 -04:00
parent a27faf6999
commit 2d234de781
Failed to extract signature
3 changed files with 24 additions and 18 deletions

View file

@ -50,6 +50,7 @@ import Git.Types
import Git.FilePath import Git.FilePath
import Annex.CatFile import Annex.CatFile
import Annex.Perms import Annex.Perms
import Annex.HashObject (hashObjectHandle)
import Logs import Logs
import Logs.Transitions import Logs.Transitions
import Logs.Trust.Pure import Logs.Trust.Pure
@ -342,8 +343,9 @@ genIndex g = Git.UpdateIndex.streamUpdateIndex g
mergeIndex :: JournalLocked -> [Git.Ref] -> Annex () mergeIndex :: JournalLocked -> [Git.Ref] -> Annex ()
mergeIndex jl branches = do mergeIndex jl branches = do
prepareModifyIndex jl prepareModifyIndex jl
h <- catFileHandle hashhandle <- hashObjectHandle
inRepo $ \g -> Git.UnionMerge.mergeIndex h g branches ch <- catFileHandle
inRepo $ \g -> Git.UnionMerge.mergeIndex hashhandle ch g branches
{- Removes any stale git lock file, to avoid git falling over when {- Removes any stale git lock file, to avoid git falling over when
- updating the index. - updating the index.

View file

@ -30,12 +30,14 @@ import Git.FilePath
-} -}
merge :: Ref -> Ref -> Repo -> IO () merge :: Ref -> Ref -> Repo -> IO ()
merge x y repo = do merge x y repo = do
h <- catFileStart repo hashhandle <- hashObjectStart repo
ch <- catFileStart repo
streamUpdateIndex repo streamUpdateIndex repo
[ lsTree x repo [ lsTree x repo
, mergeTrees x y h repo , mergeTrees x y hashhandle ch repo
] ]
catFileStop h catFileStop ch
hashObjectStop hashhandle
{- Merges a list of branches into the index. Previously staged changes in {- Merges a list of branches into the index. Previously staged changes in
- the index are preserved (and participate in the merge). - the index are preserved (and participate in the merge).
@ -45,17 +47,18 @@ merge x y repo = do
- harder to calculate a single union merge involving all the refs, as well - harder to calculate a single union merge involving all the refs, as well
- as the index. - as the index.
-} -}
mergeIndex :: CatFileHandle -> Repo -> [Ref] -> IO () mergeIndex :: HashObjectHandle -> CatFileHandle -> Repo -> [Ref] -> IO ()
mergeIndex h repo bs = forM_ bs $ \b -> mergeIndex hashhandle ch repo bs = forM_ bs $ \b ->
streamUpdateIndex repo [mergeTreeIndex b h repo] streamUpdateIndex repo [mergeTreeIndex b hashhandle ch repo]
{- For merging two trees. -} {- For merging two trees. -}
mergeTrees :: Ref -> Ref -> CatFileHandle -> Repo -> Streamer mergeTrees :: Ref -> Ref -> HashObjectHandle -> CatFileHandle -> Repo -> Streamer
mergeTrees (Ref x) (Ref y) h = doMerge h $ "diff-tree":diffOpts ++ [x, y, "--"] mergeTrees (Ref x) (Ref y) hashhandle ch = doMerge hashhandle ch
("diff-tree":diffOpts ++ [x, y, "--"])
{- For merging a single tree into the index. -} {- For merging a single tree into the index. -}
mergeTreeIndex :: Ref -> CatFileHandle -> Repo -> Streamer mergeTreeIndex :: Ref -> HashObjectHandle -> CatFileHandle -> Repo -> Streamer
mergeTreeIndex (Ref r) h = doMerge h $ mergeTreeIndex (Ref r) hashhandle ch = doMerge hashhandle ch $
"diff-index" : diffOpts ++ ["--cached", r, "--"] "diff-index" : diffOpts ++ ["--cached", r, "--"]
diffOpts :: [String] diffOpts :: [String]
@ -63,26 +66,26 @@ diffOpts = ["--raw", "-z", "-r", "--no-renames", "-l0"]
{- Streams update-index changes to perform a merge, {- Streams update-index changes to perform a merge,
- using git to get a raw diff. -} - using git to get a raw diff. -}
doMerge :: CatFileHandle -> [String] -> Repo -> Streamer doMerge :: HashObjectHandle -> CatFileHandle -> [String] -> Repo -> Streamer
doMerge ch differ repo streamer = do doMerge hashhandle ch differ repo streamer = do
(diff, cleanup) <- pipeNullSplit (map Param differ) repo (diff, cleanup) <- pipeNullSplit (map Param differ) repo
go diff go diff
void $ cleanup void $ cleanup
where where
go [] = noop go [] = noop
go (info:file:rest) = mergeFile info file ch repo >>= go (info:file:rest) = mergeFile info file hashhandle ch >>=
maybe (go rest) (\l -> streamer l >> go rest) maybe (go rest) (\l -> streamer l >> go rest)
go (_:[]) = error $ "parse error " ++ show differ go (_:[]) = error $ "parse error " ++ show differ
{- Given an info line from a git raw diff, and the filename, generates {- 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 - a line suitable for update-index that union merges the two sides of the
- diff. -} - diff. -}
mergeFile :: String -> FilePath -> CatFileHandle -> Repo -> IO (Maybe String) mergeFile :: String -> FilePath -> HashObjectHandle -> CatFileHandle -> IO (Maybe String)
mergeFile info file h repo = case filter (/= nullSha) [Ref asha, Ref bsha] of mergeFile info file hashhandle h = case filter (/= nullSha) [Ref asha, Ref bsha] of
[] -> return Nothing [] -> return Nothing
(sha:[]) -> use sha (sha:[]) -> use sha
shas -> use shas -> use
=<< either return (\s -> hashObject BlobObject (unlines s) repo) =<< either return (\s -> hashBlob hashhandle (unlines s))
=<< calcMerge . zip shas <$> mapM getcontents shas =<< calcMerge . zip shas <$> mapM getcontents shas
where where
[_colonmode, _bmode, asha, bsha, _status] = words info [_colonmode, _bmode, asha, bsha, _status] = words info

1
debian/changelog vendored
View file

@ -15,6 +15,7 @@ git-annex (6.20160230) UNRELEASED; urgency=medium
* Correct git-annex info to include unlocked files in v6 repository. * Correct git-annex info to include unlocked files in v6 repository.
* Sped up git-annex add in direct mode and v6 by using * Sped up git-annex add in direct mode and v6 by using
git hash-object --batch. git hash-object --batch.
* Sped up git-annex merge by using git hash-object --batch.
-- Joey Hess <id@joeyh.name> Mon, 29 Feb 2016 13:00:30 -0400 -- Joey Hess <id@joeyh.name> Mon, 29 Feb 2016 13:00:30 -0400