Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: Add total cell count to progress footer

Maximilian Roos56a3174761be
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rs
index f630f1801..950453910 100644
--- a/src/commands/list/collect.rs
+++ b/src/commands/list/collect.rs
@@ -586,8 +586,14 @@ pub fn collect(
// Single-line invariant: use safe width to prevent line wrapping
let max_width = super::layout::get_safe_list_width();
- // Build initial footer message
- let total_cells = all_items.len() * layout.columns.len();
+ // Create collection options
+ let options = super::collect_progressive_impl::CollectOptions {
+ fetch_ci,
+ check_merge_tree_conflicts,
+ };
+
+ // Counter for total cells - incremented as spawns are queued
+ let cell_count = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
let num_worktrees = all_items
.iter()
.filter(|item| item.worktree_data().is_some())
@@ -631,8 +637,7 @@ pub fn collect(
})
.collect();
- let initial_footer =
- format!("{INFO_EMOJI} {dim}{footer_base} (0/{total_cells} cells loaded){dim:#}");
+ let initial_footer = format!("{INFO_EMOJI} {dim}{footer_base} (loading...){dim:#}");
Some(ProgressiveTable::new(
layout.format_header_line(),
@@ -655,16 +660,11 @@ pub fn collect(
// Create channel for cell updates
let (tx, rx) = chan::unbounded();
- // Create collection options
- let options = super::collect_progressive_impl::CollectOptions {
- fetch_ci,
- check_merge_tree_conflicts,
- };
-
// Spawn worktree collection in background thread
let sorted_worktrees_clone = sorted_worktrees.clone();
let tx_worktrees = tx.clone();
let default_branch_clone = default_branch.clone();
+ let cell_count_wt = cell_count.clone();
std::thread::spawn(move || {
sorted_worktrees_clone
.par_iter()
@@ -678,6 +678,7 @@ pub fn collect(
&default_branch_clone,
&options,
tx_worktrees.clone(),
+ &cell_count_wt,
);
});
});
@@ -688,6 +689,7 @@ pub fn collect(
let main_path = main_worktree.path.clone();
let tx_branches = tx.clone();
let default_branch_clone = default_branch.clone();
+ let cell_count_br = cell_count.clone();
std::thread::spawn(move || {
branches_clone
.par_iter()
@@ -702,6 +704,7 @@ pub fn collect(
&default_branch_clone,
&options,
tx_branches.clone(),
+ &cell_count_br,
);
});
});
@@ -713,6 +716,7 @@ pub fn collect(
let main_path = main_worktree.path.clone();
let tx_remote = tx.clone();
let default_branch_clone = default_branch.clone();
+ let cell_count_rm = cell_count.clone();
std::thread::spawn(move || {
remote_branches_clone.par_iter().enumerate().for_each(
|(idx, (branch_name, commit_sha))| {
@@ -725,6 +729,7 @@ pub fn collect(
&default_branch_clone,
&options,
tx_remote.clone(),
+ &cell_count_rm,
);
},
);
@@ -769,6 +774,7 @@ pub fn collect(
let dim = Style::new().dimmed();
completed_cells += 1;
+ let total_cells = cell_count.load(std::sync::atomic::Ordering::Relaxed);
// Update footer progress
let footer_msg = format!(
diff --git a/src/commands/list/collect_progressive_impl.rs b/src/commands/list/collect_progressive_impl.rs
index 9b987402a..5bd3f4849 100644
--- a/src/commands/list/collect_progressive_impl.rs
+++ b/src/commands/list/collect_progressive_impl.rs
@@ -11,6 +11,8 @@
use crossbeam_channel::Sender;
use std::path::PathBuf;
+use std::sync::Arc;
+use std::sync::atomic::{AtomicUsize, Ordering};
use worktrunk::git::{LineDiff, Repository, Worktree};
use worktrunk::path::format_path_for_display;
@@ -360,6 +362,7 @@ pub fn collect_worktree_progressive(
default_branch: &str,
options: &CollectOptions,
tx: Sender<CellUpdate>,
+ cell_count: &Arc<AtomicUsize>,
) {
let ctx = TaskContext {
repo_path: wt.path.clone(),
@@ -371,9 +374,13 @@ pub fn collect_worktree_progressive(
std::thread::scope(|s| {
spawn_commit_details(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_ahead_behind(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_branch_diff(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_working_tree_diff(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_merge_tree_conflicts(
s,
&ctx,
@@ -381,10 +388,15 @@ pub fn collect_worktree_progressive(
true,
tx.clone(),
);
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_worktree_state(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_user_status(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_upstream(s, &ctx, true, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_ci_status(s, &ctx, options.fetch_ci, tx);
+ cell_count.fetch_add(1, Ordering::Relaxed);
});
}
@@ -465,6 +477,7 @@ fn parse_status_for_symbols(status_output: &str) -> (String, bool, bool) {
/// 4. Upstream tracking status
/// 5. Conflicts check
/// 6. CI/PR status
+#[allow(clippy::too_many_arguments)]
pub fn collect_branch_progressive(
branch_name: &str,
commit_sha: &str,
@@ -473,6 +486,7 @@ pub fn collect_branch_progressive(
default_branch: &str,
options: &CollectOptions,
tx: Sender<CellUpdate>,
+ cell_count: &Arc<AtomicUsize>,
) {
let ctx = TaskContext {
repo_path: repo_path.to_path_buf(),
@@ -484,9 +498,13 @@ pub fn collect_branch_progressive(
std::thread::scope(|s| {
spawn_commit_details(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_ahead_behind(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_branch_diff(s, &ctx, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_upstream(s, &ctx, false, tx.clone());
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_merge_tree_conflicts(
s,
&ctx,
@@ -494,6 +512,8 @@ pub fn collect_branch_progressive(
false,
tx.clone(),
);
+ cell_count.fetch_add(1, Ordering::Relaxed);
spawn_ci_status(s, &ctx, options.fetch_ci, tx);
+ cell_count.fetch_add(1, Ordering::Relaxed);
});
}