Skip to content

Commit

Permalink
Merge pull request #4115 from hvr/pr/unpack-index-state
Browse files Browse the repository at this point in the history
Add `--index-state` support to `cabal get`
  • Loading branch information
23Skidoo committed Nov 16, 2016
2 parents 81ae5c2 + a3ed467 commit 07a2725
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Cabal/doc/developing-packages.rst
Expand Up @@ -2274,6 +2274,15 @@ The ``get`` command supports the following options:
Fork the package's source repository using the appropriate version
control system. The optional argument allows to choose a specific
repository kind.
``--index-state`` *[HEAD\|@<unix-timestamp>\|<iso8601-utc-timestamp>]*
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).
This determines which package versions are available as well as which
``.cabal`` file revision is selected (unless ``--pristine`` is used).
``--pristine``
Unpack the original pristine tarball, rather than updating the
``.cabal`` file with the latest revision from the package archive.

Custom setup scripts
--------------------
Expand Down
7 changes: 5 additions & 2 deletions cabal-install/Distribution/Client/Get.hs
Expand Up @@ -39,7 +39,7 @@ import Distribution.Client.Dependency
import Distribution.Client.FetchUtils
import qualified Distribution.Client.Tar as Tar (extractTarGzFile)
import Distribution.Client.IndexUtils as IndexUtils
( getSourcePackages )
( getSourcePackagesAtIndexState, IndexState(..) )
import Distribution.Client.Compat.Process
( readProcessWithExitCode )
import Distribution.Compat.Exception
Expand Down Expand Up @@ -82,7 +82,10 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do
unless useFork $
mapM_ checkTarget userTargets

sourcePkgDb <- getSourcePackages verbosity repoCtxt
let idxState = fromFlagOrDefault IndexStateHead $
getIndexState getFlags

sourcePkgDb <- getSourcePackagesAtIndexState verbosity repoCtxt idxState

pkgSpecifiers <- resolveUserTargets verbosity repoCtxt
(fromFlag $ globalWorldFile globalFlags)
Expand Down
16 changes: 16 additions & 0 deletions cabal-install/Distribution/Client/Setup.hs
Expand Up @@ -1013,6 +1013,7 @@ instance Semigroup ReportFlags where
data GetFlags = GetFlags {
getDestDir :: Flag FilePath,
getPristine :: Flag Bool,
getIndexState :: Flag IndexState,
getSourceRepository :: Flag (Maybe RepoKind),
getVerbosity :: Flag Verbosity
} deriving Generic
Expand All @@ -1021,6 +1022,7 @@ defaultGetFlags :: GetFlags
defaultGetFlags = GetFlags {
getDestDir = mempty,
getPristine = mempty,
getIndexState = mempty,
getSourceRepository = mempty,
getVerbosity = toFlag normal
}
Expand Down Expand Up @@ -1058,6 +1060,20 @@ getCommand = CommandUI {
(Flag Nothing)
(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"]
("Unpack the original pristine tarball, rather than updating the "
++ ".cabal file with the latest revision from the package archive.")
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/changelog
Expand Up @@ -24,6 +24,8 @@
'.../$pkgid.log' to '.../$compiler/$libname.log' (#3807).
* Added a new command, 'cabal reconfigure', which re-runs 'configure'
with the most recently used flags (#2214).
* Added add the '--index-state' flag for requesting a specific
version of the package index (#3893, #4115).
* Support for building Backpack packages. See
https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst
for more details.
Expand Down

0 comments on commit 07a2725

Please sign in to comment.