mirror of
https://github.com/openai/codex.git
synced 2026-11-30 00:10:49 +00:00
add branch name w/ sync function for git info
This commit is contained in:
@@ -83,6 +83,36 @@ pub async fn collect_git_info(cwd: &Path) -> Option<GitInfo> {
|
||||
Some(git_info)
|
||||
}
|
||||
|
||||
/// Blocking convenience wrapper around `collect_git_info` suitable for
|
||||
/// synchronous contexts. If called from within an active Tokio runtime,
|
||||
/// spawns a separate thread to avoid blocking the runtime's executor thread.
|
||||
pub fn collect_git_info_blocking(cwd: &Path) -> Option<GitInfo> {
|
||||
// If we're already on a Tokio runtime, avoid `block_on` on the same thread.
|
||||
if tokio::runtime::Handle::try_current().is_ok() {
|
||||
let cwd = cwd.to_path_buf();
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
// Use a lightweight current-thread runtime.
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build();
|
||||
let res = match rt {
|
||||
Ok(rt) => rt.block_on(collect_git_info(&cwd)),
|
||||
Err(_) => None,
|
||||
};
|
||||
let _ = tx.send(res);
|
||||
});
|
||||
rx.recv().ok().flatten()
|
||||
} else {
|
||||
// Safe to block here – we're not inside a runtime.
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.ok()?;
|
||||
rt.block_on(collect_git_info(cwd))
|
||||
}
|
||||
}
|
||||
|
||||
/// Run a git command with a timeout to prevent blocking on large repositories
|
||||
async fn run_git_command_with_timeout(args: &[&str], cwd: &Path) -> Option<std::process::Output> {
|
||||
let result = timeout(
|
||||
|
||||
@@ -212,6 +212,19 @@ impl HistoryCell {
|
||||
None => config.cwd.display().to_string(),
|
||||
};
|
||||
|
||||
// Determine the current Git branch (if any) for display using
|
||||
// the shared Git info collector in a way that is safe in sync contexts.
|
||||
let branch_suffix = codex_core::git_info::collect_git_info_blocking(&config.cwd)
|
||||
.and_then(|g| g.branch)
|
||||
.map(|b| format!(" ({b})"))
|
||||
.unwrap_or_default();
|
||||
|
||||
let path_and_branch = if branch_suffix.is_empty() {
|
||||
format!(" {cwd_str}")
|
||||
} else {
|
||||
format!(" {cwd_str}{branch_suffix}")
|
||||
};
|
||||
|
||||
let lines: Vec<Line<'static>> = vec![
|
||||
Line::from(vec![
|
||||
Span::raw(">_ ").dim(),
|
||||
@@ -219,7 +232,7 @@ impl HistoryCell {
|
||||
"You are using OpenAI Codex in",
|
||||
Style::default().add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::raw(format!(" {cwd_str}")).dim(),
|
||||
Span::raw(path_and_branch).dim(),
|
||||
]),
|
||||
Line::from("".dim()),
|
||||
Line::from(" To get started, describe a task or try one of these commands:".dim()),
|
||||
@@ -834,6 +847,8 @@ impl HistoryCell {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
impl WidgetRef for &HistoryCell {
|
||||
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
|
||||
Paragraph::new(Text::from(self.plain_lines()))
|
||||
|
||||
Reference in New Issue
Block a user