Skip to content

Commit ad09964

Browse files
authored
Merge pull request #4886 from unisonweb/builtins.merge-in
add an optional destination path to `builtins.merge{,io}`
2 parents d93d442 + 0e28238 commit ad09964

27 files changed

+58
-64
lines changed

unison-cli/src/Unison/Codebase/Editor/HandleInput.hs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ loop e = do
967967
-- stepAt updateBuiltins
968968
-- checkTodo
969969

970-
MergeBuiltinsI -> do
970+
MergeBuiltinsI opath -> do
971971
Cli.Env {codebase} <- ask
972972
description <- inputDescription input
973973
-- these were added once, but maybe they've changed and need to be
@@ -983,10 +983,13 @@ loop e = do
983983
-- due to builtin terms; so we don't just reuse `uf` above.
984984
let srcb = BranchUtil.fromNames Builtin.names
985985
currentPath <- Cli.getCurrentPath
986-
_ <- Cli.updateAtM description (currentPath `snoc` "builtin") \destb ->
986+
let destPath = case opath of
987+
Just path -> Path.resolve currentPath (Path.Relative path)
988+
Nothing -> currentPath `snoc` "builtin"
989+
_ <- Cli.updateAtM description destPath \destb ->
987990
liftIO (Branch.merge'' (Codebase.lca codebase) Branch.RegularMerge srcb destb)
988991
Cli.respond Success
989-
MergeIOBuiltinsI -> do
992+
MergeIOBuiltinsI opath -> do
990993
Cli.Env {codebase} <- ask
991994
description <- inputDescription input
992995
-- these were added once, but maybe they've changed and need to be
@@ -1007,7 +1010,10 @@ loop e = do
10071010
let names0 = Builtin.names <> UF.typecheckedToNames IOSource.typecheckedFile'
10081011
let srcb = BranchUtil.fromNames names0
10091012
currentPath <- Cli.getCurrentPath
1010-
_ <- Cli.updateAtM description (currentPath `snoc` "builtin") \destb ->
1013+
let destPath = case opath of
1014+
Just path -> Path.resolve currentPath (Path.Relative path)
1015+
Nothing -> currentPath `snoc` "builtin"
1016+
_ <- Cli.updateAtM description destPath \destb ->
10111017
liftIO (Branch.merge'' (Codebase.lca codebase) Branch.RegularMerge srcb destb)
10121018
Cli.respond Success
10131019
ListEditsI maybePath -> do
@@ -1305,8 +1311,10 @@ inputDescription input =
13051311
IOTestI hq -> pure ("io.test " <> HQ.toText hq)
13061312
IOTestAllI -> pure "io.test.all"
13071313
UpdateBuiltinsI -> pure "builtins.update"
1308-
MergeBuiltinsI -> pure "builtins.merge"
1309-
MergeIOBuiltinsI -> pure "builtins.mergeio"
1314+
MergeBuiltinsI Nothing -> pure "builtins.merge"
1315+
MergeBuiltinsI (Just path) -> ("builtins.merge " <>) <$> p path
1316+
MergeIOBuiltinsI Nothing -> pure "builtins.mergeio"
1317+
MergeIOBuiltinsI (Just path) -> ("builtins.mergeio " <>) <$> p path
13101318
MakeStandaloneI out nm -> pure ("compile " <> Text.pack out <> " " <> HQ.toText nm)
13111319
ExecuteSchemeI nm args ->
13121320
pure $ "run.native " <> Text.unwords (nm : fmap Text.pack args)
@@ -1395,6 +1403,8 @@ inputDescription input =
13951403
where
13961404
hp' :: Either SCH.ShortCausalHash Path' -> Cli Text
13971405
hp' = either (pure . Text.pack . show) p'
1406+
p :: Path -> Cli Text
1407+
p = fmap tShow . Cli.resolvePath
13981408
p' :: Path' -> Cli Text
13991409
p' = fmap tShow . Cli.resolvePath'
14001410
brp :: BranchRelativePath -> Cli Text

