bug
This commit is contained in:
parent
d4ce072452
commit
aa2f4bd810
5 changed files with 46 additions and 46 deletions
15
Annex.hs
15
Annex.hs
|
@ -14,9 +14,18 @@ import qualified GitRepo as Git
|
||||||
import Types
|
import Types
|
||||||
import qualified BackendTypes as Backend
|
import qualified BackendTypes as Backend
|
||||||
|
|
||||||
-- constructor
|
{- Create and returns an Annex state object for the specified git repo.
|
||||||
new :: Git.Repo -> AnnexState
|
-}
|
||||||
new g = Backend.AnnexState { Backend.repo = g, Backend.backends = [] }
|
new :: Git.Repo -> IO AnnexState
|
||||||
|
new g = do
|
||||||
|
let s = Backend.AnnexState { Backend.repo = g, Backend.backends = [] }
|
||||||
|
(_,s') <- Annex.run s (prep g)
|
||||||
|
return s'
|
||||||
|
where
|
||||||
|
prep g = do
|
||||||
|
-- read git config and update state
|
||||||
|
g' <- liftIO $ Git.configRead g
|
||||||
|
Annex.gitRepoChange g'
|
||||||
|
|
||||||
-- performs an action in the Annex monad
|
-- performs an action in the Annex monad
|
||||||
run state action = runStateT (action) state
|
run state action = runStateT (action) state
|
||||||
|
|
|
@ -52,7 +52,7 @@ storeFileKey :: FilePath -> Annex (Maybe (Key, Backend))
|
||||||
storeFileKey file = do
|
storeFileKey file = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
let relfile = Git.relative g file
|
let relfile = Git.relative g file
|
||||||
b <- Annex.backends
|
b <- backendList
|
||||||
storeFileKey' b file relfile
|
storeFileKey' b file relfile
|
||||||
storeFileKey' [] _ _ = return Nothing
|
storeFileKey' [] _ _ = return Nothing
|
||||||
storeFileKey' (b:bs) file relfile = do
|
storeFileKey' (b:bs) file relfile = do
|
||||||
|
|
|
@ -14,6 +14,7 @@ import Locations
|
||||||
import qualified Remotes
|
import qualified Remotes
|
||||||
import qualified GitRepo as Git
|
import qualified GitRepo as Git
|
||||||
import Utility
|
import Utility
|
||||||
|
import Core
|
||||||
|
|
||||||
backend = Backend {
|
backend = Backend {
|
||||||
name = "file",
|
name = "file",
|
||||||
|
|
67
Core.hs
67
Core.hs
|
@ -6,52 +6,39 @@ import System.IO
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import Control.Monad.State (liftIO)
|
import Control.Monad.State (liftIO)
|
||||||
import Types
|
import Types
|
||||||
import BackendList
|
|
||||||
import Locations
|
import Locations
|
||||||
import UUID
|
import UUID
|
||||||
import qualified GitRepo as Git
|
import qualified GitRepo as Git
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
|
||||||
{- Create and returns an Annex state object.
|
|
||||||
- Examines and prepares the git repo.
|
|
||||||
-}
|
|
||||||
start :: IO AnnexState
|
|
||||||
start = do
|
|
||||||
g <- Git.repoFromCwd
|
|
||||||
let s = Annex.new g
|
|
||||||
(_,s') <- Annex.run s (prep g)
|
|
||||||
return s'
|
|
||||||
where
|
|
||||||
prep g = do
|
|
||||||
-- setup git and read its config; update state
|
|
||||||
g' <- liftIO $ Git.configRead g
|
|
||||||
Annex.gitRepoChange g'
|
|
||||||
liftIO $ gitSetup g'
|
|
||||||
prepUUID
|
|
||||||
|
|
||||||
{- Sets up a git repo for git-annex. May be called repeatedly. -}
|
{- Sets up a git repo for git-annex. May be called repeatedly. -}
|
||||||
gitSetup :: Git.Repo -> IO ()
|
gitSetup :: Annex ()
|
||||||
gitSetup repo = do
|
gitSetup = do
|
||||||
-- configure git to use union merge driver on state files
|
g <- Annex.gitRepo
|
||||||
exists <- doesFileExist attributes
|
liftIO $ setupattributes g
|
||||||
if (not exists)
|
prepUUID
|
||||||
then do
|
|
||||||
writeFile attributes $ attrLine ++ "\n"
|
|
||||||
commit
|
|
||||||
else do
|
|
||||||
content <- readFile attributes
|
|
||||||
if (all (/= attrLine) (lines content))
|
|
||||||
then do
|
|
||||||
appendFile attributes $ attrLine ++ "\n"
|
|
||||||
commit
|
|
||||||
else return ()
|
|
||||||
where
|
where
|
||||||
attrLine = stateLoc ++ "/*.log merge=union"
|
-- configure git to use union merge driver on state files
|
||||||
attributes = Git.attributes repo
|
setupattributes repo = do
|
||||||
commit = do
|
exists <- doesFileExist attributes
|
||||||
Git.run repo ["add", attributes]
|
if (not exists)
|
||||||
Git.run repo ["commit", "-m", "git-annex setup",
|
then do
|
||||||
attributes]
|
writeFile attributes $ attrLine ++ "\n"
|
||||||
|
commit
|
||||||
|
else do
|
||||||
|
content <- readFile attributes
|
||||||
|
if (all (/= attrLine) (lines content))
|
||||||
|
then do
|
||||||
|
appendFile attributes $ attrLine ++ "\n"
|
||||||
|
commit
|
||||||
|
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]
|
||||||
|
|
||||||
{- Checks if a given key is currently present in the annexLocation -}
|
{- Checks if a given key is currently present in the annexLocation -}
|
||||||
inAnnex :: Backend -> Key -> Annex Bool
|
inAnnex :: Backend -> Key -> Annex Bool
|
||||||
|
|
|
@ -7,12 +7,15 @@ import qualified Annex
|
||||||
import Types
|
import Types
|
||||||
import Core
|
import Core
|
||||||
import Commands
|
import Commands
|
||||||
|
import Annex
|
||||||
|
import qualified GitRepo as Git
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
actions <- argvToActions args
|
actions <- argvToActions args
|
||||||
state <- start
|
gitrepo <- Git.repoFromCwd
|
||||||
tryRun state actions
|
state <- new gitrepo
|
||||||
|
tryRun state (gitSetup:actions)
|
||||||
|
|
||||||
{- Runs a list of Annex actions. Catches exceptions, not stopping
|
{- Runs a list of Annex actions. Catches exceptions, not stopping
|
||||||
- if some error out, and propigates an overall error status at the end.
|
- if some error out, and propigates an overall error status at the end.
|
||||||
|
|
Loading…
Reference in a new issue