converted several commands to use Remote
only move and map still to convert
This commit is contained in:
parent
3470260a85
commit
30f427700f
7 changed files with 58 additions and 46 deletions
|
@ -7,10 +7,8 @@
|
||||||
|
|
||||||
module Command.Describe where
|
module Command.Describe where
|
||||||
|
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
import qualified GitRepo as Git
|
import qualified Remote
|
||||||
import qualified Remotes
|
|
||||||
import UUID
|
import UUID
|
||||||
import Messages
|
import Messages
|
||||||
import qualified Command.Init
|
import qualified Command.Init
|
||||||
|
@ -30,12 +28,10 @@ start params = notBareRepo $ do
|
||||||
_ -> error "Specify a repository and a description."
|
_ -> error "Specify a repository and a description."
|
||||||
|
|
||||||
showStart "describe" name
|
showStart "describe" name
|
||||||
Remotes.readConfigs
|
u <- Remote.nameToUUID name
|
||||||
r <- Remotes.byName name
|
return $ Just $ perform u description
|
||||||
return $ Just $ perform r description
|
|
||||||
|
|
||||||
perform :: Git.Repo -> String -> CommandPerform
|
perform :: UUID -> String -> CommandPerform
|
||||||
perform repo description = do
|
perform u description = do
|
||||||
u <- getUUID repo
|
|
||||||
describeUUID u description
|
describeUUID u description
|
||||||
return $ Just $ Command.Init.cleanup
|
return $ Just $ Command.Init.cleanup
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
module Command.Semitrust where
|
module Command.Semitrust where
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
import qualified GitRepo as Git
|
import qualified Remote
|
||||||
import qualified Remotes
|
|
||||||
import UUID
|
import UUID
|
||||||
import Trust
|
import Trust
|
||||||
import Messages
|
import Messages
|
||||||
|
@ -24,12 +23,10 @@ seek = [withString start]
|
||||||
start :: CommandStartString
|
start :: CommandStartString
|
||||||
start name = notBareRepo $ do
|
start name = notBareRepo $ do
|
||||||
showStart "semitrust" name
|
showStart "semitrust" name
|
||||||
Remotes.readConfigs
|
u <- Remote.nameToUUID name
|
||||||
r <- Remotes.byName name
|
return $ Just $ perform u
|
||||||
return $ Just $ perform r
|
|
||||||
|
|
||||||
perform :: Git.Repo -> CommandPerform
|
perform :: UUID -> CommandPerform
|
||||||
perform repo = do
|
perform uuid = do
|
||||||
uuid <- getUUID repo
|
|
||||||
trustSet uuid SemiTrusted
|
trustSet uuid SemiTrusted
|
||||||
return $ Just $ return True
|
return $ Just $ return True
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
module Command.Trust where
|
module Command.Trust where
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
import qualified GitRepo as Git
|
import qualified Remote
|
||||||
import qualified Remotes
|
|
||||||
import Trust
|
import Trust
|
||||||
import UUID
|
import UUID
|
||||||
import Messages
|
import Messages
|
||||||
|
@ -24,12 +23,10 @@ seek = [withString start]
|
||||||
start :: CommandStartString
|
start :: CommandStartString
|
||||||
start name = notBareRepo $ do
|
start name = notBareRepo $ do
|
||||||
showStart "trust" name
|
showStart "trust" name
|
||||||
Remotes.readConfigs
|
u <- Remote.nameToUUID name
|
||||||
r <- Remotes.byName name
|
return $ Just $ perform u
|
||||||
return $ Just $ perform r
|
|
||||||
|
|
||||||
perform :: Git.Repo -> CommandPerform
|
perform :: UUID -> CommandPerform
|
||||||
perform repo = do
|
perform uuid = do
|
||||||
uuid <- getUUID repo
|
|
||||||
trustSet uuid Trusted
|
trustSet uuid Trusted
|
||||||
return $ Just $ return True
|
return $ Just $ return True
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
module Command.Untrust where
|
module Command.Untrust where
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
import qualified GitRepo as Git
|
import qualified Remote
|
||||||
import qualified Remotes
|
|
||||||
import UUID
|
import UUID
|
||||||
import Trust
|
import Trust
|
||||||
import Messages
|
import Messages
|
||||||
|
@ -24,12 +23,10 @@ seek = [withString start]
|
||||||
start :: CommandStartString
|
start :: CommandStartString
|
||||||
start name = notBareRepo $ do
|
start name = notBareRepo $ do
|
||||||
showStart "untrust" name
|
showStart "untrust" name
|
||||||
Remotes.readConfigs
|
u <- Remote.nameToUUID name
|
||||||
r <- Remotes.byName name
|
return $ Just $ perform u
|
||||||
return $ Just $ perform r
|
|
||||||
|
|
||||||
perform :: Git.Repo -> CommandPerform
|
perform :: UUID -> CommandPerform
|
||||||
perform repo = do
|
perform uuid = do
|
||||||
uuid <- getUUID repo
|
|
||||||
trustSet uuid UnTrusted
|
trustSet uuid UnTrusted
|
||||||
return $ Just $ return True
|
return $ Just $ return True
|
||||||
|
|
40
Remote.hs
40
Remote.hs
|
@ -6,12 +6,15 @@
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Remote (
|
module Remote (
|
||||||
|
byName,
|
||||||
|
nameToUUID,
|
||||||
keyPossibilities,
|
keyPossibilities,
|
||||||
remotesWithUUID,
|
remotesWithUUID,
|
||||||
remotesWithoutUUID
|
remotesWithoutUUID
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.State (liftIO)
|
import Control.Monad.State (liftIO)
|
||||||
|
import Control.Monad (when, liftM)
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
import RemoteClass
|
import RemoteClass
|
||||||
|
@ -21,6 +24,7 @@ import UUID
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Trust
|
import Trust
|
||||||
import LocationLog
|
import LocationLog
|
||||||
|
import Messages
|
||||||
|
|
||||||
{- add generators for new Remotes here -}
|
{- add generators for new Remotes here -}
|
||||||
generators :: [Annex [Remote Annex]]
|
generators :: [Annex [Remote Annex]]
|
||||||
|
@ -30,7 +34,9 @@ generators = [Remote.GitRemote.generate]
|
||||||
- Since doing so can be expensive, the list is cached in the Annex. -}
|
- Since doing so can be expensive, the list is cached in the Annex. -}
|
||||||
genList :: Annex [Remote Annex]
|
genList :: Annex [Remote Annex]
|
||||||
genList = do
|
genList = do
|
||||||
liftIO $ putStrLn "Remote.genList"
|
g <- Annex.gitRepo
|
||||||
|
u <- getUUID g
|
||||||
|
showNote $ "Remote.genList " ++ u
|
||||||
rs <- Annex.getState Annex.remotes
|
rs <- Annex.getState Annex.remotes
|
||||||
if null rs
|
if null rs
|
||||||
then do
|
then do
|
||||||
|
@ -40,13 +46,24 @@ genList = do
|
||||||
return rs'
|
return rs'
|
||||||
else return rs
|
else return rs
|
||||||
|
|
||||||
{- Filters a list of remotes to ones that have the listed uuids. -}
|
{- Looks up a remote by name. (Or by UUID.) -}
|
||||||
remotesWithUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]
|
byName :: String -> Annex (Remote Annex)
|
||||||
remotesWithUUID rs us = filter (\r -> uuid r `elem` us) rs
|
byName "" = error "no remote specified"
|
||||||
|
byName n = do
|
||||||
|
allremotes <- genList
|
||||||
|
let match = filter matching allremotes
|
||||||
|
when (null match) $ error $
|
||||||
|
"there is no git remote named \"" ++ n ++ "\""
|
||||||
|
return $ head match
|
||||||
|
where
|
||||||
|
matching r = n == name r || n == uuid r
|
||||||
|
|
||||||
{- Filters a list of remotes to ones that do not have the listed uuids. -}
|
{- Looks up a remote by name (or by UUID), and returns its UUID. -}
|
||||||
remotesWithoutUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]
|
nameToUUID :: String -> Annex UUID
|
||||||
remotesWithoutUUID rs us = filter (\r -> uuid r `notElem` us) rs
|
nameToUUID "." = do -- special case for current repo
|
||||||
|
g <- Annex.gitRepo
|
||||||
|
getUUID g
|
||||||
|
nameToUUID n = liftM uuid (byName n)
|
||||||
|
|
||||||
{- Cost ordered lists of remotes that the LocationLog indicate may have a key.
|
{- Cost ordered lists of remotes that the LocationLog indicate may have a key.
|
||||||
-
|
-
|
||||||
|
@ -71,3 +88,12 @@ keyPossibilities key = do
|
||||||
let validremotes = remotesWithUUID allremotes validuuids
|
let validremotes = remotesWithUUID allremotes validuuids
|
||||||
|
|
||||||
return (sort validremotes, validtrusteduuids)
|
return (sort validremotes, validtrusteduuids)
|
||||||
|
|
||||||
|
{- Filters a list of remotes to ones that have the listed uuids. -}
|
||||||
|
remotesWithUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]
|
||||||
|
remotesWithUUID rs us = filter (\r -> uuid r `elem` us) rs
|
||||||
|
|
||||||
|
{- Filters a list of remotes to ones that do not have the listed uuids. -}
|
||||||
|
remotesWithoutUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]
|
||||||
|
remotesWithoutUUID rs us = filter (\r -> uuid r `notElem` us) rs
|
||||||
|
|
||||||
|
|
9
UUID.hs
9
UUID.hs
|
@ -3,6 +3,9 @@
|
||||||
- Each git repository used by git-annex has an annex.uuid setting that
|
- Each git repository used by git-annex has an annex.uuid setting that
|
||||||
- uniquely identifies that repository.
|
- uniquely identifies that repository.
|
||||||
-
|
-
|
||||||
|
- UUIDs of remotes are cached in git config, using keys named
|
||||||
|
- remote.<name>.annex-uuid
|
||||||
|
-
|
||||||
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
|
@ -51,11 +54,7 @@ genUUID = liftIO $ pOpen ReadFromPipe command params $ \h -> hGetLine h
|
||||||
else []
|
else []
|
||||||
|
|
||||||
{- Looks up a repo's UUID. May return "" if none is known.
|
{- Looks up a repo's UUID. May return "" if none is known.
|
||||||
-
|
-}
|
||||||
- UUIDs of remotes are cached in git config, using keys named
|
|
||||||
- remote.<name>.annex-uuid
|
|
||||||
-
|
|
||||||
- -}
|
|
||||||
getUUID :: Git.Repo -> Annex UUID
|
getUUID :: Git.Repo -> Annex UUID
|
||||||
getUUID r = do
|
getUUID r = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
|
|
2
test.hs
2
test.hs
|
@ -334,6 +334,7 @@ test_trust = "git-annex trust/untrust/semitrust" ~: intmpclonerepo $ do
|
||||||
git_annex "semitrust" ["-q", repo] @? "semitrust of semitrusted failed"
|
git_annex "semitrust" ["-q", repo] @? "semitrust of semitrusted failed"
|
||||||
trustcheck Trust.SemiTrusted "semitrusted 2"
|
trustcheck Trust.SemiTrusted "semitrusted 2"
|
||||||
where
|
where
|
||||||
|
repo = "origin"
|
||||||
trustcheck expected msg = do
|
trustcheck expected msg = do
|
||||||
present <- annexeval $ do
|
present <- annexeval $ do
|
||||||
Remotes.readConfigs
|
Remotes.readConfigs
|
||||||
|
@ -342,7 +343,6 @@ test_trust = "git-annex trust/untrust/semitrust" ~: intmpclonerepo $ do
|
||||||
u <- UUID.getUUID r
|
u <- UUID.getUUID r
|
||||||
return $ u `elem` l
|
return $ u `elem` l
|
||||||
assertBool msg present
|
assertBool msg present
|
||||||
repo = "origin"
|
|
||||||
|
|
||||||
test_fsck :: Test
|
test_fsck :: Test
|
||||||
test_fsck = "git-annex fsck" ~: TestList [basicfsck, withlocaluntrusted, withremoteuntrusted]
|
test_fsck = "git-annex fsck" ~: TestList [basicfsck, withlocaluntrusted, withremoteuntrusted]
|
||||||
|
|
Loading…
Reference in a new issue