3a05d53761
No behavior changes (hopefully), just adding SeekInput and plumbing it through to the JSON display code for later use. Over the course of 2 grueling days. withFilesNotInGit reimplemented in terms of seekHelper should be the only possible behavior change. It seems to test as behaving the same. Note that seekHelper dummies up the SeekInput in the case where segmentPaths' gives up on sorting the expanded paths because there are too many input paths. When SeekInput later gets exposed as a json field, that will result in it being a little bit wrong in the case where 100 or more paths are passed to a git-annex command. I think this is a subtle enough problem to not matter. If it does turn out to be a problem, fixing it would require splitting up the input parameters into groups of < 100, which would make git ls-files run perhaps more than is necessary. May want to revisit this, because that fix seems fairly low-impact.
82 lines
2.2 KiB
Haskell
82 lines
2.2 KiB
Haskell
{- git-annex command
|
|
-
|
|
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Command.Init where
|
|
|
|
import Command
|
|
import Annex.Init
|
|
import Annex.Version
|
|
import Types.RepoVersion
|
|
import qualified Annex.SpecialRemote
|
|
|
|
import Control.Monad.Fail as Fail (MonadFail(..))
|
|
import qualified Data.Map as M
|
|
|
|
cmd :: Command
|
|
cmd = dontCheck repoExists $
|
|
command "init" SectionSetup "initialize git-annex"
|
|
paramDesc (seek <$$> optParser)
|
|
|
|
data InitOptions = InitOptions
|
|
{ initDesc :: String
|
|
, initVersion :: Maybe RepoVersion
|
|
, autoEnableOnly :: Bool
|
|
}
|
|
|
|
optParser :: CmdParamsDesc -> Parser InitOptions
|
|
optParser desc = InitOptions
|
|
<$> (unwords <$> cmdParams desc)
|
|
<*> optional (option (str >>= parseRepoVersion)
|
|
( long "version" <> metavar paramValue
|
|
<> help "Override default annex.version"
|
|
))
|
|
<*> switch
|
|
( long "autoenable"
|
|
<> help "only enable special remotes configured with autoenable=true"
|
|
)
|
|
|
|
parseRepoVersion :: MonadFail m => String -> m RepoVersion
|
|
parseRepoVersion s = case RepoVersion <$> readish s of
|
|
Nothing -> Fail.fail $ "version parse error"
|
|
Just v
|
|
| v `elem` supportedVersions -> return v
|
|
| otherwise -> case M.lookup v autoUpgradeableVersions of
|
|
Just v' -> return v'
|
|
Nothing -> Fail.fail $ s ++ " is not a currently supported repository version"
|
|
|
|
seek :: InitOptions -> CommandSeek
|
|
seek = commandAction . start
|
|
|
|
start :: InitOptions -> CommandStart
|
|
start os
|
|
| autoEnableOnly os =
|
|
starting "init" (ActionItemOther (Just "autoenable")) si $
|
|
performAutoEnableOnly
|
|
| otherwise =
|
|
starting "init" (ActionItemOther (Just $ initDesc os)) si $
|
|
perform os
|
|
where
|
|
si = SeekInput []
|
|
|
|
perform :: InitOptions -> CommandPerform
|
|
perform os = do
|
|
case initVersion os of
|
|
Nothing -> noop
|
|
Just wantversion -> getVersion >>= \case
|
|
Just v | v /= wantversion ->
|
|
giveup $ "This repository is already a initialized with version " ++ show (fromRepoVersion v) ++ ", not changing to requested version."
|
|
_ -> noop
|
|
initialize
|
|
(if null (initDesc os) then Nothing else Just (initDesc os))
|
|
(initVersion os)
|
|
Annex.SpecialRemote.autoEnable
|
|
next $ return True
|
|
|
|
performAutoEnableOnly :: CommandPerform
|
|
performAutoEnableOnly = do
|
|
Annex.SpecialRemote.autoEnable
|
|
next $ return True
|