two types of byName
Clean up from 9769235d6b
.
In some cases, looking up a remote by name even though it has no UUID is
desirable. This includes git annex sync, which can operate on remotes
without an annex, and XMPP pairing, which runs addRemote (with calls
byName) before the UUID of the XMPP remote has been configured in git.
This commit is contained in:
parent
9e75dce764
commit
921f29c004
10 changed files with 27 additions and 16 deletions
|
@ -52,7 +52,8 @@ addRemote :: Annex String -> Annex Remote
|
|||
addRemote a = do
|
||||
name <- a
|
||||
void remoteListRefresh
|
||||
maybe (error "failed to add remote") return =<< Remote.byName (Just name)
|
||||
maybe (error "failed to add remote") return
|
||||
=<< Remote.byName (Just name)
|
||||
|
||||
{- Inits a rsync special remote, and returns its name. -}
|
||||
makeRsyncRemote :: String -> String -> Annex String
|
||||
|
|
|
@ -18,8 +18,8 @@ def = [withOptions Command.Move.options $ command "copy" paramPaths seek
|
|||
"copy content of files to/from another repository"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withField Command.Move.toOption Remote.byName $ \to ->
|
||||
withField Command.Move.fromOption Remote.byName $ \from ->
|
||||
seek = [withField Command.Move.toOption Remote.byNameWithUUID $ \to ->
|
||||
withField Command.Move.fromOption Remote.byNameWithUUID $ \from ->
|
||||
withFilesInGit $ whenAnnexed $ start to from]
|
||||
|
||||
{- A copy is just a move that does not delete the source file.
|
||||
|
|
|
@ -27,7 +27,7 @@ fromOption :: Option
|
|||
fromOption = Option.field ['f'] "from" paramRemote "drop content from a remote"
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withField fromOption Remote.byName $ \from ->
|
||||
seek = [withField fromOption Remote.byNameWithUUID $ \from ->
|
||||
withFilesInGit $ whenAnnexed $ start from]
|
||||
|
||||
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
||||
|
|
|
@ -28,7 +28,7 @@ start :: UnusedMaps -> Int -> CommandStart
|
|||
start = startUnused "dropunused" perform (performOther gitAnnexBadLocation) (performOther gitAnnexTmpLocation)
|
||||
|
||||
perform :: Key -> CommandPerform
|
||||
perform key = maybe droplocal dropremote =<< Remote.byName =<< from
|
||||
perform key = maybe droplocal dropremote =<< Remote.byNameWithUUID =<< from
|
||||
where
|
||||
dropremote r = do
|
||||
showAction $ "from " ++ Remote.name r
|
||||
|
|
|
@ -61,7 +61,7 @@ options =
|
|||
|
||||
seek :: [CommandSeek]
|
||||
seek =
|
||||
[ withField fromOption Remote.byName $ \from ->
|
||||
[ withField fromOption Remote.byNameWithUUID $ \from ->
|
||||
withIncremental $ \i -> withFilesInGit $ whenAnnexed $ start from i
|
||||
, withIncremental $ \i -> withBarePresentKeys $ startBare i
|
||||
]
|
||||
|
|
|
@ -20,7 +20,7 @@ def = [withOptions [Command.Move.fromOption] $ command "get" paramPaths seek
|
|||
"make content of annexed files available"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withField Command.Move.fromOption Remote.byName $ \from ->
|
||||
seek = [withField Command.Move.fromOption Remote.byNameWithUUID $ \from ->
|
||||
withFilesInGit $ whenAnnexed $ start from]
|
||||
|
||||
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
||||
|
|
|
@ -32,8 +32,8 @@ options :: [Option]
|
|||
options = [fromOption, toOption]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withField toOption Remote.byName $ \to ->
|
||||
withField fromOption Remote.byName $ \from ->
|
||||
seek = [withField toOption Remote.byNameWithUUID $ \to ->
|
||||
withField fromOption Remote.byNameWithUUID $ \from ->
|
||||
withFilesInGit $ whenAnnexed $ start to from True]
|
||||
|
||||
start :: Maybe Remote -> Maybe Remote -> Bool -> FilePath -> (Key, Backend) -> CommandStart
|
||||
|
|
|
@ -29,8 +29,8 @@ fileOption :: Option
|
|||
fileOption = Option.field [] "file" paramFile "the associated file"
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withField Command.Move.toOption Remote.byName $ \to ->
|
||||
withField Command.Move.fromOption Remote.byName $ \from ->
|
||||
seek = [withField Command.Move.toOption Remote.byNameWithUUID $ \to ->
|
||||
withField Command.Move.fromOption Remote.byNameWithUUID $ \from ->
|
||||
withField fileOption return $ \file ->
|
||||
withKeys $ start to from file]
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ checkUnused = chain 0
|
|||
chain v' as
|
||||
|
||||
checkRemoteUnused :: String -> CommandPerform
|
||||
checkRemoteUnused name = go =<< fromJust <$> Remote.byName (Just name)
|
||||
checkRemoteUnused name = go =<< fromJust <$> Remote.byNameWithUUID (Just name)
|
||||
where
|
||||
go r = do
|
||||
showAction "checking for unused data"
|
||||
|
|
18
Remote.hs
18
Remote.hs
|
@ -24,6 +24,7 @@ module Remote (
|
|||
remoteMap,
|
||||
uuidDescriptions,
|
||||
byName,
|
||||
byNameWithUUID,
|
||||
byCost,
|
||||
prettyPrintUUIDs,
|
||||
prettyListUUIDs,
|
||||
|
@ -72,18 +73,27 @@ addName desc n
|
|||
| otherwise = n ++ " (" ++ desc ++ ")"
|
||||
|
||||
{- When a name is specified, looks up the remote matching that name.
|
||||
- (Or it can be a UUID.) Only finds currently configured git remotes. -}
|
||||
- (Or it can be a UUID.) -}
|
||||
byName :: Maybe String -> Annex (Maybe Remote)
|
||||
byName Nothing = return Nothing
|
||||
byName (Just n) = either error Just <$> byName' n
|
||||
|
||||
{- Like byName, but the remote must have a configured UUID. -}
|
||||
byNameWithUUID :: Maybe String -> Annex (Maybe Remote)
|
||||
byNameWithUUID n = do
|
||||
v <- byName n
|
||||
return $ checkuuid <$> v
|
||||
where
|
||||
checkuuid r
|
||||
| uuid r == NoUUID = error $ "cannot determine uuid for " ++ name r
|
||||
| otherwise = r
|
||||
|
||||
byName' :: String -> Annex (Either String Remote)
|
||||
byName' "" = return $ Left "no remote specified"
|
||||
byName' n = handle . filter matching <$> remoteList
|
||||
where
|
||||
handle [] = Left $ "there is no available git remote named \"" ++ n ++ "\""
|
||||
handle (match:_)
|
||||
| uuid match == NoUUID = Left $ "cannot determine uuid for " ++ name match
|
||||
| otherwise = Right match
|
||||
handle (match:_) = Right match
|
||||
matching r = n == name r || toUUID n == uuid r
|
||||
|
||||
{- Looks up a remote by name (or by UUID, or even by description),
|
||||
|
|
Loading…
Reference in a new issue