Commit f10b7a28 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Add `--index-state` support to `cabal get`

With this `cabal get` gains the ability to

 a) unpack and update with the .cabal revision which was
    active at the given index-state, as well as

 b) allow to unpack the most recent package version
    (while satisfying imposed version constraints) as of
    the given index-state

The `--index-state` flag can be combined with `--pristine` if only b) is
desired.
parent 518cd397
...@@ -39,7 +39,7 @@ import Distribution.Client.Dependency ...@@ -39,7 +39,7 @@ import Distribution.Client.Dependency
import Distribution.Client.FetchUtils import Distribution.Client.FetchUtils
import qualified Distribution.Client.Tar as Tar (extractTarGzFile) import qualified Distribution.Client.Tar as Tar (extractTarGzFile)
import Distribution.Client.IndexUtils as IndexUtils import Distribution.Client.IndexUtils as IndexUtils
( getSourcePackages ) ( getSourcePackagesAtIndexState, IndexState(..) )
import Distribution.Client.Compat.Process import Distribution.Client.Compat.Process
( readProcessWithExitCode ) ( readProcessWithExitCode )
import Distribution.Compat.Exception import Distribution.Compat.Exception
...@@ -82,7 +82,10 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do ...@@ -82,7 +82,10 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do
unless useFork $ unless useFork $
mapM_ checkTarget userTargets mapM_ checkTarget userTargets
sourcePkgDb <- getSourcePackages verbosity repoCtxt let idxState = fromFlagOrDefault IndexStateHead $
getIndexState getFlags
sourcePkgDb <- getSourcePackagesAtIndexState verbosity repoCtxt idxState
pkgSpecifiers <- resolveUserTargets verbosity repoCtxt pkgSpecifiers <- resolveUserTargets verbosity repoCtxt
(fromFlag $ globalWorldFile globalFlags) (fromFlag $ globalWorldFile globalFlags)
......
...@@ -1013,6 +1013,7 @@ instance Semigroup ReportFlags where ...@@ -1013,6 +1013,7 @@ instance Semigroup ReportFlags where
data GetFlags = GetFlags { data GetFlags = GetFlags {
getDestDir :: Flag FilePath, getDestDir :: Flag FilePath,
getPristine :: Flag Bool, getPristine :: Flag Bool,
getIndexState :: Flag IndexState,
getSourceRepository :: Flag (Maybe RepoKind), getSourceRepository :: Flag (Maybe RepoKind),
getVerbosity :: Flag Verbosity getVerbosity :: Flag Verbosity
} deriving Generic } deriving Generic
...@@ -1021,6 +1022,7 @@ defaultGetFlags :: GetFlags ...@@ -1021,6 +1022,7 @@ defaultGetFlags :: GetFlags
defaultGetFlags = GetFlags { defaultGetFlags = GetFlags {
getDestDir = mempty, getDestDir = mempty,
getPristine = mempty, getPristine = mempty,
getIndexState = mempty,
getSourceRepository = mempty, getSourceRepository = mempty,
getVerbosity = toFlag normal getVerbosity = toFlag normal
} }
...@@ -1058,6 +1060,20 @@ getCommand = CommandUI { ...@@ -1058,6 +1060,20 @@ getCommand = CommandUI {
(Flag Nothing) (Flag Nothing)
(map (fmap show) . flagToList)) (map (fmap show) . flagToList))
, option [] ["index-state"]
("Use source package index state as it existed at a previous time. " ++
"Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps " ++
"(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD'). " ++
"This determines which package versions are available as well as " ++
".cabal file revision is selected (unless --pristine is used).")
getIndexState (\v flags -> flags { getIndexState = v })
(reqArg "STATE" (readP_to_E (const $ "index-state must be a " ++
"unix-timestamps (e.g. '@1474732068'), " ++
"a ISO8601 UTC timestamp " ++
"(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'")
(toFlag `fmap` parse))
(flagToList . fmap display))
, option [] ["pristine"] , option [] ["pristine"]
("Unpack the original pristine tarball, rather than updating the " ("Unpack the original pristine tarball, rather than updating the "
++ ".cabal file with the latest revision from the package archive.") ++ ".cabal file with the latest revision from the package archive.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment