Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cabal update message #9521

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 47 additions & 19 deletions cabal-install/src/Distribution/Client/CmdUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Distribution.Client.HttpUtils
import Distribution.Client.IndexUtils
( Index (..)
, currentIndexTimestamp
, getIndexHeadTimestamp
, indexBaseName
, updatePackageIndexCacheFile
, updateRepoIndexCache
Expand Down Expand Up @@ -280,30 +281,57 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
setModificationTime (indexBaseName repo <.> "tar") now
`catchIO` \e ->
warn verbosity $ "Could not set modification time of index tarball -- " ++ displayException e
head_ts <- getIndexHeadTimestamp verbosity index
noticeNoWrap verbosity $
"Package list of " ++ prettyShow rname ++ " is up to date."
"The repository " ++ prettyShow rname ++ " is up to date. Its most recent known index-state is " ++ prettyShow head_ts ++ "."
noticeNoWrap verbosity $
"The default index-state for the repository "
++ prettyShow rname
++ " has been updated to "
++ prettyShow indexState
++ "."
-- This resolves indexState (which could be HEAD) into a timestamp.
-- This could be null but the above guarantees we have an updated index.
revertMessage index current_ts
Sec.HasUpdates -> do
updateRepoIndexCache verbosity index
noticeNoWrap verbosity $
"Package list of " ++ prettyShow rname ++ " has been updated."

-- This resolves indexState (which could be HEAD) into a timestamp
-- This could be null but should not be, since the above guarantees
-- we have an updated index.
head_ts <- getIndexHeadTimestamp verbosity index
-- This resolves indexState (which could be HEAD) into a timestamp
-- This could be null but should not be, since the above guarantees
-- we have an updated index.
new_ts <- currentIndexTimestamp (lessVerbose verbosity) index
if new_ts == head_ts
then
noticeNoWrap verbosity $
"The most recent known index-state and the default index-state timestamp for the repository "
++ prettyShow rname
++ " have both been updated to "
++ prettyShow (IndexStateTime new_ts)
++ "."
else do
noticeNoWrap verbosity $
"The most recent known index-state for the repository "
++ prettyShow rname
++ " has been updated to "
++ prettyShow head_ts
++ "."
noticeNoWrap verbosity $
"The default index-state for the repository "
++ prettyShow rname
++ " has been updated to "
++ prettyShow indexState
++ "."
revertMessage index current_ts
where
revertMessage index current_ts = do
-- This resolves indexState (which could be HEAD) into a timestamp.
-- This could be null if we have never run cabal update before.
new_ts <- currentIndexTimestamp (lessVerbose verbosity) index

noticeNoWrap verbosity $
"The index-state is set to " ++ prettyShow (IndexStateTime new_ts) ++ "."

-- TODO: This will print multiple times if there are multiple
-- repositories: main problem is we don't have a way of updating
-- a specific repo. Once we implement that, update this.

-- In case current_ts is a valid timestamp different from new_ts, let
-- the user know how to go back to current_ts
when (current_ts /= NoTimestamp && new_ts /= current_ts) $
noticeNoWrap verbosity $
"To revert to previous state run:\n"
++ " cabal v2-update '"
++ prettyShow (UpdateRequest rname (IndexStateTime current_ts))
++ "'\n"
unlines
[ "To revert to previous state run:"
, " cabal v2-update '" ++ prettyShow (UpdateRequest (repoName repo) (IndexStateTime current_ts)) ++ "'"
]
7 changes: 6 additions & 1 deletion cabal-install/src/Distribution/Client/IndexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Distribution.Client.IndexUtils
, updatePackageIndexCacheFile
, writeIndexTimestamp
, currentIndexTimestamp
, getIndexHeadTimestamp
, BuildTreeRefType (..)
, refTypeFromTypeCode
, typeCodeFromRefType
Expand Down Expand Up @@ -973,6 +974,10 @@ getIndexCache :: Verbosity -> Index -> RepoIndexState -> IO (Cache, IndexStateIn
getIndexCache verbosity index idxState =
filterCache idxState <$> readIndexCache verbosity index

getIndexHeadTimestamp :: Verbosity -> Index -> IO Timestamp
getIndexHeadTimestamp verbosity index =
cacheHeadTs <$> readIndexCache verbosity index

packageIndexFromCache
:: Package pkg
=> Verbosity
Expand Down Expand Up @@ -1189,7 +1194,7 @@ currentIndexTimestamp verbosity index = do
return ts
-- Otherwise used the head time as stored in the index cache
_otherwise ->
fmap (isiHeadTime . snd) (getIndexCache verbosity index IndexStateHead)
getIndexHeadTimestamp verbosity index
`catchIO` \e ->
if isDoesNotExistError e
then return NoTimestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ main = cabalTest $ withProjectFile "cabal.project" $ withRemoteRepo "repo" $ do
. resultOutput
<$> recordMode DoNotRecord (cabal' "update" [])
-- update golden output with actual timestamp
shell "cp" ["cabal.out.in", "cabal.out"]
shell "sed" ["-i''", "-e", "s/REPLACEME/" <> output <> "/g", "cabal.out"]
shell "sed" ["-e", "s/REPLACEME/" <> output <> "/g; w cabal.out", "cabal.out.in"]
-- This shall fail with an error message as specified in `cabal.out`
fails $ cabal "build" ["--index-state=4000-01-01T00:00:00Z", "fake-pkg"]
-- This shall fail by not finding the package, what indicates that it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# cabal update
Downloading the latest package list from repository.localhost
Package list of repository.localhost is up to date.
The index-state is set to 2016-09-24T17:47:48Z.
The repository repository.localhost is up to date. Its most recent known index-state is 2024-01-19T07:22:23Z.
The default index-state for the repository repository.localhost has been updated to 2016-09-24T17:47:48Z.
To revert to previous state run:
cabal v2-update 'repository.localhost,2022-01-28T02:36:41Z'
# cabal update
Downloading the latest package list from repository.localhost
Package list of repository.localhost is up to date.
The index-state is set to 2022-01-28T02:36:41Z.
The repository repository.localhost is up to date. Its most recent known index-state is 2024-01-19T07:22:23Z.
The default index-state for the repository repository.localhost has been updated to 2022-01-28T02:36:41Z.
To revert to previous state run:
cabal v2-update 'repository.localhost,2016-09-24T17:47:48Z'
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ main = cabalTest $ withRemoteRepo "repo" $ do
-- The _first_ update call causes a warning about missing mirrors, the warning
-- is platform-dependent and it's not part of the test expectations, so we
-- check the output manually.
res <- recordMode DoNotRecord $
cabal' "update" ["repository.localhost,2022-01-28T02:36:41Z"]
assertOutputContains "The index-state is set to 2022-01-28T02:36:41Z" res
res <-
recordMode DoNotRecord $
cabal' "update" ["repository.localhost,2022-01-28T02:36:41Z"]
assertOutputContains "The default index-state for the repository repository.localhost has been updated to" res
assertOutputDoesNotContain "revert" res
cabal "update" ["repository.localhost,2016-09-24T17:47:48Z"]
cabal "update" ["repository.localhost,2022-01-28T02:36:41Z"]
Loading