Allow --trust etc to specify a repository by name, for temporarily trusting repositories that are not configured remotes.

This commit is contained in:
Joey Hess 2011-06-13 22:19:44 -04:00
parent 66f5b390fe
commit f547277b75
3 changed files with 26 additions and 8 deletions

View file

@ -34,7 +34,7 @@ module Remote (
) where
import Control.Monad.State (liftIO)
import Control.Monad (when, liftM, filterM)
import Control.Monad (filterM)
import Data.List
import qualified Data.Map as M
import Data.Maybe
@ -91,20 +91,35 @@ genList = do
{- Looks up a remote by name. (Or by UUID.) -}
byName :: String -> Annex (Remote Annex)
byName "" = error "no remote specified"
byName n = do
res <- byName' n
case res of
Left e -> error e
Right r -> return r
byName' :: String -> Annex (Either String (Remote Annex))
byName' "" = return $ Left "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
if (null match)
then return $ Left $ "there is no git remote named \"" ++ n ++ "\""
else return $ Right $ head match
where
matching r = n == name r || n == uuid r
{- Looks up a remote by name (or by UUID), and returns its UUID. -}
{- Looks up a remote by name (or by UUID, or even by description),
- and returns its UUID. -}
nameToUUID :: String -> Annex UUID
nameToUUID "." = getUUID =<< Annex.gitRepo -- special case for current repo
nameToUUID n = liftM uuid (byName n)
nameToUUID n = do
res <- byName' n
case res of
Left e -> return . (maybe (error e) id) =<< byDescription
Right r -> return $ uuid r
where
byDescription = return . M.lookup n . invertMap =<< uuidMap
invertMap = M.fromList . map swap . M.toList
swap (a, b) = (b, a)
{- Filters a list of remotes to ones that have the listed uuids. -}
remotesWithUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]

2
debian/changelog vendored
View file

@ -4,6 +4,8 @@ git-annex (0.20110611) UNRELEASED; urgency=low
cp is still used when copying file from repos on the same filesystem,
since --reflink=auto can make it significantly faster on filesystems
such as btrfs.
* Allow --trust etc to specify a repository by name, for temporarily
trusting repositories that are not configured remotes.
-- Joey Hess <joeyh@debian.org> Mon, 13 Jun 2011 19:53:24 -0400

View file

@ -365,7 +365,8 @@ Many git-annex commands will stage changes for later `git commit` by you.
Overrides trust settings for a repository. May be specified more than once.
The repository should be specified using the name of a configured remote.
The repository should be specified using the name of a configured remote,
or the UUID or description of a repository.
* --backend=name