| n' == n -> True
| otherwise -> False
-remoteNames :: Annex [RemoteName]
-remoteNames = do
+specialRemoteMap :: Annex (M.Map UUID RemoteName)
+specialRemoteMap = do
m <- Logs.Remote.readRemoteLog
- return $ mapMaybe (M.lookup nameKey . snd) $ M.toList m
+ return $ M.fromList $ mapMaybe go (M.toList m)
+ where
+ go (u, c) = case M.lookup nameKey c of
+ Nothing -> Nothing
+ Just n -> Just (u, n)
{- find the specified remote type -}
findType :: RemoteConfig -> Either String RemoteType
import qualified Logs.Remote
import qualified Types.Remote as R
import qualified Annex.SpecialRemote
+import qualified Remote
+import Logs.UUID
import qualified Data.Map as M
seek = withWords start
start :: [String] -> CommandStart
-start [] = unknownNameError "Specify the name of the special remote to enable."
+start [] = unknownNameError "Specify the special remote to enable."
start (name:ws) = go =<< Annex.SpecialRemote.findExisting name
where
config = Logs.Remote.keyValToConfig ws
- go Nothing = unknownNameError "Unknown special remote name."
+ go Nothing = do
+ m <- Annex.SpecialRemote.specialRemoteMap
+ confm <- Logs.Remote.readRemoteLog
+ v <- Remote.nameToUUID' name
+ case v of
+ Right u | u `M.member` m ->
+ go (Just (u, fromMaybe M.empty (M.lookup u confm)))
+ _ -> unknownNameError "Unknown special remote."
go (Just (u, c)) = do
let fullconfig = config `M.union` c
t <- either error return (Annex.SpecialRemote.findType fullconfig)
unknownNameError :: String -> Annex a
unknownNameError prefix = do
- names <- Annex.SpecialRemote.remoteNames
- error $ prefix ++ "\n" ++
- if null names
- then "(No special remotes are currently known; perhaps use initremote instead?)"
- else "Known special remotes: " ++ unwords names
+ m <- Annex.SpecialRemote.specialRemoteMap
+ descm <- M.unionWith Remote.addName <$> uuidMap <*> pure m
+ msg <- if M.null m
+ then pure "(No special remotes are currently known; perhaps use initremote instead?)"
+ else Remote.prettyPrintUUIDsDescs
+ "known special remotes"
+ descm (M.keys m)
+ error $ prefix ++ "\n" ++ msg
perform :: RemoteType -> UUID -> R.RemoteConfig -> CommandPerform
perform t u c = do
. M.toList
<$> cachedRepoData
let maxlen = maximum (map (length . snd) l)
+ descm <- lift uuidDescriptions
-- This also handles json display.
- s <- lift $ prettyPrintUUIDsWith (Just "size") desc $
+ s <- lift $ prettyPrintUUIDsWith (Just "size") desc descm $
map (\(u, sz) -> (u, Just $ mkdisp sz maxlen)) l
return $ countRepoList (length l) s
where
remoteMap,
remoteMap',
uuidDescriptions,
+ addName,
byName,
byName',
byNameOrGroup,
byNameWithUUID,
byCost,
prettyPrintUUIDs,
+ prettyPrintUUIDsDescs,
prettyPrintUUIDsWith,
prettyListUUIDs,
prettyUUID,
_ -> Right u
_us -> Left "Found multiple repositories with that description"
-{- Pretty-prints a list of UUIDs of remotes, for human display.
+{- Pretty-prints a list of UUIDs of remotes, with their descriptions,
+ - for human display.
-
- When JSON is enabled, also outputs a machine-readable description
- of the UUIDs. -}
prettyPrintUUIDs :: String -> [UUID] -> Annex String
-prettyPrintUUIDs desc uuids = prettyPrintUUIDsWith Nothing desc $
- zip uuids (repeat (Nothing :: Maybe String))
+prettyPrintUUIDs header uuids = do
+ descm <- uuidDescriptions
+ prettyPrintUUIDsDescs header descm uuids
+
+prettyPrintUUIDsDescs :: String -> M.Map UUID RemoteName -> [UUID] -> Annex String
+prettyPrintUUIDsDescs header descm uuids =
+ prettyPrintUUIDsWith Nothing header descm
+ (zip uuids (repeat (Nothing :: Maybe String)))
{- An optional field can be included in the list of UUIDs. -}
prettyPrintUUIDsWith
:: (JSON v, Show v)
=> Maybe String
-> String
+ -> M.Map UUID RemoteName
-> [(UUID, Maybe v)]
-> Annex String
-prettyPrintUUIDsWith optfield desc uuids = do
+prettyPrintUUIDsWith optfield header descm uuidvals = do
hereu <- getUUID
- m <- uuidDescriptions
- maybeShowJSON [(desc, map (jsonify m hereu) uuids)]
- return $ unwords $ map (\u -> "\t" ++ prettify m hereu u ++ "\n") uuids
+ maybeShowJSON [(header, map (jsonify hereu) uuidvals)]
+ return $ unwords $ map (\u -> "\t" ++ prettify hereu u ++ "\n") uuidvals
where
- finddescription m u = M.findWithDefault "" u m
- prettify m hereu (u, optval)
+ finddescription u = M.findWithDefault "" u descm
+ prettify hereu (u, optval)
| not (null d) = addoptval $ fromUUID u ++ " -- " ++ d
| otherwise = addoptval $ fromUUID u
where
ishere = hereu == u
- n = finddescription m u
+ n = finddescription u
d
| null n && ishere = "here"
| ishere = addName n "here"
addoptval s = case optval of
Nothing -> s
Just val -> show val ++ ": " ++ s
- jsonify m hereu (u, optval) = toJSObject $ catMaybes
+ jsonify hereu (u, optval) = toJSObject $ catMaybes
[ Just ("uuid", toJSON $ fromUUID u)
- , Just ("description", toJSON $ finddescription m u)
+ , Just ("description", toJSON $ finddescription u)
, Just ("here", toJSON $ hereu == u)
, case (optfield, optval) of
(Just field, Just val) -> Just (field, showJSON val)
* Use statvfs on OSX.
* Symlink timestamp preservation code uses functions
from unix-2.7.0 when available, which should be more portable.
+ * enableremote: List uuids and descriptions of remotes that can be
+ enabled, and accept either the uuid or the description in leu if the
+ name.
-- Joey Hess <id@joeyh.name> Mon, 19 Oct 2015 17:00:21 -0400
# SYNOPSIS
-git annex enableremote `name [param=value ...]`
+git annex enableremote `name|uuid|desc [param=value ...]`
# DESCRIPTION
The name of the remote is the same name used when originally
creating that remote with `git annex initremote`. Run
`git annex enableremote` without any name to get a list of
-special remote names.
+special remote names. Or you can specify the uuid or description of the
+remote.
Some special remotes may need parameters to be specified every time they are
enabled. For example, the directory special remote requires a directory=
--- /dev/null
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 26"""
+ date="2015-10-26T17:36:26Z"
+ content="""
+@craig, this can be slightly confusing, since `git-annex enableremote`
+uses the same name that you used when creating the remote in the first
+place, with `git-annex initremote`... which might be different than
+the name used for that remote in some repository or other, and from
+the description shown in `git annex into`.
+
+Since every remote listed by `git annex info` is apparently a regular git
+repo, not a special remote, with the exception of the glacier one, process
+of deduction suggests that the "gitannexpics" special remote is the same as
+the glacier one.
+
+I've made some changes now, so `git annex enableremote` will list the
+uuid and description, along with the name used by enableremote, and
+will accept any one of those things to specify which remote to enable.
+"""]]