Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: simplify string parsing in repository
Maximilian Roosa0ce2a2507e2
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rsindex e8f9b4117..3fcdfcf6e 100644--- a/src/git/repository/mod.rs+++ b/src/git/repository/mod.rs@@ -961,15 +961,13 @@ impl Repository {// Parse output: "<behind>\t<ahead>" format// Example: "5\t3" means 5 commits behind, 3 commits ahead// git rev-list --left-right outputs left (base) first, then right (head)- let parts: Vec<&str> = output.trim().split('\t').collect();- anyhow::ensure!(- parts.len() == 2,- "Unexpected rev-list output format: {}",- output- );+ let (behind_str, ahead_str) = output+ .trim()+ .split_once('\t')+ .ok_or_else(|| anyhow::anyhow!("Unexpected rev-list output format: {}", output))?;- let behind: usize = parts[0].parse().context("Failed to parse behind count")?;- let ahead: usize = parts[1].parse().context("Failed to parse ahead count")?;+ let behind: usize = behind_str.parse().context("Failed to parse behind count")?;+ let ahead: usize = ahead_str.parse().context("Failed to parse ahead count")?;Ok((ahead, behind))}@@ -986,12 +984,8 @@ impl Repository {let branches: Vec<(String, String)> = output.lines().filter_map(|line| {- let parts: Vec<&str> = line.split_whitespace().collect();- if parts.len() == 2 {- Some((parts[0].to_string(), parts[1].to_string()))- } else {- None- }+ let (branch, sha) = line.split_once(' ')?;+ Some((branch.to_string(), sha.to_string()))}).collect();@@ -1012,17 +1006,12 @@ impl Repository {let branches: Vec<(String, String)> = output.lines().filter_map(|line| {- let parts: Vec<&str> = line.split_whitespace().collect();- if parts.len() == 2 {- let branch_name = parts[0];- // Skip <remote>/HEAD (symref)- if branch_name.ends_with("/HEAD") {- None- } else {- Some((branch_name.to_string(), parts[1].to_string()))- }- } else {+ let (branch_name, sha) = line.split_once(' ')?;+ // Skip <remote>/HEAD (symref)+ if branch_name.ends_with("/HEAD") {None+ } else {+ Some((branch_name.to_string(), sha.to_string()))}}).collect();