mirror of
https://github.com/openai/codex.git
synced 2026-10-18 17:18:52 +00:00
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
This commit is contained in:
committed by
copyberry
parent
3749d1eff7
commit
011f803f3c
@@ -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
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user