Skip to content

Commit 691eaa9

Browse files
committed
Add pull.v2 command
1 parent 211a713 commit 691eaa9

File tree

8 files changed

+30
-41
lines changed

8 files changed

+30
-41
lines changed

Diff for: unison-cli/package.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ library:
2020
- condition: "!os(windows)"
2121
dependencies: unix
2222
dependencies:
23+
- attoparsec
2324
- Diff
2425
- IntervalMap
2526
- ListLike

Diff for: unison-cli/src/Unison/Cli/DownloadUtils.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Unison.Cli.Monad (Cli)
1919
import Unison.Cli.Monad qualified as Cli
2020
import Unison.Cli.Share.Projects qualified as Share
2121
import Unison.Codebase.Editor.HandleInput.AuthLogin (ensureAuthenticatedWithCodeserver)
22+
import Unison.Codebase.Editor.Input (SyncVersion (..))
2223
import Unison.Codebase.Editor.Output qualified as Output
2324
import Unison.Codebase.Editor.RemoteRepo (ReadShareLooseCode, shareUserHandleToText)
2425
import Unison.Codebase.Editor.RemoteRepo qualified as RemoteRepo
@@ -36,8 +37,6 @@ import Unison.Sync.Common qualified as Sync.Common
3637
import Unison.Sync.Types qualified as Share
3738
import Unison.SyncV2.Types qualified as SyncV2
3839

39-
data SyncVersion = SyncV1 | SyncV2
40-
4140
-- | Download a project/branch from Share.
4241
downloadProjectBranchFromShare ::
4342
(HasCallStack) =>

Diff for: unison-cli/src/Unison/Codebase/Editor/HandleInput.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ loop e = do
687687
_ <- Cli.updateAtM description pp \destb ->
688688
liftIO (Branch.merge'' (Codebase.lca codebase) Branch.RegularMerge srcb destb)
689689
Cli.respond Success
690-
PullI sourceTarget pullMode -> handlePull sourceTarget pullMode
690+
PullI syncVersion sourceTarget pullMode -> handlePull syncVersion sourceTarget pullMode
691691
PushRemoteBranchI pushRemoteBranchInput -> handlePushRemoteBranch pushRemoteBranchInput
692692
SyncToFileI syncFileDest projectBranchName -> SyncV2.handleSyncToFile syncFileDest projectBranchName
693693
SyncFromFileI syncFileSrc projectBranchName -> do

Diff for: unison-cli/src/Unison/Codebase/Editor/HandleInput/Pull.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ import Unison.Prelude
4646
import Unison.Project (ProjectAndBranch (..), ProjectBranchNameOrLatestRelease (..), ProjectName)
4747
import Witch (unsafeFrom)
4848

