on master help sign in
set packed thunk without unpacking
commit1566ae34c6b77c0551a1c05f0a6c4db8522ba8db authorhsloan <ishaqsloan@gmail.com> dateThu 29 Nov 2018, 18:58 (8 years ago) parentfe4de3b
2 files changed+26−10
lib/command/src/Obelisk/Command/Thunk.hs+23−10 lib/command/src/Obelisk/Command/Utils.hs+3
lib/command/src/Obelisk/Command/Thunk.hs+23−10
@@ -30,7 +30,6 @@ module Obelisk.Command.Thunk
3030 , parseGitUri
3131 , uriThunkPtr
3232 , setThunk
33− , setThunk'
3433 ) where
3534
3635import Control.Applicative
@@ -625,10 +624,7 @@ packThunk' noTrail thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir
625624 pure thunkPtr
626625
627626setThunk :: MonadObelisk m => String -> FilePath -> m ()
628−setThunk = setThunk' False
629−
630−setThunk' :: MonadObelisk m => Bool -> String -> FilePath -> m ()
631−setThunk' noTrail branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
627+setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
632628 Left err -> failWith $ T.pack $ "thunk set : " <> show err
633629 Right (ThunkData_Packed thunkptr) -> do
634630 let thunkSrc = _thunkPtr_source thunkptr
@@ -639,11 +635,28 @@ setThunk' noTrail branch thunkDir = checkThunkDirectory thunkDir >> readThunk th
639635 (exitCode, _) <- gitLsRemoteExitCode repository branch
640636 case exitCode of
641637 ExitSuccess -> do
642− -- TODO: Accomplish this without unpacking
643− _ <- unpackThunk' noTrail thunkDir
644− callProcessAndLogOutput (Debug, Error) $ gitProc thunkDir ["checkout", branch]
645− _ <- packThunk' noTrail thunkDir
646− updateThunkToLatest thunkDir
638+ remoteResults <- readGitProcessNoRepo ["ls-remote", repository, branch]
639+ uri <- mkURI $ T.pack repository
640+ let rev = head $ T.words remoteResults -- TODO: Don't use head
641+ sha256 <- nixPrefetchGit uri rev False
642+ let newThunkPtr = ThunkPtr
643+ { _thunkPtr_source = case _thunkPtr_source thunkptr of
644+ ThunkSource_Git gitSource -> ThunkSource_Git GitSource
645+ { _gitSource_url = _gitSource_url gitSource
646+ , _gitSource_branch = Just $ N $ T.pack branch
647+ , _gitSource_fetchSubmodules = _gitSource_fetchSubmodules gitSource
648+ }
649+ ThunkSource_GitHub gitHubSource -> ThunkSource_GitHub GitHubSource
650+ { _gitHubSource_owner = _gitHubSource_owner gitHubSource
651+ , _gitHubSource_repo = _gitHubSource_repo gitHubSource
652+ , _gitHubSource_branch = Just $ N $ T.pack branch
653+ }
654+ , _thunkPtr_rev = ThunkRev
655+ { _thunkRev_commit = Ref.hash $ encodeUtf8 rev
656+ , _thunkRev_nixSha256 = sha256
657+ }
658+ }
659+ overwriteThunk thunkDir newThunkPtr
647660 ExitFailure errNum -> failWith $ T.pack $ if errNum == 2
648661 then "Error: branch not found"
649662 else ("Error Code: " <> show errNum <> "issue checking out the desired branch")
lib/command/src/Obelisk/Command/Utils.hs+3
@@ -79,6 +79,9 @@ copyDir src dest =
7979readGitProcess :: MonadObelisk m => FilePath -> [String] -> m Text
8080readGitProcess repo = readProcessAndLogOutput (Debug, Notice) . gitProc repo
8181
82+readGitProcessNoRepo :: MonadObelisk m => [String] -> m Text
83+readGitProcessNoRepo = readProcessAndLogOutput (Debug, Notice) . gitProcNoRepo
84+
8285processToShellString :: FilePath -> [String] -> String
8386processToShellString cmd args = unwords $ map quoteAndEscape (cmd : args)
8487 where quoteAndEscape x = T.unpack $ "'" <> T.replace "'" "'\''" (T.pack x) <> "'"