summaryrefslogtreecommitdiff
path: root/GitUnionMerge.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-23 11:37:26 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-23 11:37:26 -0400
commit5f494154a34bad7cc54915a2a408b830e8ca77be (patch)
tree2adfc75ea36e18b3655bb2dcfa94b702288fc6c5 /GitUnionMerge.hs
parent23e765b67c38a9f02b3b5152e7e123819bb696de (diff)
add journaling to speed up changes to the git-annex branch
git is slow when the index file is large and has to be rewritten each time a file is changed. To speed this up, added a journal where changes are recorded before being fed into the index file and committed to the git-annex branch. The entire journal can be fed into git with just 2 commands, and only one write of the index file.
Diffstat (limited to 'GitUnionMerge.hs')
-rw-r--r--GitUnionMerge.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/GitUnionMerge.hs b/GitUnionMerge.hs
index 096a153a4..fa14a6bc3 100644
--- a/GitUnionMerge.hs
+++ b/GitUnionMerge.hs
@@ -7,7 +7,9 @@
module GitUnionMerge (
merge,
- commit
+ commit,
+ update_index,
+ update_index_line
) where
import System.Cmd.Utils
@@ -43,6 +45,11 @@ update_index g l = togit ["update-index", "-z", "--index-info"] (join "\0" l)
togit ps content = Git.pipeWrite g (map Param ps) content
>>= forceSuccess
+{- Generates a line suitable to be fed into update-index, to add
+ - a given file with a given sha. -}
+update_index_line :: String -> FilePath -> String
+update_index_line sha file = "100644 blob " ++ sha ++ "\t" ++ file
+
{- Gets the contents of a tree in a format suitable for update_index. -}
ls_tree :: Git.Repo -> String -> IO [String]
ls_tree g x = Git.pipeNullSplit g $
@@ -76,14 +83,13 @@ calc_merge g differ = do
mergeFile :: Git.Repo -> (String, FilePath) -> IO (Maybe String)
mergeFile g (info, file) = case filter (/= nullsha) [asha, bsha] of
[] -> return Nothing
- (sha:[]) -> return $ Just $ ls_tree_line sha
+ (sha:[]) -> return $ Just $ update_index_line sha file
shas -> do
content <- Git.pipeRead g $ map Param ("show":shas)
sha <- Git.hashObject g $ unionmerge content
- return $ Just $ ls_tree_line sha
+ return $ Just $ update_index_line sha file
where
[_colonamode, _bmode, asha, bsha, _status] = words info
- ls_tree_line sha = "100644 blob " ++ sha ++ "\t" ++ file
nullsha = take Git.shaSize $ repeat '0'
unionmerge = unlines . nub . lines