2013-04-26 22:22:44 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2020-02-19 17:58:26 +00:00
|
|
|
- Copyright 2013-2020 Joey Hess <id@joeyh.name>
|
2013-04-26 22:22:44 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-04-26 22:22:44 +00:00
|
|
|
-}
|
|
|
|
|
2019-12-05 15:40:10 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2013-04-26 22:22:44 +00:00
|
|
|
module Command.EnableRemote where
|
|
|
|
|
|
|
|
import Command
|
2016-05-24 19:24:38 +00:00
|
|
|
import qualified Annex
|
2013-04-26 22:22:44 +00:00
|
|
|
import qualified Logs.Remote
|
|
|
|
import qualified Types.Remote as R
|
2016-05-24 19:48:22 +00:00
|
|
|
import qualified Git
|
2016-11-30 18:35:24 +00:00
|
|
|
import qualified Git.Types as Git
|
2019-10-11 18:59:41 +00:00
|
|
|
import qualified Annex.SpecialRemote as SpecialRemote
|
2015-10-26 18:55:40 +00:00
|
|
|
import qualified Remote
|
2016-05-23 21:03:20 +00:00
|
|
|
import qualified Types.Remote as Remote
|
2016-05-24 19:24:38 +00:00
|
|
|
import qualified Remote.Git
|
2015-10-26 18:55:40 +00:00
|
|
|
import Logs.UUID
|
2016-05-24 19:24:38 +00:00
|
|
|
import Annex.UUID
|
2016-05-24 19:48:22 +00:00
|
|
|
import Config
|
2017-08-17 16:26:14 +00:00
|
|
|
import Config.DynamicConfig
|
|
|
|
import Types.GitConfig
|
2020-01-10 18:10:20 +00:00
|
|
|
import Types.ProposedAccepted
|
2020-02-19 17:58:26 +00:00
|
|
|
import Git.Config
|
2013-04-26 22:22:44 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd = command "enableremote" SectionSetup
|
2016-05-24 19:24:38 +00:00
|
|
|
"enables git-annex to use a remote"
|
2020-01-20 20:05:51 +00:00
|
|
|
(paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
|
2015-07-08 19:08:02 +00:00
|
|
|
(withParams seek)
|
2013-04-26 22:22:44 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withWords (commandAction . start)
|
2013-04-26 22:22:44 +00:00
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
2016-05-24 19:24:38 +00:00
|
|
|
start [] = unknownNameError "Specify the remote to enable."
|
2018-01-09 19:36:56 +00:00
|
|
|
start (name:rest) = go =<< filter matchingname <$> Annex.getGitRemotes
|
2013-04-26 22:22:44 +00:00
|
|
|
where
|
2016-05-24 19:24:38 +00:00
|
|
|
matchingname r = Git.remoteName r == Just name
|
2020-01-10 18:10:20 +00:00
|
|
|
go [] = startSpecialRemote name (Logs.Remote.keyValToConfig Proposed rest)
|
2019-10-11 18:59:41 +00:00
|
|
|
=<< SpecialRemote.findExisting name
|
2017-04-07 17:51:06 +00:00
|
|
|
go (r:_) = do
|
|
|
|
-- This could be either a normal git remote or a special
|
|
|
|
-- remote that has an url (eg gcrypt).
|
|
|
|
rs <- Remote.remoteList
|
|
|
|
case filter (\rmt -> Remote.name rmt == name) rs of
|
|
|
|
(rmt:_) | Remote.remotetype rmt == Remote.Git.remote ->
|
|
|
|
startNormalRemote name rest r
|
|
|
|
_ -> go []
|
2016-05-24 19:24:38 +00:00
|
|
|
|
2017-04-07 17:51:06 +00:00
|
|
|
-- Normal git remotes are special-cased; enableremote retries probing
|
|
|
|
-- the remote uuid.
|
|
|
|
startNormalRemote :: Git.RemoteName -> [String] -> Git.Repo -> CommandStart
|
|
|
|
startNormalRemote name restparams r
|
2020-09-14 20:49:33 +00:00
|
|
|
| null restparams = starting "enableremote" ai si $ do
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
setRemoteIgnore r False
|
|
|
|
r' <- Remote.Git.configRead False r
|
|
|
|
u <- getRepoUUID r'
|
|
|
|
next $ return $ u /= NoUUID
|
2017-04-07 17:51:06 +00:00
|
|
|
| otherwise = giveup $
|
|
|
|
"That is a normal git remote; passing these parameters does not make sense: " ++ unwords restparams
|
2020-09-14 20:49:33 +00:00
|
|
|
where
|
|
|
|
ai = ActionItemOther (Just name)
|
|
|
|
si = SeekInput [name]
|
2016-05-24 19:24:38 +00:00
|
|
|
|
2019-10-11 18:59:41 +00:00
|
|
|
startSpecialRemote :: Git.RemoteName -> Remote.RemoteConfig -> Maybe (UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID)) -> CommandStart
|
2016-05-24 19:24:38 +00:00
|
|
|
startSpecialRemote name config Nothing = do
|
2019-10-11 18:59:41 +00:00
|
|
|
m <- SpecialRemote.specialRemoteMap
|
2020-09-22 17:52:26 +00:00
|
|
|
confm <- Logs.Remote.remoteConfigMap
|
2017-12-05 19:00:50 +00:00
|
|
|
Remote.nameToUUID' name >>= \case
|
2016-05-24 19:24:38 +00:00
|
|
|
Right u | u `M.member` m ->
|
|
|
|
startSpecialRemote name config $
|
2019-10-11 18:59:41 +00:00
|
|
|
Just (u, fromMaybe M.empty (M.lookup u confm), Nothing)
|
2016-05-24 19:24:38 +00:00
|
|
|
_ -> unknownNameError "Unknown remote name."
|
2019-10-11 18:59:41 +00:00
|
|
|
startSpecialRemote name config (Just (u, c, mcu)) =
|
2020-09-14 20:49:33 +00:00
|
|
|
starting "enableremote" ai si $ do
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
let fullconfig = config `M.union` c
|
2019-10-11 18:59:41 +00:00
|
|
|
t <- either giveup return (SpecialRemote.findType fullconfig)
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
gc <- maybe (liftIO dummyRemoteGitConfig)
|
|
|
|
(return . Remote.gitconfig)
|
|
|
|
=<< Remote.byUUID u
|
2019-10-11 18:59:41 +00:00
|
|
|
performSpecialRemote t u c fullconfig gc mcu
|
2020-09-14 20:49:33 +00:00
|
|
|
where
|
|
|
|
ai = ActionItemOther (Just name)
|
|
|
|
si = SeekInput [name]
|
2016-05-24 19:24:38 +00:00
|
|
|
|
2019-10-11 18:59:41 +00:00
|
|
|
performSpecialRemote :: RemoteType -> UUID -> R.RemoteConfig -> R.RemoteConfig -> RemoteGitConfig -> Maybe (SpecialRemote.ConfigFrom UUID) -> CommandPerform
|
|
|
|
performSpecialRemote t u oldc c gc mcu = do
|
2017-09-04 16:40:33 +00:00
|
|
|
(c', u') <- R.setup t (R.Enable oldc) (Just u) Nothing c gc
|
2020-02-19 17:58:26 +00:00
|
|
|
next $ cleanupSpecialRemote t u' c' mcu
|
2016-05-24 19:24:38 +00:00
|
|
|
|
2020-02-19 17:58:26 +00:00
|
|
|
cleanupSpecialRemote :: RemoteType -> UUID -> R.RemoteConfig -> Maybe (SpecialRemote.ConfigFrom UUID) -> CommandCleanup
|
|
|
|
cleanupSpecialRemote t u c mcu = do
|
2019-10-11 18:59:41 +00:00
|
|
|
case mcu of
|
|
|
|
Nothing ->
|
|
|
|
Logs.Remote.configSet u c
|
|
|
|
Just (SpecialRemote.ConfigFrom cu) -> do
|
2020-02-19 17:45:11 +00:00
|
|
|
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
2019-10-11 18:59:41 +00:00
|
|
|
Logs.Remote.configSet cu c
|
2017-12-05 19:00:50 +00:00
|
|
|
Remote.byUUID u >>= \case
|
2016-05-24 19:48:22 +00:00
|
|
|
Nothing -> noop
|
2018-06-04 18:31:55 +00:00
|
|
|
Just r -> do
|
|
|
|
repo <- R.getRepo r
|
|
|
|
setRemoteIgnore repo False
|
2020-02-19 17:58:26 +00:00
|
|
|
unless (Remote.gitSyncableRemoteType t) $
|
|
|
|
setConfig (remoteConfig c "skipFetchAll") (boolConfig True)
|
2016-05-24 19:24:38 +00:00
|
|
|
return True
|
2013-04-26 22:22:44 +00:00
|
|
|
|
|
|
|
unknownNameError :: String -> Annex a
|
|
|
|
unknownNameError prefix = do
|
2019-10-11 18:59:41 +00:00
|
|
|
m <- SpecialRemote.specialRemoteMap
|
2019-01-01 19:39:45 +00:00
|
|
|
descm <- M.unionWith Remote.addName
|
|
|
|
<$> uuidDescMap
|
|
|
|
<*> pure (M.map toUUIDDesc m)
|
2016-05-24 19:24:38 +00:00
|
|
|
specialmsg <- if M.null m
|
2015-10-26 18:55:40 +00:00
|
|
|
then pure "(No special remotes are currently known; perhaps use initremote instead?)"
|
|
|
|
else Remote.prettyPrintUUIDsDescs
|
|
|
|
"known special remotes"
|
|
|
|
descm (M.keys m)
|
2018-01-09 19:36:56 +00:00
|
|
|
disabledremotes <- filterM isdisabled =<< Annex.getGitRemotes
|
2016-05-24 19:48:22 +00:00
|
|
|
let remotesmsg = unlines $ map ("\t" ++) $
|
|
|
|
mapMaybe Git.remoteName disabledremotes
|
2016-11-16 01:29:54 +00:00
|
|
|
giveup $ concat $ filter (not . null) [prefix ++ "\n", remotesmsg, specialmsg]
|
2016-05-24 19:48:22 +00:00
|
|
|
where
|
|
|
|
isdisabled r = anyM id
|
|
|
|
[ (==) NoUUID <$> getRepoUUID r
|
2017-08-17 16:26:14 +00:00
|
|
|
, liftIO . getDynamicConfig . remoteAnnexIgnore
|
|
|
|
=<< Annex.getRemoteGitConfig r
|
2016-05-24 19:48:22 +00:00
|
|
|
]
|