From 6fe6d673d2585039c3ea3e52a33a8f9d1d06c37f Mon Sep 17 00:00:00 2001 From: Chris Penner Date: Tue, 9 Jul 2024 14:45:11 -0700 Subject: [PATCH] Omit times from project reflogs --- .../Codebase/Editor/HandleInput/Reflogs.hs | 8 +++- .../src/Unison/Codebase/Editor/Output.hs | 5 ++- .../src/Unison/CommandLine/OutputMessages.hs | 15 +++++-- unison-src/transcripts/reflog.output.md | 44 +++++++++---------- unison-src/transcripts/reset.output.md | 12 ++--- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Reflogs.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Reflogs.hs index 23c0841d3..f2006dca7 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Reflogs.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Reflogs.hs @@ -6,6 +6,7 @@ module Unison.Codebase.Editor.HandleInput.Reflogs ) where +import Control.Monad.Reader import Data.Time (getCurrentTime) import U.Codebase.HashTags (CausalHash) import U.Codebase.Sqlite.Project (Project) @@ -52,5 +53,8 @@ reflogHelper getEntries = do if length entries == numEntriesToShow then Output.MoreEntriesThanShown else Output.AllEntriesShown - now <- liftIO getCurrentTime - Cli.respondNumbered $ Output.ShowProjectBranchReflog now moreEntriesToLoad entries + mayNow <- + asks Cli.isTranscriptTest >>= \case + True -> pure Nothing + False -> Just <$> liftIO getCurrentTime + Cli.respondNumbered $ Output.ShowProjectBranchReflog mayNow moreEntriesToLoad entries diff --git a/unison-cli/src/Unison/Codebase/Editor/Output.hs b/unison-cli/src/Unison/Codebase/Editor/Output.hs index 330a350a1..03c351993 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Output.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Output.hs @@ -154,7 +154,10 @@ data NumberedOutput PPE.PrettyPrintEnv -- PPE containing names for everything from the root namespace. ProjectPath -- The namespace we're checking dependencies for. (Map LabeledDependency (Set Name)) -- Mapping of external dependencies to their local dependents. - | ShowProjectBranchReflog UTCTime {- current time -} MoreEntriesThanShown [ProjectReflog.Entry Project ProjectBranch (CausalHash, SCH.ShortCausalHash)] + | ShowProjectBranchReflog + (Maybe UTCTime {- current time, omitted in transcript tests to be more deterministic -}) + MoreEntriesThanShown + [ProjectReflog.Entry Project ProjectBranch (CausalHash, SCH.ShortCausalHash)] data TodoOutput = TodoOutput { dependentsOfTodo :: !(Set TermReferenceId), diff --git a/unison-cli/src/Unison/CommandLine/OutputMessages.hs b/unison-cli/src/Unison/CommandLine/OutputMessages.hs index 95d58d926..3a05508c2 100644 --- a/unison-cli/src/Unison/CommandLine/OutputMessages.hs +++ b/unison-cli/src/Unison/CommandLine/OutputMessages.hs @@ -3389,19 +3389,19 @@ listDependentsOrDependencies ppe labelStart label lds types terms = c = P.syntaxToColor displayProjectBranchReflogEntries :: - UTCTime -> + Maybe UTCTime -> E.MoreEntriesThanShown -> [ProjectReflog.Entry Project ProjectBranch (CausalHash, ShortCausalHash)] -> (Pretty, NumberedArgs) displayProjectBranchReflogEntries _ _ [] = (P.warnCallout "The reflog is empty", mempty) -displayProjectBranchReflogEntries now _ entries = +displayProjectBranchReflogEntries mayNow _ entries = let (entryRows, numberedArgs) = foldMap renderEntry entries rendered = P.lines [ header, "", - P.numberedColumnNHeader ["Branch", "When", "Hash", "Description"] entryRows + P.numberedColumnNHeader (["Branch"] <> Monoid.whenM (isJust mayNow) ["When"] <> ["Hash", "Description"]) entryRows ] in (rendered, numberedArgs) where @@ -3416,7 +3416,14 @@ displayProjectBranchReflogEntries now _ entries = ] renderEntry :: ProjectReflog.Entry Project ProjectBranch (CausalHash, SCH.ShortCausalHash) -> ([[Pretty]], NumberedArgs) renderEntry ProjectReflog.Entry {time, project, branch, toRootCausalHash = (toCH, toSCH), reason} = - ([[prettyProjectAndBranchName $ ProjectAndBranch project.name branch.name, prettyHumanReadableTime now time, P.blue (prettySCH toSCH), P.text $ truncateReason reason]], [SA.Namespace toCH]) + ( [ [prettyProjectAndBranchName $ ProjectAndBranch project.name branch.name] + <> ( mayNow + & foldMap (\now -> [prettyHumanReadableTime now time]) + ) + <> [P.blue (prettySCH toSCH), P.text $ truncateReason reason] + ], + [SA.Namespace toCH] + ) truncateReason :: Text -> Text truncateReason txt = case Text.splitAt 60 txt of (short, "") -> short diff --git a/unison-src/transcripts/reflog.output.md b/unison-src/transcripts/reflog.output.md index 22e359c0f..05d59d0f2 100644 --- a/unison-src/transcripts/reflog.output.md +++ b/unison-src/transcripts/reflog.output.md @@ -81,11 +81,11 @@ scratch/main> reflog Tip: Use `diff.namespace 1 7` to compare between points in history. - Branch When Hash Description - 1. scratch/main now #6mdl5gruh5 add - 2. scratch/main now #3rqf1hbev7 add - 3. scratch/main now #ms9lggs2rg builtins.merge scratch/main:.lib.builtins - 4. scratch/main now #sg60bvjo91 Project Created + Branch Hash Description + 1. scratch/main #6mdl5gruh5 add + 2. scratch/main #3rqf1hbev7 add + 3. scratch/main #ms9lggs2rg builtins.merge scratch/main:.lib.builtins + 4. scratch/main #sg60bvjo91 Project Created ``` Should see reflog entries from the current project @@ -100,13 +100,13 @@ scratch/main> project.reflog Tip: Use `diff.namespace 1 7` to compare between points in history. - Branch When Hash Description - 1. scratch/other now #148flqs4b1 alias.term scratch/other:..y scratch/other:.z - 2. scratch/other now #6mdl5gruh5 Branch created from scratch/main - 3. scratch/main now #6mdl5gruh5 add - 4. scratch/main now #3rqf1hbev7 add - 5. scratch/main now #ms9lggs2rg builtins.merge scratch/main:.lib.builtins - 6. scratch/main now #sg60bvjo91 Project Created + Branch Hash Description + 1. scratch/other #148flqs4b1 alias.term scratch/other:..y scratch/other:.z + 2. scratch/other #6mdl5gruh5 Branch created from scratch/main + 3. scratch/main #6mdl5gruh5 add + 4. scratch/main #3rqf1hbev7 add + 5. scratch/main #ms9lggs2rg builtins.merge scratch/main:.lib.builtins + 6. scratch/main #sg60bvjo91 Project Created ``` Should see reflog entries from all projects @@ -121,15 +121,15 @@ scratch/main> reflog.global Tip: Use `diff.namespace 1 7` to compare between points in history. - Branch When Hash Description - 1. newproject/main now #2rjhs2vq43 alias.term newproject/main:.lib.builtins.Nat newproject/main... - 2. newproject/main now #ms9lggs2rg builtins.merge newproject/main:.lib.builtins - 3. newproject/main now #sg60bvjo91 Branch Created - 4. scratch/other now #148flqs4b1 alias.term scratch/other:..y scratch/other:.z - 5. scratch/other now #6mdl5gruh5 Branch created from scratch/main - 6. scratch/main now #6mdl5gruh5 add - 7. scratch/main now #3rqf1hbev7 add - 8. scratch/main now #ms9lggs2rg builtins.merge scratch/main:.lib.builtins - 9. scratch/main now #sg60bvjo91 Project Created + Branch Hash Description + 1. newproject/main #2rjhs2vq43 alias.term newproject/main:.lib.builtins.Nat newproject/main... + 2. newproject/main #ms9lggs2rg builtins.merge newproject/main:.lib.builtins + 3. newproject/main #sg60bvjo91 Branch Created + 4. scratch/other #148flqs4b1 alias.term scratch/other:..y scratch/other:.z + 5. scratch/other #6mdl5gruh5 Branch created from scratch/main + 6. scratch/main #6mdl5gruh5 add + 7. scratch/main #3rqf1hbev7 add + 8. scratch/main #ms9lggs2rg builtins.merge scratch/main:.lib.builtins + 9. scratch/main #sg60bvjo91 Project Created ``` diff --git a/unison-src/transcripts/reset.output.md b/unison-src/transcripts/reset.output.md index 7cfac62e4..c77269dea 100644 --- a/unison-src/transcripts/reset.output.md +++ b/unison-src/transcripts/reset.output.md @@ -83,12 +83,12 @@ scratch/main> reflog Tip: Use `diff.namespace 1 7` to compare between points in history. - Branch When Hash Description - 1. scratch/main now #ujvq6e87kp reset ujvq6e87kp4288eq3al9v5luctic0ocd7ug1fu0go5bicrr2vfnrb0... - 2. scratch/main now #5vq851j3hg update - 3. scratch/main now #ujvq6e87kp update - 4. scratch/main now #4bigcpnl7t builtins.merge - 5. scratch/main now #sg60bvjo91 Project Created + Branch Hash Description + 1. scratch/main #ujvq6e87kp reset ujvq6e87kp4288eq3al9v5luctic0ocd7ug1fu0go5bicrr2vfnrb0... + 2. scratch/main #5vq851j3hg update + 3. scratch/main #ujvq6e87kp update + 4. scratch/main #4bigcpnl7t builtins.merge + 5. scratch/main #sg60bvjo91 Project Created -- Reset the current branch to the first history element scratch/main> reset 2