Skip to content

Commit

Permalink
view: add method that iterates remote branches only
Browse files Browse the repository at this point in the history
There aren't many callers, but let's add it for consistency.
  • Loading branch information
yuja committed Sep 30, 2023
1 parent c5474ff commit f0f1d72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 6 additions & 8 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,14 +1616,12 @@ fn cmd_status(
.filter(|(_, target)| target.has_conflict())
.map(|(branch_name, _)| branch_name)
.collect_vec();
let mut conflicted_remote_branches = vec![];
for (branch_name, branch_target) in repo.view().branches() {
for (remote_name, remote_target) in &branch_target.remote_targets {
if remote_target.has_conflict() {
conflicted_remote_branches.push((branch_name.clone(), remote_name.clone()));
}
}
}
let conflicted_remote_branches = repo
.view()
.remote_branches()
.filter(|(_, target)| target.has_conflict())
.map(|(full_name, _)| full_name)
.collect_vec();
if !conflicted_local_branches.is_empty() {
writeln!(
formatter.labeled("conflict"),
Expand Down
11 changes: 11 additions & 0 deletions lib/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ impl View {
}
}

/// Iterates remote branch `((name, remote_name), target)`s in
/// lexicographical order.
pub fn remote_branches(&self) -> impl Iterator<Item = ((&str, &str), &RefTarget)> {
self.data.branches.iter().flat_map(|(name, branch_target)| {
branch_target
.remote_targets
.iter()
.map(|(remote_name, target)| ((name.as_ref(), remote_name.as_ref()), target))
})
}

pub fn get_remote_branch(&self, name: &str, remote_name: &str) -> &RefTarget {
if let Some(branch_target) = self.data.branches.get(name) {
let maybe_target = branch_target.remote_targets.get(remote_name);
Expand Down

0 comments on commit f0f1d72

Please sign in to comment.