rename GitUnionMerge to Git.UnionMerge
Also, moved commit function into Git proper, it's not union merge specific.
This commit is contained in:
parent
f0497312a7
commit
896726cde4
4 changed files with 40 additions and 42 deletions
18
Branch.hs
18
Branch.hs
|
@ -31,7 +31,7 @@ import qualified Data.ByteString.Char8 as B
|
||||||
|
|
||||||
import Types.BranchState
|
import Types.BranchState
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import qualified GitUnionMerge
|
import qualified Git.UnionMerge
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Utility
|
import Utility
|
||||||
import Types
|
import Types
|
||||||
|
@ -72,7 +72,7 @@ index g = gitAnnexDir g </> "index"
|
||||||
- and merge in changes from other branches.
|
- and merge in changes from other branches.
|
||||||
-}
|
-}
|
||||||
genIndex :: Git.Repo -> IO ()
|
genIndex :: Git.Repo -> IO ()
|
||||||
genIndex g = GitUnionMerge.ls_tree g fullname >>= GitUnionMerge.update_index g
|
genIndex g = Git.UnionMerge.ls_tree g fullname >>= Git.UnionMerge.update_index g
|
||||||
|
|
||||||
{- Runs an action using the branch's index file. -}
|
{- Runs an action using the branch's index file. -}
|
||||||
withIndex :: Annex a -> Annex a
|
withIndex :: Annex a -> Annex a
|
||||||
|
@ -128,14 +128,13 @@ create = unlessM (refExists fullname) $ do
|
||||||
if e
|
if e
|
||||||
then liftIO $ Git.run g "branch" [Param name, Param originname]
|
then liftIO $ Git.run g "branch" [Param name, Param originname]
|
||||||
else withIndex' True $
|
else withIndex' True $
|
||||||
liftIO $ GitUnionMerge.commit g "branch created" fullname []
|
liftIO $ Git.commit g "branch created" fullname []
|
||||||
|
|
||||||
{- Stages the journal, and commits staged changes to the branch. -}
|
{- Stages the journal, and commits staged changes to the branch. -}
|
||||||
commit :: String -> Annex ()
|
commit :: String -> Annex ()
|
||||||
commit message = whenM stageJournalFiles $ do
|
commit message = whenM stageJournalFiles $ do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
withIndex $ liftIO $
|
withIndex $ liftIO $ Git.commit g message fullname [fullname]
|
||||||
GitUnionMerge.commit g message fullname [fullname]
|
|
||||||
|
|
||||||
{- Ensures that the branch is up-to-date; should be called before
|
{- Ensures that the branch is up-to-date; should be called before
|
||||||
- data is read from it. Runs only once per git-annex run. -}
|
- data is read from it. Runs only once per git-annex run. -}
|
||||||
|
@ -158,8 +157,7 @@ update = do
|
||||||
let refs = map (last . words) (lines r)
|
let refs = map (last . words) (lines r)
|
||||||
updated <- catMaybes `liftM` mapM updateRef refs
|
updated <- catMaybes `liftM` mapM updateRef refs
|
||||||
unless (null updated && not staged) $ liftIO $
|
unless (null updated && not staged) $ liftIO $
|
||||||
GitUnionMerge.commit g "update" fullname
|
Git.commit g "update" fullname (fullname:updated)
|
||||||
(fullname:updated)
|
|
||||||
Annex.changeState $ \s -> s { Annex.branchstate = state { branchUpdated = True } }
|
Annex.changeState $ \s -> s { Annex.branchstate = state { branchUpdated = True } }
|
||||||
invalidateCache
|
invalidateCache
|
||||||
|
|
||||||
|
@ -200,7 +198,7 @@ updateRef ref
|
||||||
-- index will be removed. So, documentation
|
-- index will be removed. So, documentation
|
||||||
-- advises users not to directly modify the
|
-- advises users not to directly modify the
|
||||||
-- branch.
|
-- branch.
|
||||||
liftIO $ GitUnionMerge.merge g [ref]
|
liftIO $ Git.UnionMerge.merge g [ref]
|
||||||
return $ Just ref
|
return $ Just ref
|
||||||
|
|
||||||
{- Records changed content of a file into the journal. -}
|
{- Records changed content of a file into the journal. -}
|
||||||
|
@ -335,12 +333,12 @@ stageJournalFiles = do
|
||||||
(h, s) <- Git.pipeWriteRead g [Param "hash-object",
|
(h, s) <- Git.pipeWriteRead g [Param "hash-object",
|
||||||
Param "-w", Param "--stdin-paths"] $ unlines paths
|
Param "-w", Param "--stdin-paths"] $ unlines paths
|
||||||
-- update the index, also in just one command
|
-- update the index, also in just one command
|
||||||
GitUnionMerge.update_index g $
|
Git.UnionMerge.update_index g $
|
||||||
index_lines (lines s) $ map fileJournal fs
|
index_lines (lines s) $ map fileJournal fs
|
||||||
forceSuccess h
|
forceSuccess h
|
||||||
mapM_ removeFile paths
|
mapM_ removeFile paths
|
||||||
index_lines shas fs = map genline $ zip shas fs
|
index_lines shas fs = map genline $ zip shas fs
|
||||||
genline (sha, file) = GitUnionMerge.update_index_line sha file
|
genline (sha, file) = Git.UnionMerge.update_index_line sha file
|
||||||
|
|
||||||
{- Produces a filename to use in the journal for a file on the branch.
|
{- Produces a filename to use in the journal for a file on the branch.
|
||||||
-
|
-
|
||||||
|
|
14
Git.hs
14
Git.hs
|
@ -56,6 +56,7 @@ module Git (
|
||||||
hashObject,
|
hashObject,
|
||||||
getSha,
|
getSha,
|
||||||
shaSize,
|
shaSize,
|
||||||
|
commit,
|
||||||
|
|
||||||
prop_idempotent_deencode
|
prop_idempotent_deencode
|
||||||
) where
|
) where
|
||||||
|
@ -425,6 +426,19 @@ getSha subcommand a = do
|
||||||
shaSize :: Int
|
shaSize :: Int
|
||||||
shaSize = 40
|
shaSize = 40
|
||||||
|
|
||||||
|
{- Commits the index into the specified branch,
|
||||||
|
- with the specified parent refs. -}
|
||||||
|
commit :: Repo -> String -> String -> [String] -> IO ()
|
||||||
|
commit g message newref parentrefs = do
|
||||||
|
tree <- getSha "write-tree" $
|
||||||
|
pipeRead g [Param "write-tree"]
|
||||||
|
sha <- getSha "commit-tree" $ ignorehandle $
|
||||||
|
pipeWriteRead g (map Param $ ["commit-tree", tree] ++ ps) message
|
||||||
|
run g "update-ref" [Param newref, Param sha]
|
||||||
|
where
|
||||||
|
ignorehandle a = return . snd =<< a
|
||||||
|
ps = concatMap (\r -> ["-p", r]) parentrefs
|
||||||
|
|
||||||
{- Reads null terminated output of a git command (as enabled by the -z
|
{- Reads null terminated output of a git command (as enabled by the -z
|
||||||
- parameter), and splits it into a list of files/lines/whatever. -}
|
- parameter), and splits it into a list of files/lines/whatever. -}
|
||||||
pipeNullSplit :: Repo -> [CommandParam] -> IO [FilePath]
|
pipeNullSplit :: Repo -> [CommandParam] -> IO [FilePath]
|
||||||
|
|
|
@ -5,9 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module GitUnionMerge (
|
module Git.UnionMerge (
|
||||||
merge,
|
merge,
|
||||||
commit,
|
|
||||||
update_index,
|
update_index,
|
||||||
update_index_line,
|
update_index_line,
|
||||||
ls_tree
|
ls_tree
|
||||||
|
@ -18,7 +17,7 @@ import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.String.Utils
|
import Data.String.Utils
|
||||||
|
|
||||||
import qualified Git
|
import Git
|
||||||
import Utility
|
import Utility
|
||||||
|
|
||||||
{- Performs a union merge between two branches, staging it in the index.
|
{- Performs a union merge between two branches, staging it in the index.
|
||||||
|
@ -29,7 +28,7 @@ import Utility
|
||||||
-
|
-
|
||||||
- Should be run with a temporary index file configured by Git.useIndex.
|
- Should be run with a temporary index file configured by Git.useIndex.
|
||||||
-}
|
-}
|
||||||
merge :: Git.Repo -> [String] -> IO ()
|
merge :: Repo -> [String] -> IO ()
|
||||||
merge g (x:y:[]) = do
|
merge g (x:y:[]) = do
|
||||||
a <- ls_tree g x
|
a <- ls_tree g x
|
||||||
b <- merge_trees g x y
|
b <- merge_trees g x y
|
||||||
|
@ -40,10 +39,10 @@ merge _ _ = error "wrong number of branches to merge"
|
||||||
{- Feeds a list into update-index. Later items in the list can override
|
{- Feeds a list into update-index. Later items in the list can override
|
||||||
- earlier ones, so the list can be generated from any combination of
|
- earlier ones, so the list can be generated from any combination of
|
||||||
- ls_tree, merge_trees, and merge_tree_index. -}
|
- ls_tree, merge_trees, and merge_tree_index. -}
|
||||||
update_index :: Git.Repo -> [String] -> IO ()
|
update_index :: Repo -> [String] -> IO ()
|
||||||
update_index g l = togit ["update-index", "-z", "--index-info"] (join "\0" l)
|
update_index g l = togit ["update-index", "-z", "--index-info"] (join "\0" l)
|
||||||
where
|
where
|
||||||
togit ps content = Git.pipeWrite g (map Param ps) content
|
togit ps content = pipeWrite g (map Param ps) content
|
||||||
>>= forceSuccess
|
>>= forceSuccess
|
||||||
|
|
||||||
{- Generates a line suitable to be fed into update-index, to add
|
{- Generates a line suitable to be fed into update-index, to add
|
||||||
|
@ -52,16 +51,16 @@ update_index_line :: String -> FilePath -> String
|
||||||
update_index_line sha file = "100644 blob " ++ sha ++ "\t" ++ file
|
update_index_line sha file = "100644 blob " ++ sha ++ "\t" ++ file
|
||||||
|
|
||||||
{- Gets the contents of a tree in a format suitable for update_index. -}
|
{- Gets the contents of a tree in a format suitable for update_index. -}
|
||||||
ls_tree :: Git.Repo -> String -> IO [String]
|
ls_tree :: Repo -> String -> IO [String]
|
||||||
ls_tree g x = Git.pipeNullSplit g $
|
ls_tree g x = pipeNullSplit g $
|
||||||
map Param ["ls-tree", "-z", "-r", "--full-tree", x]
|
map Param ["ls-tree", "-z", "-r", "--full-tree", x]
|
||||||
|
|
||||||
{- For merging two trees. -}
|
{- For merging two trees. -}
|
||||||
merge_trees :: Git.Repo -> String -> String -> IO [String]
|
merge_trees :: Repo -> String -> String -> IO [String]
|
||||||
merge_trees g x y = calc_merge g $ "diff-tree":diff_opts ++ [x, y]
|
merge_trees g x y = calc_merge g $ "diff-tree":diff_opts ++ [x, y]
|
||||||
|
|
||||||
{- For merging a single tree into the index. -}
|
{- For merging a single tree into the index. -}
|
||||||
merge_tree_index :: Git.Repo -> String -> IO [String]
|
merge_tree_index :: Repo -> String -> IO [String]
|
||||||
merge_tree_index g x = calc_merge g $ "diff-index":diff_opts ++ ["--cached", x]
|
merge_tree_index g x = calc_merge g $ "diff-index":diff_opts ++ ["--cached", x]
|
||||||
|
|
||||||
diff_opts :: [String]
|
diff_opts :: [String]
|
||||||
|
@ -69,9 +68,9 @@ diff_opts = ["--raw", "-z", "-r", "--no-renames", "-l0"]
|
||||||
|
|
||||||
{- Calculates how to perform a merge, using git to get a raw diff,
|
{- Calculates how to perform a merge, using git to get a raw diff,
|
||||||
- and returning a list suitable for update_index. -}
|
- and returning a list suitable for update_index. -}
|
||||||
calc_merge :: Git.Repo -> [String] -> IO [String]
|
calc_merge :: Repo -> [String] -> IO [String]
|
||||||
calc_merge g differ = do
|
calc_merge g differ = do
|
||||||
diff <- Git.pipeNullSplit g $ map Param differ
|
diff <- pipeNullSplit g $ map Param differ
|
||||||
l <- mapM (mergeFile g) (pairs diff)
|
l <- mapM (mergeFile g) (pairs diff)
|
||||||
return $ catMaybes l
|
return $ catMaybes l
|
||||||
where
|
where
|
||||||
|
@ -82,28 +81,15 @@ calc_merge g differ = do
|
||||||
{- 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 :: Git.Repo -> (String, FilePath) -> IO (Maybe String)
|
mergeFile :: Repo -> (String, FilePath) -> IO (Maybe String)
|
||||||
mergeFile g (info, file) = case filter (/= nullsha) [asha, bsha] of
|
mergeFile g (info, file) = case filter (/= nullsha) [asha, bsha] of
|
||||||
[] -> return Nothing
|
[] -> return Nothing
|
||||||
(sha:[]) -> return $ Just $ update_index_line sha file
|
(sha:[]) -> return $ Just $ update_index_line sha file
|
||||||
shas -> do
|
shas -> do
|
||||||
content <- Git.pipeRead g $ map Param ("show":shas)
|
content <- pipeRead g $ map Param ("show":shas)
|
||||||
sha <- Git.hashObject g $ unionmerge content
|
sha <- hashObject g $ unionmerge content
|
||||||
return $ Just $ update_index_line sha file
|
return $ Just $ update_index_line sha file
|
||||||
where
|
where
|
||||||
[_colonamode, _bmode, asha, bsha, _status] = words info
|
[_colonamode, _bmode, asha, bsha, _status] = words info
|
||||||
nullsha = take Git.shaSize $ repeat '0'
|
nullsha = take shaSize $ repeat '0'
|
||||||
unionmerge = unlines . nub . lines
|
unionmerge = unlines . nub . lines
|
||||||
|
|
||||||
{- Commits the index into the specified branch,
|
|
||||||
- with the specified parent refs. -}
|
|
||||||
commit :: Git.Repo -> String -> String -> [String] -> IO ()
|
|
||||||
commit g message newref parentrefs = do
|
|
||||||
tree <- Git.getSha "write-tree" $
|
|
||||||
Git.pipeRead g [Param "write-tree"]
|
|
||||||
sha <- Git.getSha "commit-tree" $ ignorehandle $
|
|
||||||
Git.pipeWriteRead g (map Param $ ["commit-tree", tree] ++ ps) message
|
|
||||||
Git.run g "update-ref" [Param newref, Param sha]
|
|
||||||
where
|
|
||||||
ignorehandle a = return . snd =<< a
|
|
||||||
ps = concatMap (\r -> ["-p", r]) parentrefs
|
|
|
@ -10,7 +10,7 @@ import System.FilePath
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
|
|
||||||
import qualified GitUnionMerge
|
import qualified Git.UnionMerge
|
||||||
import qualified Git
|
import qualified Git
|
||||||
|
|
||||||
header :: String
|
header :: String
|
||||||
|
@ -44,6 +44,6 @@ main = do
|
||||||
g <- Git.configRead =<< Git.repoFromCwd
|
g <- Git.configRead =<< Git.repoFromCwd
|
||||||
_ <- Git.useIndex (tmpIndex g)
|
_ <- Git.useIndex (tmpIndex g)
|
||||||
setup g
|
setup g
|
||||||
GitUnionMerge.merge g [aref, bref]
|
Git.UnionMerge.merge g [aref, bref]
|
||||||
GitUnionMerge.commit g "union merge" newref [aref, bref]
|
Git.commit g "union merge" newref [aref, bref]
|
||||||
cleanup g
|
cleanup g
|
||||||
|
|
Loading…
Reference in a new issue