<commit_before>{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module Stack.Freeze
    ( freeze
    , FreezeOpts (..)
    , FreezeMode (..)
    ) where

import qualified Data.Yaml as Yaml
import qualified RIO.ByteString as B
import           Stack.Prelude
import           Stack.Types.BuildPlan
import           Stack.Types.Config

data FreezeMode = FreezeProject | FreezeSnapshot

data FreezeOpts = FreezeOpts
    { freezeMode :: FreezeMode
    }

freeze :: HasEnvConfig env => FreezeOpts -> RIO env ()
freeze (FreezeOpts FreezeProject) = do
  mproject <- view $ configL.to configMaybeProject
  case mproject of
    Just (p, _) -> do
      let deps = projectDependencies p
          resolver = projectResolver p
          completePackageLocation' pl =
            case pl of
              PLImmutable pli -> PLImmutable <$> completePackageLocation pli
              plm@(PLMutable _) -> pure plm
      resolver' <- completeSnapshotLocation resolver
      deps' <- mapM completePackageLocation' deps
      when (deps' /= deps || resolver' /= resolver) $
        liftIO $ B.putStr $ Yaml.encode p{ projectDependencies = deps'
                                         , projectResolver = resolver'
                                         }
    Nothing -> pure ()

freeze (FreezeOpts FreezeSnapshot) = do
  msnapshot <- view $ buildConfigL.to bcSnapshotDef.to sdSnapshot
  case msnapshot of
    Just (snap, _) -> do
      snap' <- completeSnapshot snap
      when (snap' /= snap) $
        liftIO $ B.putStr $ Yaml.encode snap'
    Nothing ->
      return ()<commit_msg>More verbose and easy to understand output<commit_after>{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module Stack.Freeze
    ( freeze
    , FreezeOpts (..)
    , FreezeMode (..)
    ) where

import qualified Data.Yaml as Yaml
import qualified RIO.ByteString as B
import           Stack.Prelude
import           Stack.Types.BuildPlan
import           Stack.Types.Config

data FreezeMode = FreezeProject | FreezeSnapshot

data FreezeOpts = FreezeOpts
    { freezeMode :: FreezeMode
    }

freeze :: HasEnvConfig env => FreezeOpts -> RIO env ()
freeze (FreezeOpts FreezeProject) = do
  mproject <- view $ configL.to configMaybeProject
  case mproject of
    Just (p, _) -> do
      let deps = projectDependencies p
          resolver = projectResolver p
          completePackageLocation' pl =
            case pl of
              PLImmutable pli -> PLImmutable <$> completePackageLocation pli
              plm@(PLMutable _) -> pure plm
      resolver' <- completeSnapshotLocation resolver
      deps' <- mapM completePackageLocation' deps
      if deps' == deps && resolver' == resolver
      then
        logInfo "No freezing is required for this project"
      else
        liftIO $ B.putStr $ Yaml.encode p{ projectDependencies = deps'
                                         , projectResolver = resolver'
                                         }
    Nothing -> logWarn "No project was found: nothing to freeze"

freeze (FreezeOpts FreezeSnapshot) = do
  msnapshot <- view $ buildConfigL.to bcSnapshotDef.to sdSnapshot
  case msnapshot of
    Just (snap, _) -> do
      snap' <- completeSnapshot snap
      if snap' == snap
      then
        logInfo "No freezing is required for the snapshot of this project"
      else
        liftIO $ B.putStr $ Yaml.encode snap'
    Nothing ->
      logWarn "No snapshot was found: nothing to freeze"
{'fraction_non_alphanumeric': 0.08092485549132948, 'fraction_numerical': 0.0, 'mean_word_length': 2.195752539242844, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1262169', 'n_tokens_mistral': 980, 'n_tokens_neox': 978, 'n_words': 293}