Improve the "Try making some of these repositories available" message
authorJoey Hess <joeyh@joeyh.name>
Tue, 22 Sep 2020 18:10:30 +0000 (14:10 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 22 Sep 2020 18:10:30 +0000 (14:10 -0400)
With some hints for the user for what to do.

Took care to avoid changing the json output. It would have been ok to add
the new separated lists to it, in addition to the old list, but I didn't
do that because I didn't see much point.

CHANGELOG
Messages.hs
Remote.hs
doc/todo/make___34____Try_making_some_of_these_repositories_available__34___more_informative.mdwn

index 0c31e7fd8b2eefe27203d1f1634784f7a7414e3a..c9f7c20f9d931b5e89812d91b3b9e8ec134f48ef 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,6 +14,8 @@ git-annex (8.20200909) UNRELEASED; urgency=medium
   * add, addurl, importfeed, import: Added --no-check-gitignore option
     for finer grained control than using --force.
   * addunused: Don't check .gitignores when adding files.
+  * Improve the "Try making some of these repositories available"
+    message, with some hints for the user for what to do.
 
  -- Joey Hess <id@joeyh.name>  Mon, 14 Sep 2020 18:34:37 -0400
 
index 07b152c24ae1f4d69d078603e460d9daf0cf4f56..d3e63458ad16a3c0b0c80dc276c613ab2b151256 100644 (file)
@@ -45,6 +45,7 @@ module Messages (
        disableDebugOutput,
        debugEnabled,
        commandProgressDisabled,
+       jsonOutputEnabled,
        outputMessage,
        withMessageState,
        prompt,
@@ -288,6 +289,12 @@ commandProgressDisabled = withMessageState $ \s -> return $
                JSONOutput _ -> True
                NormalOutput -> concurrentOutputEnabled s
 
+jsonOutputEnabled :: Annex Bool
+jsonOutputEnabled = withMessageState $ \s -> return $
+       case outputType s of
+               JSONOutput _ -> True
+               _ -> False
+
 {- Prevents any concurrent console access while running an action, so
  - that the action is the only thing using the console, and can eg prompt
  - the user.
index b343fac47be83416fe2cac0a4b085fd5d9526ec0..1989f9382c1a38e2588bac638b7089a3e6eb9de6 100644 (file)
--- a/Remote.hs
+++ b/Remote.hs
@@ -1,6 +1,6 @@
 {- git-annex remotes
  -
- - Copyright 2011-2019 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2020 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -73,6 +73,7 @@ import Annex.UUID
 import Logs.UUID
 import Logs.Trust
 import Logs.Location hiding (logStatus)
+import Logs.Remote
 import Logs.Web
 import Remote.List
 import Remote.List.Util
@@ -337,31 +338,53 @@ remoteLocations locations trusted = do
 
        return (sortBy (comparing cost) validremotes, validtrustedlocations)
 
-{- Displays known locations of a key. -}
+{- Displays known locations of a key and helps the user take action
+ - to make them accessible. -}
 showLocations :: Bool -> Key -> [UUID] -> String -> Annex ()
 showLocations separateuntrusted key exclude nolocmsg = do
        u <- getUUID
+       remotes <- remoteList
        uuids <- keyLocations key
        untrusteduuids <- if separateuntrusted
                then trustGet UnTrusted
                else pure []
-       let uuidswanted = filteruuids uuids (u:exclude++untrusteduuids) 
+       let uuidswanted = filteruuids uuids (u:exclude++untrusteduuids)
        let uuidsskipped = filteruuids uuids (u:exclude++uuidswanted)
-       ppuuidswanted <- prettyPrintUUIDs "wanted" uuidswanted
-       ppuuidsskipped <- prettyPrintUUIDs "skipped" uuidsskipped
-       let msg = message ppuuidswanted ppuuidsskipped
-       unless (null msg) $
-               showLongNote msg
-       ignored <- remoteList
-               >>= filterM (liftIO . getDynamicConfig . remoteAnnexIgnore . gitconfig)
+       let remoteuuids = map uuid remotes
+       let isremoteuuid x = elem x remoteuuids
+       let (remotesmakeavailable, uuidsothers) = 
+               partition isremoteuuid uuidswanted
+       isspecialremote <- flip M.member <$> remoteConfigMap
+       let (enablespecialremotes, addgitremotes) = 
+               partition isspecialremote uuidsothers
+       
+       -- Add "wanted" field to the JSON. While it's since been split
+       -- up more, this avoids breaking any JSON parsers that expect it.
+       ifM jsonOutputEnabled
+               ( void $ prettyPrintUUIDs "wanted" uuidswanted
+               , do
+                       ppremotesmakeavailable <- pp "remotes" remotesmakeavailable
+                               "Try making some of these remotes available"
+                       ppenablespecialremotes <- pp "enableremote" enablespecialremotes
+                               "Maybe enable some of these special remotes (git annex initremote ...)"
+                       ppaddgitremotes <- pp "repos" addgitremotes
+                               "Maybe add some of these git remotes (git remote add ...)"
+                       ppuuidsskipped <- pp "skipped" uuidsskipped
+                               "Also these untrusted repositories may contain the file"
+                       showLongNote $ case ppremotesmakeavailable ++ ppenablespecialremotes ++ ppaddgitremotes ++ ppuuidsskipped of
+                               [] -> nolocmsg
+                               s -> s
+               )
+       ignored <- filterM (liftIO . getDynamicConfig . remoteAnnexIgnore . gitconfig) remotes
        unless (null ignored) $
                showLongNote $ "(Note that these git remotes have annex-ignore set: " ++ unwords (map name ignored) ++ ")"
   where
        filteruuids l x = filter (`notElem` x) l
-       message [] [] = nolocmsg
-       message rs [] = "Try making some of these repositories available:\n" ++ rs
-       message [] us = "Also these untrusted repositories may contain the file:\n" ++ us
-       message rs us = message rs [] ++ message [] us
+
+       pp jh l h = addheader h <$> prettyPrintUUIDs jh l
+
+       addheader _ [] = []
+       addheader h l = h ++ ":\n" ++ l
 
 showTriedRemotes :: [Remote] -> Annex ()
 showTriedRemotes [] = noop
index b92e91b16018e776318aa54053516e3aff94c260..2978049ab113b6bf1ba52e331cd0ac0f4e421e41 100644 (file)
@@ -29,5 +29,5 @@ although those remote descriptions/names give an idea for an informed user, they
 """]]
 
 [[!meta author=yoh]]
-[[!tag projects/dandi]]
-[[!tag needsthought]]
+
+> implemented as shown. [[done]] --[[Joey]]