Skip to content

Commit 5d9b31f

Browse files
authored
Merge pull request #3236 from commercialhaskell/unpack-by-hash
Unpack by hash
2 parents bc85681 + 8b0d087 commit 5d9b31f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ Other enhancements:
5757
* MinGW bin folder now is searched for dynamic libraries. See [#3126](https://github.com/commercialhaskell/stack/issues/3126)
5858
* When using Nix, nix-shell now depends always on git to prevent runtime errors
5959
while fetching metadata
60+
* The `stack unpack` command now accepts a form where an explicit
61+
Hackage revision hash is specified, e.g. `stack unpack
62+
foo-1.2.3@gitsha1:deadbeef`. Note that this should be considered
63+
_experimental_, Stack will likely move towards a different hash
64+
format in the future.
6065

6166
Bug fixes:
6267

src/Stack/Fetch.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import Data.Monoid
5959
import Data.Set (Set)
6060
import qualified Data.Set as Set
6161
import qualified Data.Text as T
62-
import Data.Text.Encoding (decodeUtf8)
62+
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
6363
import Data.Text.Metrics
6464
import Data.Typeable (Typeable)
6565
import Data.Word (Word64)
@@ -146,7 +146,7 @@ unpackPackages mMiniBuildPlan dest input = do
146146
([], x) -> return $ partitionEithers x
147147
(errs, _) -> throwM $ CouldNotParsePackageSelectors errs
148148
resolved <- resolvePackages mMiniBuildPlan
149-
(Map.fromList $ map (, Nothing) idents)
149+
(Map.fromList idents)
150150
(Set.fromList names)
151151
ToFetchResult toFetch alreadyUnpacked <- getToFetch (Just dest') resolved
152152
unless (Map.null alreadyUnpacked) $
@@ -165,8 +165,12 @@ unpackPackages mMiniBuildPlan dest input = do
165165
Right x -> Right $ Left x
166166
Left _ ->
167167
case parsePackageIdentifierFromString s of
168-
Left _ -> Left s
169-
Right x -> Right $ Right x
168+
Right x -> Right $ Right (x, Nothing)
169+
Left _ -> maybe (Left s) (Right . Right) $ do
170+
(identS, '@':revisionS) <- return $ break (== '@') s
171+
Right ident <- return $ parsePackageIdentifierFromString identS
172+
hash <- T.stripPrefix "gitsha1:" $ T.pack revisionS
173+
Just (ident, Just $ GitSHA1 $ encodeUtf8 hash)
170174

171175
-- | Ensure that all of the given package idents are unpacked into the build
172176
-- unpack directory, and return the paths to all of the subdirectories.

0 commit comments

Comments
 (0)