Skip to content

Commit

Permalink
Merge pull request #6596 from phadej/indexstate-module
Browse files Browse the repository at this point in the history
Move IndexState to own module
  • Loading branch information
phadej authored Mar 21, 2020
2 parents f8ad7bb + defd59f commit c52fdf7
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 35 deletions.
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/CmdUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Distribution.Simple.Utils
import Distribution.Verbosity
( Verbosity, normal, lessVerbose )
import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.IndexUtils.IndexState
import Distribution.Client.IndexUtils
( updateRepoIndexCache, Index(..), writeIndexTimestamp
, currentIndexTimestamp, indexBaseName )
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/IndexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import qualified Codec.Archive.Tar as Tar
import qualified Codec.Archive.Tar.Entry as Tar
import qualified Codec.Archive.Tar.Index as Tar
import qualified Distribution.Client.Tar as Tar
import Distribution.Client.IndexUtils.IndexState
import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.Types
import Distribution.Verbosity
Expand Down
47 changes: 47 additions & 0 deletions cabal-install/Distribution/Client/IndexUtils/IndexState.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Client.IndexUtils.IndexUtils
-- Copyright : (c) 2016 Herbert Valerio Riedel
-- License : BSD3
--
-- Timestamp type used in package indexes
module Distribution.Client.IndexUtils.IndexState (
IndexState(..),
) where

import Distribution.Client.Compat.Prelude
import Distribution.Client.IndexUtils.Timestamp (Timestamp)

import Distribution.FieldGrammar.Described
import Distribution.Parsec (Parsec (..))
import Distribution.Pretty (Pretty (..))

import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as Disp

-- | Specification of the state of a specific repo package index
data IndexState = IndexStateHead -- ^ Use all available entries
| IndexStateTime !Timestamp -- ^ Use all entries that existed at
-- the specified time
deriving (Eq,Generic,Show)

instance Binary IndexState
instance Structured IndexState
instance NFData IndexState

instance Pretty IndexState where
pretty IndexStateHead = Disp.text "HEAD"
pretty (IndexStateTime ts) = pretty ts

instance Parsec IndexState where
parsec = parseHead <|> parseTime where
parseHead = IndexStateHead <$ P.string "HEAD"
parseTime = IndexStateTime <$> parsec

instance Described IndexState where
describe _ = REUnion
[ "HEAD"
, RENamed "timestamp" (describe (Proxy :: Proxy Timestamp))
]
30 changes: 0 additions & 30 deletions cabal-install/Distribution/Client/IndexUtils/Timestamp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module Distribution.Client.IndexUtils.Timestamp
, timestampToUTCTime
, utcTimeToTimestamp
, maximumTimestamp

, IndexState(..)
) where

import Distribution.Client.Compat.Prelude
Expand Down Expand Up @@ -278,31 +276,3 @@ instance Parsec Timestamp where
-- missing/unknown/invalid
nullTimestamp :: Timestamp
nullTimestamp = TS minBound

----------------------------------------------------------------------------
-- defined here for now to avoid import cycles

-- | Specification of the state of a specific repo package index
data IndexState = IndexStateHead -- ^ Use all available entries
| IndexStateTime !Timestamp -- ^ Use all entries that existed at
-- the specified time
deriving (Eq,Generic,Show)

instance Binary IndexState
instance Structured IndexState
instance NFData IndexState

instance Pretty IndexState where
pretty IndexStateHead = Disp.text "HEAD"
pretty (IndexStateTime ts) = pretty ts

instance Parsec IndexState where
parsec = parseHead <|> parseTime where
parseHead = IndexStateHead <$ P.string "HEAD"
parseTime = IndexStateTime <$> parsec

instance Described IndexState where
describe _ = REUnion
[ "HEAD"
, RENamed "timestamp" (describe (Proxy :: Proxy Timestamp))
]
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Distribution.Client.BuildReports.Types
( ReportLevel(..) )
import Distribution.Client.SourceRepo (SourceRepoList)

import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.IndexUtils.IndexState
( IndexState )

import Distribution.Client.CmdInstall.ClientInstallFlags
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import Distribution.Client.BuildReports.Types
( ReportLevel(..) )
import Distribution.Client.Dependency.Types
( PreSolver(..) )
import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.IndexUtils.IndexState
( IndexState(..) )
import qualified Distribution.Client.Init.Types as IT
( InitFlags(..), PackageType(..) )
Expand Down
1 change: 1 addition & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ executable cabal
Distribution.Client.HashValue
Distribution.Client.HttpUtils
Distribution.Client.IndexUtils
Distribution.Client.IndexUtils.IndexState
Distribution.Client.IndexUtils.Timestamp
Distribution.Client.Init
Distribution.Client.Init.Heuristics
Expand Down
1 change: 1 addition & 0 deletions cabal-install/cabal-install.cabal.pp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
Distribution.Client.HashValue
Distribution.Client.HttpUtils
Distribution.Client.IndexUtils
Distribution.Client.IndexUtils.IndexState
Distribution.Client.IndexUtils.Timestamp
Distribution.Client.Init
Distribution.Client.Init.Heuristics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import Distribution.Utils.NubList

import Distribution.Client.BuildReports.Types (ReportLevel (..))
import Distribution.Client.CmdInstall.ClientInstallFlags (InstallMethod)
import Distribution.Client.IndexUtils.Timestamp (IndexState (..), Timestamp, epochTimeToTimestamp)
import Distribution.Client.IndexUtils.IndexState (IndexState (..))
import Distribution.Client.IndexUtils.Timestamp (Timestamp, epochTimeToTimestamp)
import Distribution.Client.InstallSymlink (OverwritePolicy)
import Distribution.Client.Types (RepoName (..), WriteGhcEnvironmentFilesPolicy)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import Distribution.Pretty (prettyShow)

import qualified Distribution.Utils.CharSet as CS

import Distribution.Client.IndexUtils.Timestamp (IndexState, Timestamp)
import Distribution.Client.Types (RepoName)
import Distribution.Client.IndexUtils.IndexState (IndexState)
import Distribution.Client.IndexUtils.Timestamp (Timestamp)
import Distribution.Client.Types (RepoName)

import qualified RERE as RE
import qualified RERE.CharSet as RE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Distribution.Solver.Types.Settings
import Distribution.Client.BuildReports.Types
import Distribution.Client.CmdInstall.ClientInstallFlags
import Distribution.Client.Dependency.Types
import Distribution.Client.IndexUtils.IndexState
import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.InstallSymlink
import Distribution.Client.ProjectConfig.Types
Expand Down

0 comments on commit c52fdf7

Please sign in to comment.