pull up where we load a git-pulled branch into memory

This commit is contained in:
Mitchell Rosen 2024-05-08 11:57:58 -04:00
parent 0144c69e49
commit 6dcd616bcd
4 changed files with 16 additions and 35 deletions

View File

@ -114,8 +114,6 @@ module Unison.Codebase
)
where
import Control.Monad.Except (ExceptT (ExceptT), runExceptT)
import Control.Monad.Trans.Except (throwE)
import Data.Map qualified as Map
import Data.Set qualified as Set
import U.Codebase.Branch qualified as V2
@ -133,18 +131,12 @@ import Unison.Codebase.CodeLookup qualified as CL
import Unison.Codebase.Editor.Git (withStatus)
import Unison.Codebase.Editor.Git qualified as Git
import Unison.Codebase.Editor.RemoteRepo (ReadGitRemoteNamespace)
import Unison.Codebase.GitError qualified as GitError
import Unison.Codebase.Path
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.SqliteCodebase.Conversions qualified as Cv
import Unison.Codebase.SqliteCodebase.Operations qualified as SqliteCodebase.Operations
import Unison.Codebase.SyncMode (SyncMode)
import Unison.Codebase.Type
( Codebase (..),
GitError (GitCodebaseError),
PushGitBranchOpts (..),
SyncToDir,
)
import Unison.Codebase.Type (Codebase (..), GitError, PushGitBranchOpts (..), SyncToDir)
import Unison.CodebasePath (CodebasePath, getCodebaseDir)
import Unison.ConstructorReference (ConstructorReference, GConstructorReference (..))
import Unison.DataDeclaration (Decl)
@ -168,7 +160,6 @@ import Unison.Typechecker.TypeLookup (TypeLookup (TypeLookup))
import Unison.Typechecker.TypeLookup qualified as TL
import Unison.UnisonFile qualified as UF
import Unison.Util.Relation qualified as Rel
import Unison.Util.Timing (time)
import Unison.Var (Var)
import Unison.WatchKind qualified as WK
@ -499,23 +490,19 @@ importRemoteBranch ::
ReadGitRemoteNamespace ->
SyncMode ->
Preprocessing m ->
m (Either GitError (Branch m))
importRemoteBranch codebase ns mode preprocess = runExceptT $ do
branchHash <- ExceptT . viewRemoteBranch' codebase ns Git.RequireExistingBranch $ \(branch, cacheDir) -> do
withStatus "Importing downloaded files into local codebase..." $ do
m (Either GitError CausalHash)
importRemoteBranch codebase ns mode preprocess = do
viewRemoteBranch' codebase ns Git.RequireExistingBranch \(branch, cacheDir) ->
withStatus "Importing downloaded files into local codebase..." do
processedBranch <- preprocessOp branch
time "SyncFromDirectory" $ do
syncFromDirectory codebase cacheDir mode processedBranch
pure $ Branch.headHash processedBranch
time "load fresh local branch after sync" $ do
lift (getBranchForHash codebase branchHash) >>= \case
Nothing -> throwE . GitCodebaseError $ GitError.CouldntLoadSyncedBranch ns branchHash
Just result -> pure $ result
syncFromDirectory codebase cacheDir mode processedBranch
pure (Branch.headHash processedBranch)
where
preprocessOp :: Branch m -> m (Branch m)
preprocessOp = case preprocess of
Preprocessed f -> f
Unmodified -> pure
preprocessOp =
case preprocess of
Preprocessed f -> f
Unmodified -> pure
-- | Pull a git branch and view it from the cache, without syncing into the
-- local codebase.

View File

@ -2,7 +2,7 @@
module Unison.Codebase.GitError where
import Unison.Codebase.Editor.RemoteRepo (ReadGitRemoteNamespace, ReadGitRepo, WriteGitRepo)
import Unison.Codebase.Editor.RemoteRepo (ReadGitRepo, WriteGitRepo)
import Unison.Codebase.Path
import Unison.Codebase.ShortCausalHash (ShortCausalHash)
import Unison.Prelude
@ -32,6 +32,5 @@ data GitCodebaseError h
| RemoteNamespaceHashAmbiguous ReadGitRepo ShortCausalHash (Set h)
| CouldntLoadRootBranch ReadGitRepo h
| CouldntParseRemoteBranch ReadGitRepo String
| CouldntLoadSyncedBranch ReadGitRemoteNamespace h
| CouldntFindRemoteBranch ReadGitRepo Path
deriving (Show)

View File

@ -226,8 +226,10 @@ loadRemoteNamespaceIntoMemory syncMode pullMode remoteNamespace = do
let preprocess = case pullMode of
Input.PullWithHistory -> Unmodified
Input.PullWithoutHistory -> Preprocessed $ pure . Branch.discardHistory
Cli.ioE (Codebase.importRemoteBranch codebase repo syncMode preprocess) \err ->
Cli.returnEarly (Output.GitError err)
causalHash <-
liftIO (Codebase.importRemoteBranch codebase repo syncMode preprocess) & onLeftM \err ->
Cli.returnEarly (Output.GitError err)
liftIO (Codebase.expectBranchForHash codebase causalHash)
ReadShare'LooseCode repo -> loadShareLooseCodeIntoMemory repo
ReadShare'ProjectBranch remoteBranch -> do
projectBranchCausalHashJWT <- downloadShareProjectBranch (pullMode == Input.PullWithoutHistory) remoteBranch

View File

@ -1351,13 +1351,6 @@ notifyUser dir = \case
<> P.group ("(" <> P.text (Hash.toBase32HexText $ unCausalHash hash) <> ")")
<> "from the repository at"
<> prettyReadGitRepo repo
CouldntLoadSyncedBranch ns h ->
P.wrap $
"I just finished importing the branch"
<> P.red (P.shown h)
<> "from"
<> P.red (prettyReadRemoteNamespaceWith absurd (RemoteRepo.ReadRemoteNamespaceGit ns))
<> "but now I can't find it."
CouldntFindRemoteBranch repo path ->
P.wrap $
"I couldn't find the remote branch at"