From 0a3c8a6790a581e85803dc836d70e9a238d955ad Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 26 Mar 2025 23:01:03 +0200 Subject: [PATCH] Remove project strong reference from git panel's log output editor (#27496) A readonly buffer built from a static `&str` output does not need rich project-based capabilities, and leaking projects in global git panel might be dangerous. Also adds readonly capability to the buffer, as `editor.set_read_only(true);` API is a separate thing. Release Notes: - N/A --- crates/git_ui/src/git_panel.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index a5804b91a8fd3704021c7be6da7e292a2dd251d4..833fc3b5f3c5947f3a3aad8f276f2b63e6266b5b 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -2495,7 +2495,6 @@ impl GitPanel { { return; // Hide the cancelled by user message } else { - let project = self.project.clone(); workspace.update(cx, |workspace, cx| { let workspace_weak = cx.weak_entity(); let toast = @@ -2503,13 +2502,10 @@ impl GitPanel { this.icon(ToastIcon::new(IconName::XCircle).color(Color::Error)) .action("View Log", move |window, cx| { let message = message.clone(); - let project = project.clone(); let action = action.clone(); workspace_weak .update(cx, move |workspace, cx| { - Self::open_output( - project, action, workspace, &message, window, cx, - ) + Self::open_output(action, workspace, &message, window, cx) }) .ok(); }) @@ -2531,21 +2527,17 @@ impl GitPanel { let status_toast = StatusToast::new(message, cx, move |this, _cx| { use remote_output::SuccessStyle::*; - let project = self.project.clone(); match style { Toast { .. } => this, ToastWithLog { output } => this .icon(ToastIcon::new(IconName::GitBranchSmall).color(Color::Muted)) .action("View Log", move |window, cx| { let output = output.clone(); - let project = project.clone(); let output = format!("stdout:\n{}\nstderr:\n{}", output.stdout, output.stderr); workspace_weak .update(cx, move |workspace, cx| { - Self::open_output( - project, operation, workspace, &output, window, cx, - ) + Self::open_output(operation, workspace, &output, window, cx) }) .ok(); }), @@ -2559,7 +2551,6 @@ impl GitPanel { } fn open_output( - project: Entity, operation: impl Into, workspace: &mut Workspace, output: &str, @@ -2568,8 +2559,11 @@ impl GitPanel { ) { let operation = operation.into(); let buffer = cx.new(|cx| Buffer::local(output, cx)); + buffer.update(cx, |buffer, cx| { + buffer.set_capability(language::Capability::ReadOnly, cx); + }); let editor = cx.new(|cx| { - let mut editor = Editor::for_buffer(buffer, Some(project), window, cx); + let mut editor = Editor::for_buffer(buffer, None, window, cx); editor.buffer().update(cx, |buffer, cx| { buffer.set_title(format!("Output from git {operation}"), cx); });