diff options
author | Joey Hess <joey@kitenet.net> | 2013-12-01 13:59:39 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-12-01 13:59:45 -0400 |
commit | 91bf77fae4e0645d466db01a9a45f6a380c933f7 (patch) | |
tree | a2e57e048dfb9c40edd6ae74d293ec92beb23eb1 /Annex | |
parent | 05224f307e37aa51b8daa11ce2d2657e4b41bed3 (diff) |
Avoid using git commit in direct mode, since in some situations it will read the full contents of files in the tree.
The assistant's commit code also always avoids git commit, for simplicity.
Indirect mode sync still does a git commit -a to catch unstaged changes.
Note that this means that direct mode sync no longer runs the pre-commit
hook or any other hooks git commit might call. The git annex pre-commit
hook action for direct mode is however explicitly run. (The assistant
already ran git commit with hooks disabled, so no change there.)
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/Branch.hs | 6 | ||||
-rw-r--r-- | Annex/Direct.hs | 24 |
2 files changed, 25 insertions, 5 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs index 9838af25f..658ad731f 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -95,7 +95,7 @@ getBranch = maybe (hasOrigin >>= go >>= use) return =<< branchsha fromMaybe (error $ "failed to create " ++ show name) <$> branchsha go False = withIndex' True $ - inRepo $ Git.Branch.commit "branch created" fullname [] + inRepo $ Git.Branch.commitAlways "branch created" fullname [] use sha = do setIndexSha sha return sha @@ -249,7 +249,7 @@ commitIndex jl branchref message parents = do commitIndex' :: JournalLocked -> Git.Ref -> String -> [Git.Ref] -> Annex () commitIndex' jl branchref message parents = do updateIndex jl branchref - committedref <- inRepo $ Git.Branch.commit message fullname parents + committedref <- inRepo $ Git.Branch.commitAlways message fullname parents setIndexSha committedref parentrefs <- commitparents <$> catObject committedref when (racedetected branchref parentrefs) $ do @@ -486,7 +486,7 @@ performTransitionsLocked jl ts neednewlocalbranch transitionedrefs = do Annex.Queue.flush if neednewlocalbranch then do - committedref <- inRepo $ Git.Branch.commit message fullname transitionedrefs + committedref <- inRepo $ Git.Branch.commitAlways message fullname transitionedrefs setIndexSha committedref else do ref <- getBranch diff --git a/Annex/Direct.hs b/Annex/Direct.hs index 3fa5f9362..1034e6547 100644 --- a/Annex/Direct.hs +++ b/Annex/Direct.hs @@ -1,6 +1,6 @@ {- git-annex direct mode - - - Copyright 2012 Joey Hess <joey@kitenet.net> + - Copyright 2012, 2013 Joey Hess <joey@kitenet.net> - - Licensed under the GNU GPL version 3 or higher. -} @@ -88,7 +88,27 @@ stageDirect = do addgit file = Annex.Queue.addCommand "add" [Param "-f"] [file] - deletegit file = Annex.Queue.addCommand "rm" [Param "-f"] [file] + deletegit file = Annex.Queue.addCommand "rm" [Param "-qf"] [file] + +{- Run before a commit to update direct mode bookeeping to reflect the + - staged changes being committed. -} +preCommitDirect :: Annex Bool +preCommitDirect = do + (diffs, clean) <- inRepo $ DiffTree.diffIndex Git.Ref.headRef + makeabs <- flip fromTopFilePath <$> gitRepo + forM_ diffs (go makeabs) + liftIO clean + where + go makeabs diff = do + withkey (DiffTree.srcsha diff) (DiffTree.srcmode diff) removeAssociatedFile + withkey (DiffTree.dstsha diff) (DiffTree.dstmode diff) addAssociatedFile + where + withkey sha mode a = when (sha /= nullSha) $ do + k <- catKey sha mode + case k of + Nothing -> noop + Just key -> void $ a key $ + makeabs $ DiffTree.file diff {- Adds a file to the annex in direct mode. Can fail, if the file is - modified or deleted while it's being added. -} |