Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor field names for semantic clarity in diff columns
Maximilian Roos70c368897d3f
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rsindex 7865aea7f..7e59ce46e 100644--- a/src/commands/list/collect.rs+++ b/src/commands/list/collect.rs@@ -169,11 +169,19 @@ enum DrainOutcome {TimedOut {/// Number of task results received before timeoutreceived_count: usize,- /// Items with missing results: (item_idx, branch_name, missing_result_kinds)- items_with_missing: Vec<(usize, String, Vec<TaskKind>)>,+ /// Items with missing results+ items_with_missing: Vec<MissingResult>,},}+/// Item with missing task results (for timeout diagnostics)+#[derive(Debug)]+struct MissingResult {+ item_idx: usize,+ name: String,+ missing_kinds: Vec<TaskKind>,+}+/// Tracks expected result types per item for timeout diagnostics.////// Populated at spawn time so we know exactly which results to expect,@@ -257,7 +265,7 @@ fn drain_results(let received_count: usize = received_by_item.values().map(|v| v.len()).sum();// Find items with missing results by comparing received vs expected- let mut items_with_missing: Vec<(usize, String, Vec<TaskKind>)> = Vec::new();+ let mut items_with_missing: Vec<MissingResult> = Vec::new();for (item_idx, item) in items.iter().enumerate() {// Get expected results for this item (populated at spawn time)@@ -270,23 +278,27 @@ fn drain_results(.unwrap_or(&[]);// Find missing results- let missing: Vec<TaskKind> = expected+ let missing_kinds: Vec<TaskKind> = expected.iter().filter(|kind| !received.contains(kind)).copied().collect();- if !missing.is_empty() {+ if !missing_kinds.is_empty() {let name = item.branch.clone().unwrap_or_else(|| item.head[..8.min(item.head.len())].to_string());- items_with_missing.push((item_idx, name, missing));+ items_with_missing.push(MissingResult {+ item_idx,+ name,+ missing_kinds,+ });}}// Sort by item index and limit to first 5- items_with_missing.sort_by_key(|(idx, _, _)| *idx);+ items_with_missing.sort_by_key(|result| result.item_idx);items_with_missing.truncate(5);return DrainOutcome::TimedOut {@@ -842,9 +854,14 @@ pub fn collect(if !items_with_missing.is_empty() {diag.push_str("\nMissing results:");- for (_, name, missing) in &items_with_missing {- let missing_names: Vec<&str> = missing.iter().map(|k| k.into()).collect();- diag.push_str(&format!("\n - {name}: {}", missing_names.join(", ")));+ for result in &items_with_missing {+ let missing_names: Vec<&str> =+ result.missing_kinds.iter().map(|k| k.into()).collect();+ diag.push_str(&format!(+ "\n - {}: {}",+ result.name,+ missing_names.join(", ")+ ));}}diff --git a/src/commands/list/json_output.rs b/src/commands/list/json_output.rsindex 0e5f0604a..72b2266a3 100644--- a/src/commands/list/json_output.rs+++ b/src/commands/list/json_output.rs@@ -356,14 +356,14 @@ impl JsonItem {/// Convert UpstreamStatus to JsonRemotefn upstream_to_json(upstream: &UpstreamStatus, branch: &Option<String>) -> Option<JsonRemote> {- upstream.active().map(|(remote, ahead, behind)| {+ upstream.active().map(|active| {// Use local branch name since UpstreamStatus only stores the remote name,// not the full tracking refspec. In most cases these match (e.g., feature -> origin/feature).JsonRemote {- name: remote.to_string(),+ name: active.remote.to_string(),branch: branch.clone().unwrap_or_default(),- ahead,- behind,+ ahead: active.ahead,+ behind: active.behind,}})}diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rsindex 2f5be7f4a..337a822bd 100644--- a/src/commands/list/layout.rs+++ b/src/commands/list/layout.rs@@ -231,13 +231,11 @@ fn try_allocate(}/// Width information for two-part columns: diffs ("+128 -147") and arrows ("↑6 ↓1")-/// - For diff columns: added_digits/deleted_digits refer to line change counts-/// - For arrow columns: added_digits/deleted_digits refer to ahead/behind commit counts#[derive(Clone, Copy, Debug)]pub struct DiffWidths {pub total: usize,- pub added_digits: usize, // First part: + for diffs, ↑ for arrows- pub deleted_digits: usize, // Second part: - for diffs, ↓ for arrows+ pub positive_digits: usize, // First part: +/↑/⇡+ pub negative_digits: usize, // Second part: -/↓/⇣}#[derive(Clone, Debug)]@@ -359,8 +357,8 @@ pub enum ColumnFormat {#[derive(Clone, Copy, Debug)]pub struct DiffColumnConfig {- pub added_digits: usize,- pub deleted_digits: usize,+ pub positive_digits: usize,+ pub negative_digits: usize,pub total_width: usize,pub display: DiffDisplayConfig,}@@ -410,8 +408,8 @@ impl ColumnIdeal {Some(Self {width: widths.total,format: ColumnFormat::Diff(DiffColumnConfig {- added_digits: widths.added_digits,- deleted_digits: widths.deleted_digits,+ positive_digits: widths.positive_digits,+ negative_digits: widths.negative_digits,total_width: widths.total,display,}),@@ -471,25 +469,25 @@ fn build_estimated_widths(max_branch: usize, skip_tasks: &HashSet<TaskKind>) ->// Commit counts (Arrows): compact notation, 2 digits covers up to 99ahead_behind: DiffWidths {total: ahead_behind_fixed,- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,},// Line diffs (Signs): show full numbers, 3 digits covers up to 999working_diff: DiffWidths {total: working_diff_fixed,- added_digits: 3,- deleted_digits: 3,+ positive_digits: 3,+ negative_digits: 3,},branch_diff: DiffWidths {total: branch_diff_fixed,- added_digits: 3,- deleted_digits: 3,+ positive_digits: 3,+ negative_digits: 3,},// Upstream (Arrows): compact notation, 2 digits covers up to 99upstream: DiffWidths {total: upstream_fixed,- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,},};@@ -761,12 +759,12 @@ mod tests {"Working diff should pre-allocate for '+999 -999' (9 chars)");assert_eq!(- widths.working_diff.added_digits, 3,- "Pre-allocated for 3-digit added count"+ widths.working_diff.positive_digits, 3,+ "Pre-allocated for 3-digit positive count");assert_eq!(- widths.working_diff.deleted_digits, 3,- "Pre-allocated for 3-digit deleted count"+ widths.working_diff.negative_digits, 3,+ "Pre-allocated for 3-digit negative count");// Branch diff also uses Signs variant when show_full=true@@ -776,12 +774,12 @@ mod tests {"Branch diff should pre-allocate for '+999 -999' (9 chars)");assert_eq!(- widths.branch_diff.added_digits, 3,- "Pre-allocated for 3-digit added count"+ widths.branch_diff.positive_digits, 3,+ "Pre-allocated for 3-digit positive count");assert_eq!(- widths.branch_diff.deleted_digits, 3,- "Pre-allocated for 3-digit deleted count"+ widths.branch_diff.negative_digits, 3,+ "Pre-allocated for 3-digit negative count");// Commit counts (Arrows variant: ↑↓) use compact notation, allocate 2 digits@@ -791,12 +789,12 @@ mod tests {"Ahead/behind should pre-allocate for '↑99 ↓99' (7 chars)");assert_eq!(- widths.ahead_behind.added_digits, 2,- "Pre-allocated for 2-digit ahead count (uses compact notation)"+ widths.ahead_behind.positive_digits, 2,+ "Pre-allocated for 2-digit positive count (uses compact notation)");assert_eq!(- widths.ahead_behind.deleted_digits, 2,- "Pre-allocated for 2-digit behind count (uses compact notation)"+ widths.ahead_behind.negative_digits, 2,+ "Pre-allocated for 2-digit negative count (uses compact notation)");// Upstream also uses Arrows variant@@ -806,12 +804,12 @@ mod tests {"Upstream should pre-allocate for '↑99 ↓99' (7 chars)");assert_eq!(- widths.upstream.added_digits, 2,- "Pre-allocated for 2-digit ahead count"+ widths.upstream.positive_digits, 2,+ "Pre-allocated for 2-digit positive count");assert_eq!(- widths.upstream.deleted_digits, 2,- "Pre-allocated for 2-digit behind count"+ widths.upstream.negative_digits, 2,+ "Pre-allocated for 2-digit negative count");}diff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex c334e7462..ceb39e9a8 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -42,8 +42,8 @@ impl DisplayFields {});let upstream_display = upstream.as_ref().and_then(|u| {- u.active().and_then(|(_, upstream_ahead, upstream_behind)| {- ColumnKind::Upstream.format_diff_plain(upstream_ahead, upstream_behind)+ u.active().and_then(|active| {+ ColumnKind::Upstream.format_diff_plain(active.ahead, active.behind)})});@@ -164,11 +164,20 @@ pub struct UpstreamStatus {pub(super) behind: usize,}+/// Active upstream tracking information+pub struct ActiveUpstream<'a> {+ pub remote: &'a str,+ pub ahead: usize,+ pub behind: usize,+}+impl UpstreamStatus {- pub fn active(&self) -> Option<(&str, usize, usize)> {- self.remote- .as_deref()- .map(|remote| (remote, self.ahead, self.behind))+ pub fn active(&self) -> Option<ActiveUpstream<'_>> {+ self.remote.as_deref().map(|remote| ActiveUpstream {+ remote,+ ahead: self.ahead,+ behind: self.behind,+ })}#[cfg(test)]@@ -392,8 +401,9 @@ impl ListItem {// 6. Upstream statusif let Some(ref upstream) = self.upstream- && let Some((_, ahead, behind)) = upstream.active()- && let Some(formatted) = ColumnKind::Upstream.format_diff_plain(ahead, behind)+ && let Some(active) = upstream.active()+ && let Some(formatted) =+ ColumnKind::Upstream.format_diff_plain(active.ahead, active.behind){parts.push(formatted);}@@ -449,7 +459,7 @@ impl ListItem {let upstream = self.upstream.as_ref().unwrap_or(&default_upstream);let upstream_divergence = match upstream.active() {None => Divergence::None,- Some((_, ahead, behind)) => Divergence::from_counts_with_remote(ahead, behind),+ Some(active) => Divergence::from_counts_with_remote(active.ahead, active.behind),};match &self.kind {diff --git a/src/commands/list/render.rs b/src/commands/list/render.rsindex 1bca111c7..2bd31a50b 100644--- a/src/commands/list/render.rs+++ b/src/commands/list/render.rs@@ -218,16 +218,16 @@ impl DiffColumnConfig {let mut segment = StyledLine::new();// Check for overflow- let positive_overflow = Self::exceeds_width(positive, self.added_digits);- let negative_overflow = Self::exceeds_width(negative, self.deleted_digits);+ let positive_overflow = Self::exceeds_width(positive, self.positive_digits);+ let negative_overflow = Self::exceeds_width(negative, self.negative_digits);if positive == 0 && negative == 0 && !self.display.always_show_zeros {segment.push_raw(" ".repeat(self.total_width));return segment;}- let positive_width = 1 + self.added_digits;- let negative_width = 1 + self.deleted_digits;+ let positive_width = 1 + self.positive_digits;+ let negative_width = 1 + self.negative_digits;// Fixed content width ensures vertical alignment of subcolumnslet content_width = positive_width + 1 + negative_width;@@ -608,13 +608,13 @@ impl ColumnLayout {cell.truncate_to_width(self.width)}ColumnKind::Upstream => {- let Some((_, ahead, behind)) = ctx.upstream.active() else {+ let Some(active) = ctx.upstream.active() else {return StyledLine::new();};// Show centered | when in sync instead of ⇡0 ⇣0// Note: This duplicates the InSync check from Divergence::Special, but// checking counts directly is simpler than threading the enum through.- if ahead == 0 && behind == 0 {+ if active.ahead == 0 && active.behind == 0 {let mut cell = StyledLine::new();// Center the symbol in the column widthlet padding_left = (self.width.saturating_sub(1)) / 2;@@ -622,7 +622,7 @@ impl ColumnLayout {cell.push_styled("|", Style::new().dimmed());return cell;}- self.render_diff_cell(ahead, behind)+ self.render_diff_cell(active.ahead, active.behind)}ColumnKind::Time => {let mut cell = StyledLine::new();@@ -717,8 +717,8 @@ mod tests {1,1,DiffColumnConfig {- added_digits: 1,- deleted_digits: 1,+ positive_digits: 1,+ negative_digits: 1,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -740,8 +740,8 @@ mod tests {10,50,DiffColumnConfig {- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -763,8 +763,8 @@ mod tests {100,50,DiffColumnConfig {- added_digits: 3,- deleted_digits: 2,+ positive_digits: 3,+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -786,8 +786,8 @@ mod tests {0,0,DiffColumnConfig {- added_digits: 1,- deleted_digits: 1,+ positive_digits: 1,+ negative_digits: 1,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -811,8 +811,8 @@ mod tests {1,1,DiffColumnConfig {- added_digits: 1,- deleted_digits: 1,+ positive_digits: 1,+ negative_digits: 1,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -948,8 +948,8 @@ mod tests {ahead,behind,DiffColumnConfig {- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Arrows,@@ -976,8 +976,8 @@ mod tests {0,0,DiffColumnConfig {- added_digits: 0,- deleted_digits: 2,+ positive_digits: 0,+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Arrows,@@ -993,8 +993,8 @@ mod tests {0,50,DiffColumnConfig {- added_digits: 0,- deleted_digits: 2,+ positive_digits: 0,+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Arrows,@@ -1021,8 +1021,8 @@ mod tests {0,0,DiffColumnConfig {- added_digits: 1,- deleted_digits: 1,+ positive_digits: 1,+ negative_digits: 1,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Arrows,@@ -1042,8 +1042,8 @@ mod tests {0,0,DiffColumnConfig {- added_digits: 1,- deleted_digits: 1,+ positive_digits: 1,+ negative_digits: 1,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Arrows,@@ -1136,8 +1136,8 @@ mod tests {53,7,DiffColumnConfig {- added_digits: 2, // Allocates 3 chars: "+NN"- deleted_digits: 2,+ positive_digits: 2, // Allocates 3 chars: "+NN"+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -1156,8 +1156,8 @@ mod tests {33,23,DiffColumnConfig {- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -1176,8 +1176,8 @@ mod tests {2,2,DiffColumnConfig {- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -1228,8 +1228,8 @@ mod tests {999,999,DiffColumnConfig {- added_digits: 3,- deleted_digits: 3,+ positive_digits: 3,+ negative_digits: 3,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -1248,8 +1248,8 @@ mod tests {1000,500,DiffColumnConfig {- added_digits: 3,- deleted_digits: 3,+ positive_digits: 3,+ negative_digits: 3,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -1278,8 +1278,8 @@ mod tests {500,1000,DiffColumnConfig {- added_digits: 3,- deleted_digits: 3,+ positive_digits: 3,+ negative_digits: 3,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -1307,8 +1307,8 @@ mod tests {100_000,200_000,DiffColumnConfig {- added_digits: 3,- deleted_digits: 3,+ positive_digits: 3,+ negative_digits: 3,total_width: total,display: DiffDisplayConfig {variant: DiffVariant::Signs,@@ -1344,8 +1344,8 @@ mod tests {1000, // Use larger value to show K suffix50,DiffColumnConfig {- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,total_width: arrow_total,display: DiffDisplayConfig {variant: DiffVariant::Arrows,@@ -1374,8 +1374,8 @@ mod tests {50,1000, // Use larger value to show K suffixDiffColumnConfig {- added_digits: 2,- deleted_digits: 2,+ positive_digits: 2,+ negative_digits: 2,total_width: arrow_total,display: DiffDisplayConfig {variant: DiffVariant::Arrows,