Lightweight coding agent that runs in your terminal
Rust
Avoid collecting unused Git metadata in skill analytics (#49076)
Tamir Duberstein011f803f3cd4
diff --git a/codex-rs/analytics/src/reducer.rs b/codex-rs/analytics/src/reducer.rsindex d9a0090188..956f155523 100644--- a/codex-rs/analytics/src/reducer.rs+++ b/codex-rs/analytics/src/reducer.rs@@ -157,7 +157,7 @@ use codex_app_server_protocol::TurnSteerResponse;use codex_app_server_protocol::UserInput;use codex_app_server_protocol::WebSearchAction;use codex_git_utils::SanitizedGitUrl;-use codex_git_utils::collect_git_info;+use codex_git_utils::get_git_origin_url;use codex_git_utils::get_git_repo_root;use codex_login::default_client::originator;use codex_protocol::config_types::ModeKind;@@ -1348,9 +1348,7 @@ impl AnalyticsReducer {};let repo_root = get_git_repo_root(path.as_path());let repo_url = if let Some(root) = repo_root.as_ref() {- collect_git_info(root)- .await- .and_then(|info| info.repository_url)+ get_git_origin_url(root).await} else {None};diff --git a/codex-rs/git-utils/src/info.rs b/codex-rs/git-utils/src/info.rsindex 092acd0dab..7f038304db 100644--- a/codex-rs/git-utils/src/info.rs+++ b/codex-rs/git-utils/src/info.rs@@ -59,6 +59,17 @@ pub struct GitDiffToRemote {pub diff: String,}+/// Return the sanitized URL for the `origin` remote, if available.+pub async fn get_git_origin_url(cwd: &Path) -> Option<SanitizedGitUrl> {+ let output = run_git_command_with_timeout(&["remote", "get-url", "origin"], cwd).await?;+ if !output.status.success() {+ return None;+ }++ let url = String::from_utf8(output.stdout).ok()?;+ SanitizedGitUrl::try_from(url.trim()).ok()+}+/// Collect git repository information from the given working directory using command-line git./// Returns None if no git repository is found or if git operations fail./// Uses timeouts to prevent freezing on large repositories.@@ -75,16 +86,16 @@ pub async fn collect_git_info(cwd: &Path) -> Option<GitInfo> {}// Run all git info collection commands in parallel- let (commit_result, branch_result, url_result) = tokio::join!(+ let (commit_result, branch_result, repository_url) = tokio::join!(run_git_command_with_timeout(&["rev-parse", "HEAD"], cwd),run_git_command_with_timeout(&["rev-parse", "--abbrev-ref", "HEAD"], cwd),- run_git_command_with_timeout(&["remote", "get-url", "origin"], cwd)+ get_git_origin_url(cwd));let mut git_info = GitInfo {commit_hash: None,branch: None,- repository_url: None,+ repository_url,};// Process commit hash@@ -106,14 +117,6 @@ pub async fn collect_git_info(cwd: &Path) -> Option<GitInfo> {}}- // Process repository URL- if let Some(output) = url_result- && output.status.success()- && let Ok(url) = String::from_utf8(output.stdout)- {- git_info.repository_url = SanitizedGitUrl::try_from(url.trim()).ok();- }-Some(git_info)}diff --git a/codex-rs/git-utils/src/lib.rs b/codex-rs/git-utils/src/lib.rsindex 495a459fb0..1224d2ab03 100644--- a/codex-rs/git-utils/src/lib.rs+++ b/codex-rs/git-utils/src/lib.rs@@ -41,6 +41,7 @@ pub use info::canonicalize_git_remote_url;pub use info::collect_git_info;pub use info::current_branch_name;pub use info::default_branch_name;+pub use info::get_git_origin_url;pub use info::get_git_remote_urls;pub use info::get_git_remote_urls_assume_git_repo;pub use info::get_git_repo_root;