summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-05 15:39:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-05 15:43:56 -0400
commit5c46685ab3bc1f579e55d764d5887b7f4a208d65 (patch)
tree7bb19dd15cea25d8c3617e4a3e12e92c1a28ab64
parent349da7cd84ab7b5d4b602bc3ab51e3a548a1633a (diff)
two types of byName
Clean up from 5123a1a83aa3b954fe67629508bab5ccea0e4148. 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.
-rw-r--r--Assistant/MakeRemote.hs3
-rw-r--r--Command/Copy.hs4
-rw-r--r--Command/Drop.hs2
-rw-r--r--Command/DropUnused.hs2
-rw-r--r--Command/Fsck.hs2
-rw-r--r--Command/Get.hs2
-rw-r--r--Command/Move.hs4
-rw-r--r--Command/TransferKey.hs4
-rw-r--r--Command/Unused.hs2
-rw-r--r--Remote.hs18
10 files changed, 27 insertions, 16 deletions
diff --git a/Assistant/MakeRemote.hs b/Assistant/MakeRemote.hs
index b01b051f6..113018363 100644
--- a/Assistant/MakeRemote.hs
+++ b/Assistant/MakeRemote.hs
@@ -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
diff --git a/Command/Copy.hs b/Command/Copy.hs
index 6967c2f93..4b04a2423 100644
--- a/Command/Copy.hs
+++ b/Command/Copy.hs
@@ -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.
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 1683f3b57..5699175ed 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -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
diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs
index 95af062f5..ccf43c040 100644
--- a/Command/DropUnused.hs
+++ b/Command/DropUnused.hs
@@ -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
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index b662ee578..a27588482 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -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
]
diff --git a/Command/Get.hs b/Command/Get.hs
index 9c58bde64..95f71a84b 100644
--- a/Command/Get.hs
+++ b/Command/Get.hs
@@ -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
diff --git a/Command/Move.hs b/Command/Move.hs
index 6d087ecae..cc8fb506f 100644
--- a/Command/Move.hs
+++ b/Command/Move.hs
@@ -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
diff --git a/Command/TransferKey.hs b/Command/TransferKey.hs
index 28ace3cd2..407c1d483 100644
--- a/Command/TransferKey.hs
+++ b/Command/TransferKey.hs
@@ -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]
diff --git a/Command/Unused.hs b/Command/Unused.hs
index 5f8af2185..64a619b0a 100644
--- a/Command/Unused.hs
+++ b/Command/Unused.hs
@@ -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"
diff --git a/Remote.hs b/Remote.hs
index 22e304de3..4f8b7cf6a 100644
--- a/Remote.hs
+++ b/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),