git-annex/Core.hs

63 lines
1.5 KiB
Haskell
Raw Normal View History

2010-10-14 07:40:26 +00:00
{- git-annex core functions -}
module Core where
import System.IO
import System.Directory
import Control.Monad.State (liftIO)
import Types
import Locations
import UUID
import qualified GitRepo as Git
import qualified Annex
2010-10-14 20:13:43 +00:00
2010-10-14 21:57:04 +00:00
{- Sets up a git repo for git-annex. -}
startup :: [Flag] -> Annex ()
startup flags = do
2010-10-15 03:52:45 +00:00
mapM (\f -> Annex.flagChange f True) flags
2010-10-14 20:13:43 +00:00
g <- Annex.gitRepo
2010-10-14 21:57:04 +00:00
liftIO $ gitAttributes g
2010-10-14 20:13:43 +00:00
prepUUID
2010-10-14 21:57:04 +00:00
{- When git-annex is done, it runs this. -}
shutdown :: Annex ()
shutdown = do
g <- Annex.gitRepo
2010-10-15 03:52:45 +00:00
needcommit <- Annex.flagIsSet NeedCommit
if (needcommit)
2010-10-16 17:22:48 +00:00
then liftIO $ Git.run g ["commit", "-q", "-m",
2010-10-15 18:31:06 +00:00
"git-annex log update", gitStateDir g]
2010-10-15 03:52:45 +00:00
else return ()
2010-10-14 21:57:04 +00:00
{- configure git to use union merge driver on state files, if it is not
- already -}
gitAttributes :: Git.Repo -> IO ()
gitAttributes repo = do
exists <- doesFileExist attributes
if (not exists)
then do
writeFile attributes $ attrLine ++ "\n"
commit
else do
content <- readFile attributes
if (all (/= attrLine) (lines content))
2010-10-14 07:40:26 +00:00
then do
2010-10-14 21:57:04 +00:00
appendFile attributes $ attrLine ++ "\n"
2010-10-14 07:40:26 +00:00
commit
2010-10-14 21:57:04 +00:00
else return ()
where
attrLine = stateLoc ++ "/*.log merge=union"
attributes = Git.attributes repo
commit = do
Git.run repo ["add", attributes]
Git.run repo ["commit", "-m", "git-annex setup",
attributes]
2010-10-14 18:38:29 +00:00
{- Checks if a given key is currently present in the annexLocation -}
2010-10-14 23:36:11 +00:00
inAnnex :: Key -> Annex Bool
inAnnex key = do
2010-10-14 18:38:29 +00:00
g <- Annex.gitRepo
2010-10-14 23:36:11 +00:00
liftIO $ doesFileExist $ annexLocation g key
{- -}