Adds pull.silent command and links it to existing output silencing mechanism so initial codebase download is less noisy

This commit is contained in:
rlmark 2021-09-27 15:55:20 -07:00
parent f45f62035f
commit 6e80e02665
8 changed files with 92 additions and 66 deletions

View File

@ -150,6 +150,7 @@ import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as Nel
import Unison.Codebase.Editor.AuthorInfo (AuthorInfo(..))
import qualified Unison.Hashing.V2.Convert as Hashing
import Unison.Codebase.Verbosity (Verbosity(..))
type F m i v = Free (Command m i v)
@ -429,7 +430,7 @@ loop = do
UpdateBuiltinsI -> "builtins.update"
MergeBuiltinsI -> "builtins.merge"
MergeIOBuiltinsI -> "builtins.mergeio"
PullRemoteBranchI orepo dest _syncMode ->
PullRemoteBranchI orepo dest _syncMode _ ->
(Text.pack . InputPattern.patternName
$ InputPatterns.patternFromInput input)
<> " "
@ -740,7 +741,7 @@ loop = do
if Branch.isEmpty srcb then branchNotFound src0
else do
let err = Just $ MergeAlreadyUpToDate src0 dest0
mergeBranchAndPropagateDefaultPatch mergeMode inputDescription err srcb (Just dest0) dest
mergeBranchAndPropagateDefaultPatch mergeMode inputDescription err srcb (Just dest0) dest
PreviewMergeLocalBranchI src0 dest0 -> do
let [src, dest] = resolveToAbsolute <$> [src0, dest0]
@ -1685,13 +1686,16 @@ loop = do
makePrintNamesFromLabeled' (Patch.labeledDependencies patch)
respond $ ListEdits patch ppe
PullRemoteBranchI mayRepo path syncMode -> unlessError do
PullRemoteBranchI mayRepo path syncMode verbosity -> unlessError do
ns <- maybe (writePathToRead <$> resolveConfiguredGitUrl Pull path) pure mayRepo
lift $ unlessGitError do
b <- importRemoteBranch ns syncMode
let msg = Just $ PullAlreadyUpToDate ns path
let destAbs = resolveToAbsolute path
lift $ mergeBranchAndPropagateDefaultPatch Branch.RegularMerge inputDescription msg b (Just path) destAbs
let controlPathPrintout = case verbosity of
Default -> Just path
Silent -> Nothing
lift $ mergeBranchAndPropagateDefaultPatch Branch.RegularMerge inputDescription msg b controlPathPrintout destAbs
PushRemoteBranchI mayRepo path syncMode -> do
let srcAbs = resolveToAbsolute path
@ -2206,20 +2210,19 @@ unlessError' f ma = unlessError $ withExceptT f ma
-- supply unchangedMessage if you want to display it if merge had no effect
mergeBranchAndPropagateDefaultPatch :: (Monad m, Var v) => Branch.MergeMode ->
InputDescription -> Maybe (Output v) -> Branch m -> Maybe Path.Path' -> Path.Absolute -> Action' m v ()
mergeBranchAndPropagateDefaultPatch mode inputDescription unchangedMessage srcb dest0 dest =
ifM (mergeBranch mode inputDescription srcb dest0 dest)
mergeBranchAndPropagateDefaultPatch mode inputDescription unchangedMessage srcb dest0 dest =
ifM (mergeBranch mode inputDescription srcb dest0 dest )
(loadPropagateDiffDefaultPatch inputDescription dest0 dest)
(for_ unchangedMessage respond)
where
mergeBranch :: (Monad m, Var v) =>
Branch.MergeMode -> InputDescription -> Branch m -> Maybe Path.Path' -> Path.Absolute -> Action' m v Bool
Branch.MergeMode -> InputDescription -> Branch m -> Maybe Path.Path' -> Path.Absolute -> Action' m v Bool
mergeBranch mode inputDescription srcb dest0 dest = unsafeTime "Merge Branch" $ do
destb <- getAt dest
merged <- eval $ Merge mode srcb destb
b <- updateAtM inputDescription dest (const $ pure merged)
for_ dest0 $ \dest0 ->
diffHelper (Branch.head destb) (Branch.head merged) >>=
respondNumbered . uncurry (ShowDiffAfterMerge dest0 dest)
for_ dest0 $ \dest0 -> diffHelper (Branch.head destb) (Branch.head merged) >>=
respondNumbered . uncurry (ShowDiffAfterMerge dest0 dest) -- rlm note
pure b
loadPropagateDiffDefaultPatch :: (Monad m, Var v) =>

