enableremote: List uuids and descriptions of remotes that can be enabled, and accept...
authorJoey Hess <joeyh@joeyh.name>
Mon, 26 Oct 2015 18:55:40 +0000 (14:55 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 26 Oct 2015 18:55:40 +0000 (14:55 -0400)
Annex/SpecialRemote.hs
Command/EnableRemote.hs
Command/Info.hs
Remote.hs
debian/changelog
doc/git-annex-enableremote.mdwn
doc/special_remotes/comment_26_606c1bee71a265f9df3a8cf50fce9a21._comment [new file with mode: 0644]

index 44bc666ce40b2e8f177a880cc73a23c6bf769ccf..3892eea2f23fc34ed8eb6eeb704a960794b6f6ff 100644 (file)
@@ -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
index 84216dd78dee11706647e1fecd949b16cdd8cac2..b3ba451c248f382c21650aab5081b1a41c8ad1cc 100644 (file)
@@ -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
index 25a537e8d843edd2d46fb3239e41cbac67d5afa6..d22c23c04f2f79b79b7b7e570d97448dab71c2f8 100644 (file)
@@ -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
index f24b2e9782055aa1dc213b38e63df18bc8c4f1c0..4f57af996eae1f060dbc0f1d38c840288917f07a 100644 (file)
--- 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 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 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 hereu (u, optval) = toJSObject $ catMaybes
+       jsonify hereu (u, optval) = toJSObject $ catMaybes
                [ Just ("uuid", toJSON $ fromUUID u)
-               , Just ("description", toJSON $ finddescription u)
+               , Just ("description", toJSON $ finddescription u)
                , Just ("here", toJSON $ hereu == u)
                , case (optfield, optval) of
                        (Just field, Just val) -> Just (field, showJSON val)
index 118df60c03e846d5f5161b60137116c534781670..4c6b3fd8a53b0f9b496cbc84b78e93bb6f7f094f 100644 (file)
@@ -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
 
index 3b543c969be6e4b2c083a44520a29c66f1a28109..8467247157dc00dd4709c625d889b9b2fe126de0 100644 (file)
@@ -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 (file)
index 0000000..28a35bd
--- /dev/null
@@ -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.
+"""]]