5f494154a3
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.
49 lines
1.1 KiB
Haskell
49 lines
1.1 KiB
Haskell
{- git-union-merge program
|
|
-
|
|
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
|
-
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
-}
|
|
|
|
import System.Environment
|
|
import System.FilePath
|
|
import System.Directory
|
|
import Control.Monad (when)
|
|
|
|
import qualified GitUnionMerge
|
|
import qualified GitRepo as Git
|
|
|
|
header :: String
|
|
header = "Usage: git-union-merge ref ref newref"
|
|
|
|
usage :: IO a
|
|
usage = error $ "bad parameters\n\n" ++ header
|
|
|
|
tmpIndex :: Git.Repo -> FilePath
|
|
tmpIndex g = Git.workTree g </> Git.gitDir g </> "index.git-union-merge"
|
|
|
|
setup :: Git.Repo -> IO ()
|
|
setup g = do
|
|
cleanup g -- idempotency
|
|
|
|
cleanup :: Git.Repo -> IO ()
|
|
cleanup g = do
|
|
e' <- doesFileExist (tmpIndex g)
|
|
when e' $ removeFile (tmpIndex g)
|
|
|
|
parseArgs :: IO [String]
|
|
parseArgs = do
|
|
args <- getArgs
|
|
if (length args /= 3)
|
|
then usage
|
|
else return args
|
|
|
|
main :: IO ()
|
|
main = do
|
|
[aref, bref, newref] <- parseArgs
|
|
g <- Git.configRead =<< Git.repoFromCwd
|
|
_ <- Git.useIndex (tmpIndex g)
|
|
setup g
|
|
GitUnionMerge.merge g [aref, bref]
|
|
GitUnionMerge.commit g "union merge" newref [aref, bref]
|
|
cleanup g
|