unison-cli/src/Unison/Codebase/Editor/Input.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ data Input
202202
| ShowDefinitionByPrefixI OutputLocation [HQ.HashQualified Name]
203203
| ShowReflogI
204204
| UpdateBuiltinsI
205-
| MergeBuiltinsI
206-
| MergeIOBuiltinsI
205+
| MergeBuiltinsI (Maybe Path)
206+
| MergeIOBuiltinsI (Maybe Path)
207207
| ListDependenciesI (HQ.HashQualified Name)
208208
| ListDependentsI (HQ.HashQualified Name)
209209
| -- | List all external dependencies of a given namespace, or the current namespace if

unison-cli/src/Unison/CommandLine/InputPatterns.hs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,29 @@ mergeBuiltins =
105105
"builtins.merge"
106106
[]
107107
I.Hidden
108-
[]
109-
"Adds the builtins to `builtins.` in the current namespace (excluding `io` and misc)."
110-
(const . pure $ Input.MergeBuiltinsI)
108+
[("namespace", Optional, namespaceArg)]
109+
"Adds the builtins (excluding `io` and misc) to the specified namespace. Defaults to `builtin.`"
110+
\case
111+
[] -> pure . Input.MergeBuiltinsI $ Nothing
112+
[p] -> first P.text do
113+
p <- Path.parsePath p
114+
pure . Input.MergeBuiltinsI $ Just p
115+
_ -> Left (I.help mergeBuiltins)
111116

112117
mergeIOBuiltins :: InputPattern
113118
mergeIOBuiltins =
114119
InputPattern
115120
"builtins.mergeio"
116121
[]
117122
I.Hidden
118-
[]
119-
"Adds all the builtins to `builtins.` in the current namespace, including `io` and misc."
120-
(const . pure $ Input.MergeIOBuiltinsI)
123+
[("namespace", Optional, namespaceArg)]
124+
"Adds all the builtins, including `io` and misc., to the specified namespace. Defaults to `builtin.`"
125+
\case
126+
[] -> pure . Input.MergeIOBuiltinsI $ Nothing
127+
[p] -> first P.text do
128+
p <- Path.parsePath p
129+
pure . Input.MergeIOBuiltinsI $ Just p
130+
_ -> Left (I.help mergeBuiltins)
121131

122132
updateBuiltins :: InputPattern
123133
updateBuiltins =

unison-src/transcripts/dont-upgrade-refs-that-exist-in-old.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ If `foo#old` exists in old, and `foo#new` exists in new, you might think `upgrad
33

44
```ucm:hide
55
.> project.create-empty foo
6-
foo/main> builtins.merge
7-
foo/main> move.namespace builtin lib.builtin
6+
foo/main> builtins.merge lib.builtin
87
```
98

109
```unison

unison-src/transcripts/edit-namespace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```ucm:hide
2-
.lib> builtins.mergeio
2+
.> builtins.mergeio lib.builtin
33
```
44

55
```unison:hide

unison-src/transcripts/update-suffixifies-properly.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
```ucm:hide
22
.> project.create-empty myproject
3-
myproject/main> builtins.merge
4-
myproject/main> move.namespace builtin lib.builtin
3+
myproject/main> builtins.merge lib.builtin
54
```
65

76
```unison

unison-src/transcripts/update-type-add-constructor.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
```ucm:hide
2-
.> builtins.merge
3-
.> move.namespace builtin lib.builtin
2+
.> builtins.merge lib.builtin
43
```
54

65
```unison

unison-src/transcripts/update-type-add-field.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
```ucm:hide
2-
.> builtins.merge
3-
.> move.namespace builtin lib.builtin
2+
.> builtins.merge lib.builtin
43
```
54

65
```unison

unison-src/transcripts/update-type-add-record-field.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
```ucm:hide
2-
.> builtins.merge
3-
.> move.namespace builtin lib.builtin
2+
.> builtins.merge lib.builtin
43
```
54

65
```unison

unison-src/transcripts/update-type-constructor-alias.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
```ucm:hide
2-
.> builtins.merge
3-
.> move.namespace builtin lib.builtin
2+
.> builtins.merge lib.builtin
43
```
54

65
```unison

0 commit comments

Comments
 (0)