info: Added --autoenable option

Use cases include using git-annex init --no-autoenable and then going back
and enabling the special remotes that have autoenable configured. As well
as just querying to remember which ones have it enabled.

It lists all special remotes that have autoenable=yes whether currently
enabled or not. And it can be used with --json.

I pondered making this "git-annex info autoenable", but that seemed wrong
because then if the use has a directory named "autoenable", it's unclear
what they are asking for. (Although "git-annex info remote" may be
similarly unclear.) Making it an option does mean that it can't be provided
via --batch though.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2022-06-01 14:20:38 -04:00
parent 0d50c90794
commit c59ea5b1ca
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 57 additions and 11 deletions

View file

@ -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

View file

@ -1,6 +1,7 @@
git-annex (10.20220526) UNRELEASED; urgency=medium
* init: Added --no-autoenable option.
* info: Added --autoenable option.
-- Joey Hess <id@joeyh.name> Wed, 01 Jun 2022 13:23:05 -0400

View file

@ -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

View file

@ -1,6 +1,6 @@
{- git-annex trust log
-
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
- Copyright 2010-2022 Joey Hess <id@joeyh.name>
-
- 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])

View file

@ -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