View File

@ -21,6 +21,7 @@ import Unison.ShortHash (ShortHash)
import Unison.Codebase.ShortBranchHash (ShortBranchHash)
import qualified Unison.Codebase.ShortBranchHash as SBH
import Unison.Codebase.SyncMode ( SyncMode )
import Unison.Codebase.Verbosity
import Unison.Name ( Name )
import Unison.NameSegment ( NameSegment )
@ -52,7 +53,7 @@ data Input
| MergeLocalBranchI Path' Path' Branch.MergeMode
| PreviewMergeLocalBranchI Path' Path'
| DiffNamespaceI Path' Path' -- old new
| PullRemoteBranchI (Maybe ReadRemoteNamespace) Path' SyncMode
| PullRemoteBranchI (Maybe ReadRemoteNamespace) Path' SyncMode Verbosity
| PushRemoteBranchI (Maybe WriteRemotePath) Path' SyncMode
| CreatePullRequestI ReadRemoteNamespace ReadRemoteNamespace
| LoadPullRequestI ReadRemoteNamespace ReadRemoteNamespace Path'

View File

@ -78,7 +78,7 @@ data NumberedOutput v
| ShowDiffAfterDeleteDefinitions PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterDeleteBranch Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterModifyBranch Path.Path' Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterMerge Path.Path' Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterMerge Path.Path' Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann) -- rlm note
| ShowDiffAfterMergePropagate Path.Path' Path.Absolute Path.Path' PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterMergePreview Path.Path' Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterPull Path.Path' Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
@ -101,7 +101,7 @@ data Output v
| BadMainFunction String (Type v Ann) PPE.PrettyPrintEnv [Type v Ann]
| BranchEmpty (Either ShortBranchHash Path')
| BranchNotEmpty Path'
| LoadPullRequest ReadRemoteNamespace ReadRemoteNamespace Path' Path' Path' Path'
| LoadPullRequest ReadRemoteNamespace ReadRemoteNamespace Path' Path' Path' Path' -- rlm note
| CreatedNewBranch Path.Absolute
| BranchAlreadyExists Path'
| PatchAlreadyExists Path.Split'

View File

@ -0,0 +1,4 @@
module Unison.Codebase.Verbosity
where
data Verbosity = Default | Silent deriving (Eq, Show)

View File

@ -46,6 +46,8 @@ import qualified Unison.Codebase.Editor.UriParser as UriParser
import Unison.Codebase.Editor.RemoteRepo (ReadRemoteNamespace, WriteRemotePath, WriteRepo)
import qualified Unison.Codebase.Editor.RemoteRepo as RemoteRepo
import Data.Tuple.Extra (uncurry3)
import Unison.Codebase.Verbosity (Verbosity)
import qualified Unison.Codebase.Verbosity as Verbosity
showPatternHelp :: InputPattern -> P.Pretty CT.ColorText
showPatternHelp i = P.lines [
@ -709,49 +711,58 @@ resetRoot = InputPattern "reset-root" [] [(Required, pathArg)]
pure $ Input.ResetRootI src
_ -> Left (I.help resetRoot))
pull :: InputPattern
pull = InputPattern
"pull"
[]
[(Optional, gitUrlArg), (Optional, pathArg)]
(P.lines
[ P.wrap
"The `pull` command merges a remote namespace into a local namespace."
, ""
, P.wrapColumn2
[ ( "`pull remote local`"
, "merges the remote namespace `remote`"
<>"into the local namespace `local`."
)
, ( "`pull remote`"
, "merges the remote namespace `remote`"
<>"into the current namespace")
, ( "`pull`"
, "merges the remote namespace configured in `.unisonConfig`"
<> "with the key `GitUrl.ns` where `ns` is the current namespace,"
<> "into the current namespace")
]
, ""
, P.wrap "where `remote` is a git repository, optionally followed by `:`"
<> "and an absolute remote path, such as:"
, P.indentN 2 . P.lines $
[P.backticked "https://github.com/org/repo"
,P.backticked "https://github.com/org/repo:.some.remote.path"
]
]
)
(\case
[] ->
Right $ Input.PullRemoteBranchI Nothing Path.relativeEmpty' SyncMode.ShortCircuit
[url] -> do
ns <- parseUri "url" url
Right $ Input.PullRemoteBranchI (Just ns) Path.relativeEmpty' SyncMode.ShortCircuit
[url, path] -> do
ns <- parseUri "url" url
p <- first fromString $ Path.parsePath' path
Right $ Input.PullRemoteBranchI (Just ns) p SyncMode.ShortCircuit
_ -> Left (I.help pull)
)
pullSilent :: InputPattern
pullSilent =
pullImpl "pull.silent" Verbosity.Silent
pull :: InputPattern
pull = pullImpl "pull" Verbosity.Default
pullImpl :: [Char] -> Verbosity -> InputPattern
pullImpl name verbosity = self
where
self = InputPattern
name
[]
[(Optional, gitUrlArg), (Optional, pathArg)]
(P.lines
[ P.wrap
"The" <> makeExample' self <> "command merges a remote namespace into a local namespace."
, ""
, P.wrapColumn2
[ ( makeExample self ["remote", "local"]
, "merges the remote namespace `remote`"
<>"into the local namespace `local"
)
, ( makeExample self ["remote"]
, "merges the remote namespace `remote`"
<>"into the current namespace")
, ( makeExample' self
, "merges the remote namespace configured in `.unisonConfig`"
<> "with the key `GitUrl.ns` where `ns` is the current namespace,"
<> "into the current namespace")
]
, ""
, P.wrap "where `remote` is a git repository, optionally followed by `:`"
<> "and an absolute remote path, such as:"
, P.indentN 2 . P.lines $
[P.backticked "https://github.com/org/repo"
,P.backticked "https://github.com/org/repo:.some.remote.path"
]
]
)
(\case
[] ->
Right $ Input.PullRemoteBranchI Nothing Path.relativeEmpty' SyncMode.ShortCircuit verbosity
[url] -> do
ns <- parseUri "url" url
Right $ Input.PullRemoteBranchI (Just ns) Path.relativeEmpty' SyncMode.ShortCircuit verbosity
[url, path] -> do
ns <- parseUri "url" url
p <- first fromString $ Path.parsePath' path
Right $ Input.PullRemoteBranchI (Just ns) p SyncMode.ShortCircuit verbosity
_ -> Left (I.help pull)
)
pullExhaustive :: InputPattern
pullExhaustive = InputPattern
@ -768,14 +779,14 @@ pullExhaustive = InputPattern
)
(\case
[] ->
Right $ Input.PullRemoteBranchI Nothing Path.relativeEmpty' SyncMode.Complete
Right $ Input.PullRemoteBranchI Nothing Path.relativeEmpty' SyncMode.Complete Verbosity.Default
[url] -> do
ns <- parseUri "url" url
Right $ Input.PullRemoteBranchI (Just ns) Path.relativeEmpty' SyncMode.Complete
Right $ Input.PullRemoteBranchI (Just ns) Path.relativeEmpty' SyncMode.Complete Verbosity.Default
[url, path] -> do
ns <- parseUri "url" url
p <- first fromString $ Path.parsePath' path
Right $ Input.PullRemoteBranchI (Just ns) p SyncMode.Complete
Right $ Input.PullRemoteBranchI (Just ns) p SyncMode.Complete Verbosity.Default
_ -> Left (I.help pull)
)
@ -1399,6 +1410,7 @@ validInputs =
, names
, push
, pull
, pullSilent
, pushExhaustive
, pullExhaustive
, createPullRequest
@ -1552,6 +1564,9 @@ pathArg :: ArgumentType
pathArg = ArgumentType "namespace" $
pathCompletor exactComplete (Set.map Path.toText . Branch.deepPaths)
verbosityArg :: ArgumentType
verbosityArg = ArgumentType "verbosity" $ \q _ _ _ -> pure (exactComplete q ["default", "silent"])
newNameArg :: ArgumentType
newNameArg = ArgumentType "new-name" $
pathCompletor prefixIncomplete
@ -1577,10 +1592,10 @@ collectNothings f as = [ a | (Nothing, a) <- map f as `zip` as ]
patternFromInput :: Input -> InputPattern
patternFromInput = \case
Input.PushRemoteBranchI _ _ SyncMode.ShortCircuit -> push
Input.PushRemoteBranchI _ _ SyncMode.ShortCircuit -> push
Input.PushRemoteBranchI _ _ SyncMode.Complete -> pushExhaustive
Input.PullRemoteBranchI _ _ SyncMode.ShortCircuit -> pull
Input.PullRemoteBranchI _ _ SyncMode.Complete -> pushExhaustive
Input.PullRemoteBranchI _ _ SyncMode.ShortCircuit _ -> pull
Input.PullRemoteBranchI _ _ SyncMode.Complete _ -> pushExhaustive
_ -> error "todo: finish this function"
inputStringFromInput :: IsString s => Input -> P.Pretty s
@ -1589,7 +1604,7 @@ inputStringFromInput = \case
(P.string . I.patternName $ patternFromInput i)
<> (" " <> maybe mempty (P.text . uncurry RemoteRepo.printHead) rh)
<> " " <> P.shown p'
i@(Input.PullRemoteBranchI ns p' _) ->
i@(Input.PullRemoteBranchI ns p' _ _) ->
(P.string . I.patternName $ patternFromInput i)
<> (" " <> maybe mempty (P.text . uncurry3 RemoteRepo.printNamespace) ns)
<> " " <> P.shown p'

View File

@ -150,6 +150,7 @@ notifyNumbered o = case o of
, undoTip
]) (showDiffNamespace ShowNumbers ppe bAbs bAbs diff)
-- rlm note:
ShowDiffAfterModifyBranch b' _ _ (OBD.isEmpty -> True) ->
(P.wrap $ "Nothing changed in" <> prettyPath' b' <> ".", mempty)
ShowDiffAfterModifyBranch b' bAbs ppe diff ->
@ -159,11 +160,11 @@ notifyNumbered o = case o of
, p
, ""
, undoTip
]) (showDiffNamespace ShowNumbers ppe bAbs bAbs diff)
]) (showDiffNamespace ShowNumbers ppe bAbs bAbs diff) -- rlm note change
ShowDiffAfterMerge _ _ _ (OBD.isEmpty -> True) ->
(P.wrap $ "Nothing changed as a result of the merge.", mempty)
ShowDiffAfterMerge dest' destAbs ppe diffOutput ->
ShowDiffAfterMerge dest' destAbs ppe diffOutput -> -- rlm note: HERE silence
first (\p -> P.lines [
P.wrap $ "Here's what's changed in " <> prettyPath' dest' <> "after the merge:"
, ""

View File

@ -13,6 +13,7 @@ import Unison.Codebase.Editor.Input (Input (..), Event)
import Data.Sequence (singleton)
import Unison.NameSegment (NameSegment(NameSegment))
import Unison.Codebase.Editor.RemoteRepo (ReadRemoteNamespace)
import qualified Unison.Codebase.Verbosity as Verbosity
-- Should Welcome include whether or not the codebase was created just now?
@ -82,7 +83,7 @@ pullBase ns = do
seg = NameSegment "base"
rootPath = Path.Path { Path.toSeq = singleton seg }
abs = Path.Absolute {Path.unabsolute = rootPath}
PullRemoteBranchI (Just ns) (Path.Path' {Path.unPath' = Left abs}) SyncMode.Complete
PullRemoteBranchI (Just ns) (Path.Path' {Path.unPath' = Left abs}) SyncMode.Complete Verbosity.Silent
asciiartUnison :: P.Pretty P.ColorText
asciiartUnison =

View File

@ -81,6 +81,7 @@ library
Unison.Codebase.TranscriptParser
Unison.Codebase.Type
Unison.Codebase.TypeEdit
Unison.Codebase.Verbosity
Unison.Codebase.Watch
Unison.CodebasePath
Unison.CommandLine