summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-10-26 14:55:40 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-10-26 14:55:40 -0400
commit5de4482c1b52ead223bc380b45fcc421e25a80a4 (patch)
tree075091a3b866e28c906a3f7d44d20b2a4fcddd33
parent6580aa68ca335e66daab9a9c2b7f91ad6f9bd2cb (diff)
enableremote: List uuids and descriptions of remotes that can be enabled, and accept either the uuid or the description in leu if the name.
-rw-r--r--Annex/SpecialRemote.hs10
-rw-r--r--Command/EnableRemote.hs26
-rw-r--r--Command/Info.hs3
-rw-r--r--Remote.hs33
-rw-r--r--debian/changelog3
-rw-r--r--doc/git-annex-enableremote.mdwn5
-rw-r--r--doc/special_remotes/comment_26_606c1bee71a265f9df3a8cf50fce9a21._comment20
7 files changed, 75 insertions, 25 deletions
diff --git a/Annex/SpecialRemote.hs b/Annex/SpecialRemote.hs
index 44bc666ce..3892eea2f 100644
--- a/Annex/SpecialRemote.hs
+++ b/Annex/SpecialRemote.hs
@@ -42,10 +42,14 @@ findByName n = filter (matching . snd) . M.toList
| 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
diff --git a/Command/EnableRemote.hs b/Command/EnableRemote.hs
index 84216dd78..b3ba451c2 100644
--- a/Command/EnableRemote.hs
+++ b/Command/EnableRemote.hs
@@ -12,6 +12,8 @@ import Command
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
@@ -25,12 +27,19 @@ seek :: CmdParams -> CommandSeek
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)
@@ -39,11 +48,14 @@ start (name:ws) = go =<< Annex.SpecialRemote.findExisting name
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
diff --git a/Command/Info.hs b/Command/Info.hs
index 25a537e8d..d22c23c04 100644
--- a/Command/Info.hs
+++ b/Command/Info.hs
@@ -427,8 +427,9 @@ reposizes_stats = stat desc $ nojson $ 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
diff --git a/Remote.hs b/Remote.hs
index f24b2e978..4f57af996 100644
--- a/Remote.hs
+++ b/Remote.hs
@@ -25,6 +25,7 @@ module Remote (
remoteMap,
remoteMap',
uuidDescriptions,
+ addName,
byName,
byName',
byNameOrGroup,
@@ -32,6 +33,7 @@ module Remote (
byNameWithUUID,
byCost,
prettyPrintUUIDs,
+ prettyPrintUUIDsDescs,
prettyPrintUUIDsWith,
prettyListUUIDs,
prettyUUID,
@@ -168,34 +170,41 @@ nameToUUID' n = byName' n >>= go
_ -> 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"
@@ -203,9 +212,9 @@ prettyPrintUUIDsWith optfield desc uuids = do
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)
diff --git a/debian/changelog b/debian/changelog
index 118df60c0..4c6b3fd8a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,9 @@ git-annex (5.20151020) UNRELEASED; urgency=medium
* 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
diff --git a/doc/git-annex-enableremote.mdwn b/doc/git-annex-enableremote.mdwn
index 3b543c969..846724715 100644
--- a/doc/git-annex-enableremote.mdwn
+++ b/doc/git-annex-enableremote.mdwn
@@ -4,7 +4,7 @@ git-annex enableremote - enables use of an existing special remote
# SYNOPSIS
-git annex enableremote `name [param=value ...]`
+git annex enableremote `name|uuid|desc [param=value ...]`
# DESCRIPTION
@@ -15,7 +15,8 @@ originally created with the initremote command.
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=
diff --git a/doc/special_remotes/comment_26_606c1bee71a265f9df3a8cf50fce9a21._comment b/doc/special_remotes/comment_26_606c1bee71a265f9df3a8cf50fce9a21._comment
new file mode 100644
index 000000000..28a35bd9a
--- /dev/null
+++ b/doc/special_remotes/comment_26_606c1bee71a265f9df3a8cf50fce9a21._comment
@@ -0,0 +1,20 @@
+[[!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.
+"""]]