Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make the commit sha availabe in the app, via a global
Max Brunsfelda03d062120c9
diff --git a/crates/util/src/channel.rs b/crates/util/src/channel.rsindex 7e60b5e15f6..55f13df0846 100644--- a/crates/util/src/channel.rs+++ b/crates/util/src/channel.rs@@ -1,6 +1,5 @@-use std::env;-use lazy_static::lazy_static;+use std::env;lazy_static! {pub static ref RELEASE_CHANNEL_NAME: String = if cfg!(debug_assertions) {@@ -18,6 +17,8 @@ lazy_static! {};}+pub struct AppCommitSha(pub String);+#[derive(Copy, Clone, PartialEq, Eq, Default)]pub enum ReleaseChannel {#[default]@@ -40,7 +41,6 @@ impl ReleaseChannel {pub fn dev_name(&self) -> &'static str {match self {ReleaseChannel::Dev => "dev",- // TODO kb need to add DB dataReleaseChannel::Nightly => "nightly",ReleaseChannel::Preview => "preview",ReleaseChannel::Stable => "stable",@@ -69,7 +69,6 @@ impl ReleaseChannel {pub fn release_query_param(&self) -> Option<&'static str> {match self {Self::Dev => None,- // TODO kb need to add server handlingSelf::Nightly => Some("nightly=1"),Self::Preview => Some("preview=1"),Self::Stable => None,diff --git a/crates/zed2/build.rs b/crates/zed2/build.rsindex 14bf9999fb7..619f2480298 100644--- a/crates/zed2/build.rs+++ b/crates/zed2/build.rs@@ -1,3 +1,5 @@+use std::process::Command;+fn main() {println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.15.7");@@ -21,4 +23,14 @@ fn main() {// Register exported Objective-C selectors, protocols, etcprintln!("cargo:rustc-link-arg=-Wl,-ObjC");++ // Populate git sha environment variable if git is available+ if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {+ if output.status.success() {+ println!(+ "cargo:rustc-env=ZED_COMMIT_SHA={}",+ String::from_utf8_lossy(&output.stdout).trim()+ );+ }+ }}diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rsindex 700660a9b7e..5206514dfef 100644--- a/crates/zed2/src/main.rs+++ b/crates/zed2/src/main.rs@@ -43,7 +43,7 @@ use std::{use theme::ActiveTheme;use util::{async_maybe,- channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL},+ channel::{parse_zed_link, AppCommitSha, ReleaseChannel, RELEASE_CHANNEL},http::{self, HttpClient},paths, ResultExt,};@@ -113,6 +113,10 @@ fn main() {app.run(move |cx| {cx.set_global(*RELEASE_CHANNEL);+ if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") {+ cx.set_global(AppCommitSha(build_sha.into()))+ }+cx.set_global(listener.clone());load_embedded_fonts(cx);diff --git a/crates/zed2/src/zed2.rs b/crates/zed2/src/zed2.rsindex 84cacccb5ad..e2e113c9b0f 100644--- a/crates/zed2/src/zed2.rs+++ b/crates/zed2/src/zed2.rs@@ -23,7 +23,7 @@ use std::{borrow::Cow, ops::Deref, sync::Arc};use terminal_view::terminal_panel::TerminalPanel;use util::{asset_str,- channel::ReleaseChannel,+ channel::{AppCommitSha, ReleaseChannel},paths::{self, LOCAL_SETTINGS_RELATIVE_PATH},ResultExt,};@@ -432,9 +432,16 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {}fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext<Workspace>) {+ use std::fmt::Write as _;+let app_name = cx.global::<ReleaseChannel>().display_name();let version = env!("CARGO_PKG_VERSION");- let prompt = cx.prompt(PromptLevel::Info, &format!("{app_name} {version}"), &["OK"]);+ let mut message = format!("{app_name} {version}");+ if let Some(sha) = cx.try_global::<AppCommitSha>() {+ write!(&mut message, "\n\n{}", sha.0).unwrap();+ }++ let prompt = cx.prompt(PromptLevel::Info, &message, &["OK"]);cx.foreground_executor().spawn(async {prompt.await.ok();