diff --git a/Annex/SpecialRemote.hs b/Annex/SpecialRemote.hs index 5e2a1c2325..d2dc146af9 100644 --- a/Annex/SpecialRemote.hs +++ b/Annex/SpecialRemote.hs @@ -63,7 +63,10 @@ newConfig name sameas fromuser m = case sameas of specialRemoteMap :: Annex (M.Map UUID RemoteName) specialRemoteMap = do m <- Logs.Remote.remoteConfigMap - return $ M.fromList $ mapMaybe go (M.toList m) + return $ specialRemoteNameMap m + +specialRemoteNameMap :: M.Map UUID RemoteConfig -> M.Map UUID RemoteName +specialRemoteNameMap = M.fromList . mapMaybe go . M.toList where go (u, c) = case lookupName c of Nothing -> Nothing @@ -85,14 +88,14 @@ findType config = maybe unspecified (specified . fromProposedAccepted) $ autoEnable :: Annex () autoEnable = do - remotemap <- M.filter configured <$> remoteConfigMap + m <- autoEnableable enabled <- getenabledremotes - forM_ (M.toList remotemap) $ \(cu, c) -> unless (cu `M.member` enabled) $ do + forM_ (M.toList m) $ \(cu, c) -> unless (cu `M.member` enabled) $ do let u = case findSameasUUID c of Just (Sameas u') -> u' Nothing -> cu case (lookupName c, findType c) of - (Just name, Right t) -> whenM (canenable u) $ do + (Just name, Right t) -> do showSideAction $ "Auto enabling special remote " ++ name dummycfg <- liftIO dummyRemoteGitConfig tryNonAsync (setup t (AutoEnable c) (Just u) Nothing c dummycfg) >>= \case @@ -102,13 +105,25 @@ autoEnable = do setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu) _ -> return () where - configured rc = fromMaybe False $ - trueFalseParser' . fromProposedAccepted - =<< M.lookup autoEnableField rc - canenable u = (/= DeadTrusted) <$> lookupTrust u getenabledremotes = M.fromList . map (\r -> (getcu r, r)) <$> remoteList getcu r = fromMaybe (Remote.uuid r) (remoteAnnexConfigUUID (Remote.gitconfig r)) + +autoEnableable :: Annex (M.Map UUID RemoteConfig) +autoEnableable = do + tm <- trustMap + (M.filterWithKey (notdead tm) . M.filter configured) + <$> remoteConfigMap + where + configured c = fromMaybe False $ + trueFalseParser' . fromProposedAccepted + =<< M.lookup autoEnableField c + notdead tm cu c = + let u = case findSameasUUID c of + Just (Sameas u') -> u' + Nothing -> cu + in lookupTrust' u tm /= DeadTrusted + diff --git a/CHANGELOG b/CHANGELOG index cda5007438..8e571fe8d9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ git-annex (10.20220526) UNRELEASED; urgency=medium * init: Added --no-autoenable option. + * info: Added --autoenable option. -- Joey Hess Wed, 01 Jun 2022 13:23:05 -0400 diff --git a/Command/Info.hs b/Command/Info.hs index 8a2583d17f..3658893b9b 100644 --- a/Command/Info.hs +++ b/Command/Info.hs @@ -22,6 +22,7 @@ import qualified Git import qualified Annex import qualified Remote import qualified Types.Remote as Remote +import qualified Annex.SpecialRemote as SpecialRemote import Utility.DataUnits import Utility.DiskFree import Annex.Content @@ -105,6 +106,7 @@ data InfoOptions = InfoOptions { infoFor :: CmdParams , bytesOption :: Bool , batchOption :: BatchMode + , autoenableOption :: Bool } optParser :: CmdParamsDesc -> Parser InfoOptions @@ -115,6 +117,10 @@ optParser desc = InfoOptions <> help "display file sizes in bytes" ) <*> parseBatchOption False + <*> switch + ( long "autoenable" + <> help "list special remotes that are configured to autoenable" + ) seek :: InfoOptions -> CommandSeek seek o = case batchOption o of @@ -124,7 +130,9 @@ seek o = case batchOption o of start :: InfoOptions -> [String] -> CommandStart start o [] = do - globalInfo o + if autoenableOption o + then autoenableInfo + else globalInfo o stop start o ps = do mapM_ (\p -> itemInfo o (SeekInput [p], p)) ps @@ -140,6 +148,19 @@ globalInfo o = do evalStateT (mapM_ showStat stats) (emptyStatInfo o) return True +autoenableInfo :: Annex () +autoenableInfo = showCustom "info" (SeekInput []) $ do + m <- SpecialRemote.specialRemoteNameMap + <$> SpecialRemote.autoEnableable + descm <- M.unionWith Remote.addName + <$> uuidDescMap + <*> pure (M.map toUUIDDesc m) + s <- Remote.prettyPrintUUIDsDescs + "autoenable special remotes" + descm (M.keys m) + showRaw (encodeBS s) + return True + itemInfo :: InfoOptions -> (SeekInput, String) -> Annex () itemInfo o (si, p) = ifM (isdir p) ( dirInfo o p si diff --git a/Logs/Trust.hs b/Logs/Trust.hs index 220ff54f06..f2066ba29e 100644 --- a/Logs/Trust.hs +++ b/Logs/Trust.hs @@ -1,6 +1,6 @@ {- git-annex trust log - - - Copyright 2010-2020 Joey Hess + - Copyright 2010-2022 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -14,6 +14,7 @@ module Logs.Trust ( trustPartition, trustExclude, lookupTrust, + lookupTrust', trustMapLoad, ) where @@ -37,7 +38,10 @@ trustGet level = M.keys . M.filter (== level) <$> trustMap {- Returns the TrustLevel of a given repo UUID. -} lookupTrust :: UUID -> Annex TrustLevel -lookupTrust u = (fromMaybe def . M.lookup u) <$> trustMap +lookupTrust u = lookupTrust' u <$> trustMap + +lookupTrust' :: UUID -> TrustMap -> TrustLevel +lookupTrust' u m = fromMaybe def $ M.lookup u m {- Partitions a list of UUIDs to those matching a TrustLevel and not. -} trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID]) diff --git a/doc/git-annex-info.mdwn b/doc/git-annex-info.mdwn index e6c9bcee57..a33ec1378a 100644 --- a/doc/git-annex-info.mdwn +++ b/doc/git-annex-info.mdwn @@ -45,6 +45,11 @@ for the local repository and all annexed content. Makes the `--batch` input be delimited by nulls instead of the usual newlines. +* `--autoenable` + + Display a list of special remotes that have been configured to + autoenable. + * matching options The [[git-annex-matching-options]](1) can be used to select what