Skip to content

Commit

Permalink
cli: propagate error from find_bookmarks_with() callback
Browse files Browse the repository at this point in the history
An error may be returned from revset containing_fn.
  • Loading branch information
yuja committed Oct 22, 2024
1 parent 825b667 commit 9d98ca4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion cli/src/commands/bookmark/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ fn find_forgettable_bookmarks<'a>(
name_patterns: &[StringPattern],
) -> Result<Vec<(&'a str, BookmarkTarget<'a>)>, CommandError> {
find_bookmarks_with(name_patterns, |pattern| {
view.bookmarks().filter(|(name, _)| pattern.matches(name))
view.bookmarks()
.filter(|(name, _)| pattern.matches(name))
.map(Ok)
})
}
13 changes: 8 additions & 5 deletions cli/src/commands/bookmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,25 @@ fn find_local_bookmarks<'a>(
name_patterns: &[StringPattern],
) -> Result<Vec<(&'a str, &'a RefTarget)>, CommandError> {
find_bookmarks_with(name_patterns, |pattern| {
view.local_bookmarks_matching(pattern)
view.local_bookmarks_matching(pattern).map(Ok)
})
}

fn find_bookmarks_with<'a, 'b, V, I: Iterator<Item = (&'a str, V)>>(
fn find_bookmarks_with<'a, 'b, V, I>(
name_patterns: &'b [StringPattern],
mut find_matches: impl FnMut(&'b StringPattern) -> I,
) -> Result<Vec<I::Item>, CommandError> {
let mut matching_bookmarks: Vec<I::Item> = vec![];
) -> Result<Vec<(&'a str, V)>, CommandError>
where
I: Iterator<Item = Result<(&'a str, V), CommandError>>,
{
let mut matching_bookmarks: Vec<(&'a str, V)> = vec![];
let mut unmatched_patterns = vec![];
for pattern in name_patterns {
let mut matches = find_matches(pattern).peekable();
if matches.peek().is_none() {
unmatched_patterns.push(pattern);
}
matching_bookmarks.extend(matches);
matches.process_results(|iter| matching_bookmarks.extend(iter))?;
}
match &unmatched_patterns[..] {
[] => {
Expand Down
1 change: 1 addition & 0 deletions cli/src/commands/bookmark/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub fn cmd_bookmark_move(
repo.view()
.local_bookmarks_matching(pattern)
.filter(|(_, target)| target.added_ids().any(&is_source_commit))
.map(Ok)
})?
} else {
repo.view()
Expand Down

0 comments on commit 9d98ca4

Please sign in to comment.