49-
handlePull :: PullSourceTarget -> PullMode -> Cli ()
50-
handlePull unresolvedSourceAndTarget pullMode = do
49+
handlePull :: SyncVersion -> PullSourceTarget -> PullMode -> Cli ()
50+
handlePull syncVersion unresolvedSourceAndTarget pullMode = do
5151
let includeSquashed = case pullMode of
5252
Input.PullWithHistory -> Share.NoSquashedHead
5353
Input.PullWithoutHistory -> Share.IncludeSquashedHead
@@ -59,7 +59,7 @@ handlePull unresolvedSourceAndTarget pullMode = do
5959
ReadShare'LooseCode repo -> downloadLooseCodeFromShare repo & onLeftM (Cli.returnEarly . Output.ShareError)
6060
ReadShare'ProjectBranch remoteBranch ->
6161
downloadProjectBranchFromShare
62-
SyncV1
62+
syncVersion
6363
( case pullMode of
6464
Input.PullWithHistory -> Share.NoSquashedHead
6565
Input.PullWithoutHistory -> Share.IncludeSquashedHead

Diff for: unison-cli/src/Unison/Codebase/Editor/HandleInput/SyncV2.hs

+5-28
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ where
88

99
import Control.Lens
1010
import Control.Monad.Reader (MonadReader (..))
11+
import U.Codebase.HashTags (CausalHash)
1112
import U.Codebase.Sqlite.Queries qualified as Q
13+
import Unison.Cli.DownloadUtils (SyncVersion (..), downloadProjectBranchFromShare)
1214
import Unison.Cli.Monad (Cli)
1315
import Unison.Cli.Monad qualified as Cli
1416
import Unison.Cli.MonadUtils qualified as Cli
1517
import Unison.Cli.ProjectUtils qualified as Project
18+
import Unison.Cli.Share.Projects qualified as Projects
1619
import Unison.Codebase (CodebasePath)
1720
import Unison.Codebase qualified as Codebase
1821
import Unison.Codebase.Editor.Output qualified as Output
@@ -22,7 +25,6 @@ import Unison.Prelude
2225
import Unison.Project (ProjectAndBranch (..), ProjectBranchName, ProjectName)
2326
import Unison.Share.SyncV2 qualified as SyncV2
2427
import Unison.SyncV2.Types (BranchRef)
25-
import Unison.Cli.DownloadUtils (SyncVersion, downloadProjectBranchFromShare)
2628

2729
handleSyncToFile :: FilePath -> ProjectAndBranch (Maybe ProjectName) (Maybe ProjectBranchName) -> Cli ()
2830
handleSyncToFile destSyncFile branchToSync = do
@@ -72,30 +74,5 @@ handleSyncFromCodebase description srcCodebasePath srcBranch destBranch = do
7274
Right (Right (Left syncErr)) -> do
7375
Cli.respond (Output.SyncPullError syncErr)
7476

75-
handleSyncFromCodebase :: Text -> CodebasePath -> ProjectAndBranch ProjectName ProjectBranchName -> ProjectAndBranch (Maybe ProjectName) ProjectBranchName -> Cli ()
76-
handleSyncFromCodebase description srcCodebasePath srcBranch destBranch = do
77-
Cli.Env {codebase} <- ask
78-
pp <- Cli.getCurrentProjectPath
79-
projectBranch <- Project.resolveProjectBranchInProject (pp ^. #project) (over #branch Just destBranch)
80-
r <- liftIO $ Init.withOpenCodebase SqliteCodebase.init "sync-src" srcCodebasePath Init.DontLock (Init.MigrateAfterPrompt Init.Backup Init.Vacuum) \srcCodebase -> do
81-
Codebase.withConnection srcCodebase \srcConn -> do
82-
maySrcCausalHash <- Codebase.runTransaction srcCodebase $ do
83-
let ProjectAndBranch srcProjName srcBranchName = srcBranch
84-
runMaybeT do
85-
project <- MaybeT (Q.loadProjectByName srcProjName)
86-
branch <- MaybeT (Q.loadProjectBranchByName (project ^. #projectId) srcBranchName)
87-
lift $ Project.getProjectBranchCausalHash branch
88-
case maySrcCausalHash of
89-
Nothing -> pure $ Left (error "Todo proper error")
90-
Just srcCausalHash -> do
91-
let shouldValidate = True
92-
fmap (const srcCausalHash) <$> liftIO (SyncV2.syncFromCodebase shouldValidate srcConn codebase srcCausalHash)
93-
94-
case r of
95-
Left _err -> pure $ error "Todo proper error"
96-
Right (Left syncErr) -> Cli.respond (Output.SyncPullError syncErr)
97-
Right (Right causalHash) -> do
98-
Cli.setProjectBranchRootToCausalHash (projectBranch ^. #branch) description causalHash
99-
100-
handleSyncFromCodeserver :: SyncVersion -> Projects.IncludeSquashedHead -> Projects.RemoteProjectBranch -> Cli (Either Output.ShareError CausalHash)
101-
handleSyncFromCodeserver = downloadProjectBranchFromShare
77+
handleSyncFromCodeserver :: Projects.IncludeSquashedHead -> Projects.RemoteProjectBranch -> Cli (Either Output.ShareError CausalHash)
78+
handleSyncFromCodeserver = downloadProjectBranchFromShare SyncV2

Diff for: unison-cli/src/Unison/Codebase/Editor/Input.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Unison.Codebase.Editor.Input
2727
IsGlobal,
2828
DeleteOutput (..),
2929
DeleteTarget (..),
30+
SyncVersion (..),
3031
)
3132
where
3233

@@ -55,6 +56,9 @@ data Event
5556
= UnisonFileChanged SourceName Source
5657
deriving stock (Show)
5758

59+
data SyncVersion = SyncV1 | SyncV2
60+
deriving (Eq, Show)
61+
5862
type Source = Text -- "id x = x\nconst a b = a"
5963

6064
type SourceName = Text -- "foo.u" or "buffer 7"
@@ -124,7 +128,7 @@ data Input
124128
MergeLocalBranchI BranchRelativePath (Maybe BranchRelativePath) Branch.MergeMode
125129
| PreviewMergeLocalBranchI BranchRelativePath (Maybe BranchRelativePath)
126130
| DiffNamespaceI BranchId2 BranchId2 -- old new
127-
| PullI !PullSourceTarget !PullMode
131+
| PullI !SyncVersion !PullSourceTarget !PullMode
128132
| PushRemoteBranchI PushRemoteBranchInput
129133
| SyncToFileI FilePath (ProjectAndBranch (Maybe ProjectName) (Maybe ProjectBranchName))
130134
| SyncFromFileI FilePath UnresolvedProjectBranch

Diff for: unison-cli/src/Unison/CommandLine/InputPatterns.hs

+13-6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module Unison.CommandLine.InputPatterns
9292
projectSwitch,
9393
projectsInputPattern,
9494
pull,
95+
pullV2,
9596
pullWithoutHistory,
9697
push,
9798
pushCreate,
@@ -1783,7 +1784,11 @@ reset =
17831784

17841785
pull :: InputPattern
17851786
pull =
1786-
pullImpl "pull" [] Input.PullWithHistory ""
1787+
pullImpl "pull" [] Input.PullWithHistory "" Input.SyncV1
1788+
1789+
pullV2 :: InputPattern
1790+
pullV2 =
1791+
pullImpl "pull.v2" [] Input.PullWithHistory "" Input.SyncV2
17871792

17881793
pullWithoutHistory :: InputPattern
17891794
pullWithoutHistory =
@@ -1792,9 +1797,10 @@ pullWithoutHistory =
17921797
[]
17931798
Input.PullWithoutHistory
17941799
"without including the remote's history. This usually results in smaller codebase sizes."
1800+
Input.SyncV1
17951801

1796-
pullImpl :: String -> [String] -> Input.PullMode -> P.Pretty CT.ColorText -> InputPattern
1797-
pullImpl name aliases pullMode addendum = do
1802+
pullImpl :: String -> [String] -> Input.PullMode -> P.Pretty CT.ColorText -> Input.SyncVersion -> InputPattern
1803+
pullImpl name aliases pullMode addendum syncVersion = do
17981804
self
17991805
where
18001806
self =
@@ -1838,18 +1844,18 @@ pullImpl name aliases pullMode addendum = do
18381844
explainRemote Pull
18391845
],
18401846
parse = \case
1841-
[] -> pure $ Input.PullI Input.PullSourceTarget0 pullMode
1847+
[] -> pure $ Input.PullI syncVersion Input.PullSourceTarget0 pullMode
18421848
[sourceArg] -> do
18431849
source <- handlePullSourceArg sourceArg
1844-
pure (Input.PullI (Input.PullSourceTarget1 source) pullMode)
1850+
pure (Input.PullI syncVersion (Input.PullSourceTarget1 source) pullMode)
18451851
[sourceArg, targetArg] ->
18461852
-- You used to be able to pull into a path, so this arg parser is a little complicated, because
18471853
-- we want to provide helpful suggestions if you are doing a deprecated or invalid thing.
18481854
case ( handlePullSourceArg sourceArg,
18491855
handleMaybeProjectBranchArg targetArg,
18501856
handlePath'Arg targetArg
18511857
) of
1852-
(Right source, Right target, _) -> Right (Input.PullI (Input.PullSourceTarget2 source target) pullMode)
1858+
(Right source, Right target, _) -> Right (Input.PullI syncVersion (Input.PullSourceTarget2 source target) pullMode)
18531859
(Left err, _, _) -> Left err
18541860
-- Parsing as a path didn't work either; just show the branch parse error
18551861
(Right _, Left err, Left _) -> Left err
@@ -3795,6 +3801,7 @@ validInputs =
37953801
projectSwitch,
37963802
projectsInputPattern,
37973803
pull,
3804+
pullV2,
37983805
pullWithoutHistory,
37993806
push,
38003807
pushCreate,

Diff for: unison-cli/unison-cli.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ library
201201
, aeson-pretty
202202
, ansi-terminal
203203
, async
204+
, attoparsec
204205
, base
205206
, bytestring
206207
, cmark

0 commit comments

Comments
 (0)