partially switched over to new diff command

This commit is contained in:
Arya Irani 2020-01-13 22:44:35 -05:00
parent 8b9845891a
commit f9c21dfe33
3 changed files with 89 additions and 70 deletions

View File

@ -401,7 +401,8 @@ loop = do
let makeDeleteTypeNames = fmap (BranchUtil.makeDeleteTypeName resolvedPath) . toList $ tys
stepManyAt (makeDeleteTermNames ++ makeDeleteTypeNames)
root'' <- use root
respond $ ShowDiff input (Branch.namesDiff root' root'')
diffHelper (Branch.head root') (Branch.head root'') >>=
respondNumbered . uncurry ShowDiffAfterDelete
else do
failed <-
loadSearchResults $ SR.fromNames failed
@ -479,7 +480,8 @@ loop = do
merged <- eval . Eval $ Branch.merge srcb destb
b <- updateAtM dest $ const (pure merged)
if b then do
respond (ShowDiff input (Branch.namesDiff destb merged))
diffHelper (Branch.head destb) (Branch.head merged) >>=
respondNumbered . uncurry (ShowDiffAfterMerge dest)
patch <- getPatchAt defaultPatchPath
void $ propagatePatch inputDescription patch dest
else respond (NothingTodo input)
@ -492,25 +494,17 @@ loop = do
destb <- getAt dest
merged <- eval . Eval $ Branch.merge srcb destb
if merged == destb then respond (NothingTodo input)
else respond $ ShowDiff input (Branch.namesDiff destb merged)
else
diffHelper (Branch.head destb) (Branch.head merged) >>=
respondNumbered . uncurry (ShowDiffAfterMergePreview dest)
DiffNamespaceI before0 after0 -> do
let [beforep, afterp] =
Path.toAbsolutePath currentPath' <$> [before0, after0]
before <- Branch.head <$> getAt beforep
after <- Branch.head <$> getAt afterp
diff <- eval . Eval $ BranchDiff.diff0 before after
names0 <- basicPrettyPrintNames0
ppe <- PPE.suffixifiedPPE <$> prettyPrintEnvDecl (Names names0 mempty)
outputDiff <- OBranchDiff.toOutput
loadTypeOfTerm
declOrBuiltin
hqLength
(Branch.toNames0 before)
(Branch.toNames0 after)
ppe
diff
respondNumbered $ ShowDiffNamespace ppe beforep afterp outputDiff
(ppe, outputDiff) <- diffHelper before after
respondNumbered $ ShowDiffNamespace beforep afterp ppe outputDiff
-- move the root to a sub-branch
MoveBranchI Nothing dest -> do
@ -573,7 +567,7 @@ loop = do
(failed, failedDependents) <-
let rootNames = Branch.toNames0 root0
toDelete = Names.prefix0
(Path.toName . Path.unsplit . resolveSplit' $ p)
(Path.toName . Path.unsplit . resolveSplit' $ p) -- resolveSplit' incorporates currentPath
(Branch.toNames0 b)
in getEndangeredDependents (eval . GetDependents) toDelete rootNames
if failed == mempty then do
@ -632,7 +626,8 @@ loop = do
else CantUndoPastMerge
Just (_, prev) -> do
updateRoot root' prev inputDescription
respond $ ShowDiff input (Branch.namesDiff prev root')
diffHelper (Branch.head prev) (Branch.head root') >>=
respondNumbered . uncurry Output.ShowDiffAfterUndo
AliasTermI src dest -> case (toList (getHQ'Terms src), toList (getTerms dest)) of
([r], []) -> do
@ -1759,7 +1754,8 @@ loadRemoteBranchAt input inputDescription (repo, sbh, remotePath) p = do
where
doMerge b b0 = do
merged <- eval . Eval $ Branch.merge b b0
respond $ ShowDiff input (Branch.namesDiff b0 merged)
diffHelper (Branch.head b0) (Branch.head merged) >>=
respondNumbered . uncurry ShowDiffAfterPull
pure merged
syncRemoteRootBranch
@ -2400,6 +2396,25 @@ executePPE unisonFile =
(UF.termSignatureExternalLabeledDependencies unisonFile)
(UF.typecheckedToNames0 unisonFile)
diffHelper :: Monad m
=> Branch0 m
-> Branch0 m
-> Action' m v (PPE.PrettyPrintEnv, OBranchDiff.BranchDiffOutput v Ann)
diffHelper before after = do
hqLength <- eval CodebaseHashLength
diff <- eval . Eval $ BranchDiff.diff0 before after
names0 <- basicPrettyPrintNames0
ppe <- PPE.suffixifiedPPE <$> prettyPrintEnvDecl (Names names0 mempty)
(ppe,) <$>
OBranchDiff.toOutput
loadTypeOfTerm
declOrBuiltin
hqLength
(Branch.toNames0 before)
(Branch.toNames0 after)
ppe
diff
loadTypeOfTerm :: Referent -> Action m i v (Maybe (Type v Ann))
loadTypeOfTerm (Referent.Ref r) = eval $ LoadTypeOfTerm r
loadTypeOfTerm (Referent.Con (Reference.DerivedId r) cid _) = do

View File

@ -70,7 +70,14 @@ pushPull push pull p = case p of
Pull -> pull
data NumberedOutput v
= ShowDiffNamespace PPE.PrettyPrintEnv Path.Absolute Path.Absolute (BranchDiffOutput v Ann)
= ShowDiffNamespace Path.Absolute Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterDelete PPE.PrettyPrintEnv (BranchDiffOutput v Ann) -- path is Path.absoluteEmpty
| ShowDiffAfterMerge Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterMergePreview Path.Absolute PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterUndo PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
| ShowDiffAfterPull PPE.PrettyPrintEnv (BranchDiffOutput v Ann)
-- | ShowDiff
data Output v
-- Generic Success response; we might consider deleting this.
@ -157,7 +164,6 @@ data Output v
-- todo: eventually replace these sets with [SearchResult' v Ann]
-- and a nicer render.
| BustedBuiltins (Set Reference) (Set Reference)
| BranchDiff Names Names
| GitError Input GitError
| NoConfiguredGitUrl PushPull Path'
| ConfiguredGitUrlParseError PushPull Path' Text String
@ -171,7 +177,6 @@ data Output v
| PatchNeedsToBeConflictFree
| PatchInvolvesExternalDependents PPE.PrettyPrintEnv (Set Reference)
| WarnIncomingRootBranch (Set ShortBranchHash)
| ShowDiff Input Names.Diff
| History (Maybe Int) [(ShortBranchHash, Names.Diff)] HistoryTail
| ShowReflog [ReflogEntry]
| NothingTodo Input
@ -293,8 +298,6 @@ isFailure o = case o of
NothingToPatch{} -> False
WarnIncomingRootBranch{} -> False
History{} -> False
ShowDiff{} -> False
BranchDiff{} -> False
NotImplemented -> True
DumpNumberedArgs{} -> False
DumpBitBooster{} -> False

View File

@ -128,7 +128,7 @@ renderFileName dir = P.group . P.blue . fromString <$> shortenDirectory dir
notifyNumbered :: Var v => NumberedOutput v -> (Pretty, NumberedArgs)
notifyNumbered o = case o of
ShowDiffNamespace ppe oldPath rightPath diffOutput ->
ShowDiffNamespace oldPath rightPath ppe diffOutput ->
showDiffNamespace ppe oldPath rightPath diffOutput
notifyUser :: forall v . Var v => FilePath -> Output v -> IO Pretty
@ -672,7 +672,6 @@ notifyUser dir o = case o of
TermNotFound' _ h ->
pure $ "I could't find a term with hash "
<> (prettyShortHash $ Reference.toShortHash (Reference.DerivedId h))
BranchDiff _ _ -> pure "Those namespaces are different."
NothingToPatch _patchPath dest -> pure $
P.callout "😶" . P.wrap
$ "This had no effect. Perhaps the patch has already been applied"
@ -741,51 +740,7 @@ notifyUser dir o = case o of
]
ex = "Use" <> IP.makeExample IP.history ["#som3n4m3space"]
<> "to view history starting from a given namespace hash."
ShowDiff input diff -> pure $ case input of
Input.UndoI -> P.callout "" . P.lines $ [
"Here's the changes I undid:", "",
prettyDiff diff
]
Input.MergeLocalBranchI src dest -> P.callout "🆕" . P.lines $
[ P.wrap $
"Here's what's changed in " <> prettyPath' dest <> "after the merge:"
, ""
, prettyDiff diff
, ""
, tip "You can always `undo` if this wasn't what you wanted."
]
Input.PullRemoteBranchI _ dest ->
if Names.isEmptyDiff diff then
"✅ Looks like " <> prettyPath' dest <> " is up to date."
else P.callout "🆕" . P.lines $ [
P.wrap $ "Here's what's changed in " <> prettyPath' dest <> "after the pull:", "",
prettyDiff diff, "",
tip "You can always `undo` if this wasn't what you wanted." ]
Input.PreviewMergeLocalBranchI src dest ->
P.callout "🔎"
. P.lines
$ [ P.wrap
$ "Here's what would change in "
<> prettyPath' dest
<> "after the merge:"
, ""
, prettyDiff diff
]
Input.DeleteBranchI{} -> deleteDiff
Input.DeleteI{} -> deleteDiff
Input.DeleteTermI{} -> deleteDiff
Input.DeleteTypeI{} -> deleteDiff
_ -> prettyDiff diff
where
deleteDiff =
P.callout "🆕" . P.lines $
[ P.wrap $
"Here's what's changed after the delete:"
, ""
, prettyDiff diff
, ""
, tip "You can always `undo` if this wasn't what you wanted."
]
NothingTodo input -> pure . P.callout "😶" $ case input of
Input.MergeLocalBranchI src dest ->
P.wrap $ "The merge had no effect, since the destination"
@ -1208,6 +1163,52 @@ listOfLinks ppe results = pure $ P.lines [
prettyType Nothing = "❓ (missing a type for this definition)"
prettyType (Just t) = TypePrinter.pretty ppe t
-- ShowDiff input diff -> pure $ case input of
-- Input.UndoI -> P.callout "⏪" . P.lines $ [
-- "Here's the changes I undid:", "",
-- prettyDiff diff
-- ]
-- Input.MergeLocalBranchI src dest -> P.callout "🆕" . P.lines $
-- [ P.wrap $
-- "Here's what's changed in " <> prettyPath' dest <> "after the merge:"
-- , ""
-- , prettyDiff diff
-- , ""
-- , tip "You can always `undo` if this wasn't what you wanted."
-- ]
-- Input.PullRemoteBranchI _ dest ->
-- if Names.isEmptyDiff diff then
-- "✅ Looks like " <> prettyPath' dest <> " is up to date."
-- else P.callout "🆕" . P.lines $ [
-- P.wrap $ "Here's what's changed in " <> prettyPath' dest <> "after the pull:", "",
-- prettyDiff diff, "",
-- tip "You can always `undo` if this wasn't what you wanted." ]
-- Input.PreviewMergeLocalBranchI src dest ->
-- P.callout "🔎"
-- . P.lines
-- $ [ P.wrap
-- $ "Here's what would change in "
-- <> prettyPath' dest
-- <> "after the merge:"
-- , ""
-- , prettyDiff diff
-- ]
-- Input.DeleteBranchI{} -> deleteDiff
-- Input.DeleteI{} -> deleteDiff
-- Input.DeleteTermI{} -> deleteDiff
-- Input.DeleteTypeI{} -> deleteDiff
-- _ -> prettyDiff diff
-- where
-- deleteDiff =
-- P.callout "🆕" . P.lines $
-- [ P.wrap $
-- "Here's what's changed after the delete:"
-- , ""
-- , prettyDiff diff
-- , ""
-- , tip "You can always `undo` if this wasn't what you wanted."
-- ]
showDiffNamespace :: forall v . Var v
=> PPE.PrettyPrintEnv
-> Path.Absolute