From 011f803f3cd44802354873de259778913c56ef94 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 28 Sep 2026 20:21:56 +0000 Subject: [PATCH] Avoid collecting unused Git metadata in skill analytics (#49076) ## Why Skill invocation analytics only needs the repository's origin URL, but `collect_git_info` also checks the repository and reads its commit and branch. ## What changed Extract and export `get_git_origin_url` and use it directly in skill analytics to skip the extra Git commands. Reuse the helper in `collect_git_info`, preserving URL sanitization and command timeouts. GitOrigin-RevId: f878936937d0ff8c6313bb8168448e0b25ba1a39 --- codex-rs/analytics/src/reducer.rs | 6 ++---- codex-rs/git-utils/src/info.rs | 25 ++++++++++++++----------- codex-rs/git-utils/src/lib.rs | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/codex-rs/analytics/src/reducer.rs b/codex-rs/analytics/src/reducer.rs index 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.rs index 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 { + 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 { } // 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 { } } - // 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.rs index 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;