move commit to Git.Branch

This commit is contained in:
Joey Hess 2011-12-13 15:08:44 -04:00
parent 13fff71f20
commit 25b2cc4148
3 changed files with 19 additions and 20 deletions

View file

@ -71,7 +71,7 @@ getBranch = maybe (hasOrigin >>= go >>= use) (return) =<< branchsha
fromMaybe (error $ "failed to create " ++ show name) fromMaybe (error $ "failed to create " ++ show name)
<$> branchsha <$> branchsha
go False = withIndex' True $ do go False = withIndex' True $ do
inRepo $ Git.commit "branch created" fullname [] inRepo $ Git.Branch.commit "branch created" fullname []
use sha = do use sha = do
setIndexSha sha setIndexSha sha
return sha return sha
@ -190,7 +190,7 @@ commit message = whenM journalDirty $ lockJournal $ do
commitBranch :: Git.Ref -> String -> [Git.Ref] -> Annex () commitBranch :: Git.Ref -> String -> [Git.Ref] -> Annex ()
commitBranch branchref message parents = do commitBranch branchref message parents = do
updateIndex branchref updateIndex branchref
committedref <- inRepo $ Git.commit message fullname parents committedref <- inRepo $ Git.Branch.commit message fullname parents
setIndexSha committedref setIndexSha committedref
parentrefs <- commitparents <$> catObject committedref parentrefs <- commitparents <$> catObject committedref
when (racedetected branchref parentrefs) $ when (racedetected branchref parentrefs) $

18
Git.hs
View file

@ -52,7 +52,6 @@ module Git (
useIndex, useIndex,
getSha, getSha,
shaSize, shaSize,
commit,
assertLocal, assertLocal,
prop_idempotent_deencode prop_idempotent_deencode
@ -354,23 +353,6 @@ getSha subcommand a = do
shaSize :: Int shaSize :: Int
shaSize = 40 shaSize = 40
{- Commits the index into the specified branch (or other ref),
- with the specified parent refs, and returns the committed sha -}
commit :: String -> Branch -> [Ref] -> Repo -> IO Sha
commit message branch parentrefs repo = do
tree <- getSha "write-tree" $ asString $
pipeRead [Param "write-tree"] repo
sha <- getSha "commit-tree" $ asString $
ignorehandle $ pipeWriteRead
(map Param $ ["commit-tree", show tree] ++ ps)
(L.pack message) repo
run "update-ref" [Param $ show branch, Param $ show sha] repo
return sha
where
ignorehandle a = snd <$> a
asString a = L.unpack <$> a
ps = concatMap (\r -> ["-p", show r]) parentrefs
{- Checks if a string from git config is a true value. -} {- Checks if a string from git config is a true value. -}
configTrue :: String -> Bool configTrue :: String -> Bool
configTrue s = map toLower s == "true" configTrue s = map toLower s == "true"

View file

@ -58,3 +58,20 @@ fastForward branch (first:rest) repo = do
(True, False) -> findbest r rs -- better (True, False) -> findbest r rs -- better
(False, True) -> findbest c rs -- worse (False, True) -> findbest c rs -- worse
(False, False) -> findbest c rs -- same (False, False) -> findbest c rs -- same
{- Commits the index into the specified branch (or other ref),
- with the specified parent refs, and returns the committed sha -}
commit :: String -> Branch -> [Ref] -> Repo -> IO Sha
commit message branch parentrefs repo = do
tree <- getSha "write-tree" $ asString $
pipeRead [Param "write-tree"] repo
sha <- getSha "commit-tree" $ asString $
ignorehandle $ pipeWriteRead
(map Param $ ["commit-tree", show tree] ++ ps)
(L.pack message) repo
run "update-ref" [Param $ show branch, Param $ show sha] repo
return sha
where
ignorehandle a = snd <$> a
asString a = L.unpack <$> a
ps = concatMap (\r -> ["-p", show r]) parentrefs