@@ -12,7 +12,7 @@ import Distribution.Client.ProjectConfig
1212 ( ProjectConfig (.. )
1313 , projectConfigWithSolverRepoContext )
1414import Distribution.Client.Types
15- ( Repo (.. ), RemoteRepo (.. ), maybeRepoRemote )
15+ ( Repo (.. ), RemoteRepo (.. ), isRepoRemote )
1616import Distribution.Client.HttpUtils
1717 ( DownloadResult (.. ) )
1818import Distribution.Client.FetchUtils
@@ -25,17 +25,19 @@ import Distribution.Client.Setup
2525import Distribution.Simple.Setup
2626 ( HaddockFlags , fromFlagOrDefault , fromFlag )
2727import Distribution.Simple.Utils
28- ( die' , notice , wrapText , writeFileAtomic , noticeNoWrap )
28+ ( die' , notice , wrapText , writeFileAtomic , noticeNoWrap , intercalate )
2929import Distribution.Verbosity
3030 ( Verbosity , normal , lessVerbose )
3131import Distribution.Client.IndexUtils.Timestamp
3232import Distribution.Client.IndexUtils
3333 ( updateRepoIndexCache , Index (.. ), writeIndexTimestamp
3434 , currentIndexTimestamp )
3535import Distribution.Text
36- ( display )
36+ ( Text (.. ), display , simpleParse )
37+
38+ import qualified Distribution.Compat.ReadP as ReadP
39+ import qualified Text.PrettyPrint as Disp
3740
38- import Data.Maybe (mapMaybe )
3941import Control.Monad (unless , when )
4042import qualified Data.ByteString.Lazy as BS
4143import Distribution.Client.GZipUtils (maybeDecompress )
@@ -69,33 +71,66 @@ updateCommand = Client.installCommand {
6971 ++ " is very much appreciated.\n "
7072 }
7173
74+ data UpdateRequest = UpdateRequest
75+ { updateRequestRepoName :: String
76+ , updateRequestRepoState :: IndexState
77+ } deriving (Show )
78+
79+ instance Text UpdateRequest where
80+ disp (UpdateRequest n s) = Disp. text n Disp. <> Disp. char ' @' Disp. <> disp s
81+ parse = parseWithState ReadP. +++ parseHEAD
82+ where parseWithState = do
83+ name <- ReadP. many1 (ReadP. satisfy (\ c -> c /= ' @' ))
84+ _ <- ReadP. char ' @'
85+ state <- parse
86+ return (UpdateRequest name state)
87+ parseHEAD = do
88+ name <- ReadP. manyTill (ReadP. satisfy (\ c -> c /= ' @' )) ReadP. eof
89+ return (UpdateRequest name IndexStateHead )
90+
7291updateAction :: (ConfigFlags , ConfigExFlags , InstallFlags , HaddockFlags )
7392 -> [String ] -> GlobalFlags -> IO ()
7493updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
7594 extraArgs globalFlags = do
76- unless (null extraArgs) $
77- die' verbosity $ " 'update' doesn't take any extra arguments: " ++ unwords extraArgs
7895
7996 ProjectBaseContext {
8097 projectConfig
8198 } <- establishProjectBaseContext verbosity cliConfig
8299
83100 projectConfigWithSolverRepoContext verbosity (projectConfigShared projectConfig) (projectConfigBuildOnly projectConfig)
84101 $ \ repoCtxt -> do
85- let repos = repoContextRepos repoCtxt
86- remoteRepos = mapMaybe maybeRepoRemote repos
102+ let repos = filter isRepoRemote $ repoContextRepos repoCtxt
103+ repoName = remoteRepoName . repoRemote
104+ parseArg :: String -> IO UpdateRequest
105+ parseArg s = case simpleParse s of
106+ Just r -> pure r
107+ Nothing -> die' verbosity $ " 'new-update' unable to parse repo: \" " ++ s ++ " \" "
108+ updateRepoRequests <- mapM parseArg extraArgs
109+
110+ unless (null updateRepoRequests) $ do
111+ let remoteRepoNames = map repoName repos
112+ unknownRepos = [r | (UpdateRequest r _) <- updateRepoRequests
113+ , not (r `elem` remoteRepoNames)]
114+ unless (null unknownRepos) $
115+ die' verbosity $ " 'new-update' repo(s): \" " ++ intercalate " \" , \" " unknownRepos
116+ ++ " \" can not be found in known remote repo(s): " ++ intercalate " , " remoteRepoNames
117+
118+ let reposToUpdate = case updateRepoRequests of
119+ [] -> repos
120+ updateRequests -> let repoNames = map updateRequestRepoName updateRequests
121+ in filter (\ r-> repoName r `elem` repoNames) repos
87122
88- case remoteRepos of
123+ case reposToUpdate of
89124 [] -> return ()
90125 [remoteRepo] ->
91126 notice verbosity $ " Downloading the latest package list from "
92- ++ remoteRepoName remoteRepo
127+ ++ repoName remoteRepo
93128 _ -> notice verbosity . unlines
94129 $ " Downloading the latest package lists from: "
95- : map ((" - " ++ ) . remoteRepoName) remoteRepos
96- jobCtrl <- newParallelJobControl (length repos )
97- mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) repos
98- mapM_ (\ _ -> collectJob jobCtrl) repos
130+ : map ((" - " ++ ) . repoName) repos
131+ jobCtrl <- newParallelJobControl (length reposToUpdate )
132+ mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) reposToUpdate
133+ mapM_ (\ _ -> collectJob jobCtrl) reposToUpdate
99134
100135 where
101136 verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
@@ -140,4 +175,5 @@ updateRepo verbosity updateFlags repoCtxt repo = do
140175 when (current_ts /= nullTimestamp) $
141176 noticeNoWrap verbosity $
142177 " To revert to previous state run:\n " ++
143- " cabal update --index-state='" ++ display current_ts ++ " '\n "
178+ " cabal new-update '" ++ remoteRepoName (repoRemote repo) ++ " @" ++ display current_ts ++ " '\n "
179+
0 commit comments