From 9d98ca491ece5c5f800d73138854cbbdfb103409 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 19 Oct 2024 18:58:20 +0900 Subject: [PATCH] cli: propagate error from find_bookmarks_with() callback An error may be returned from revset containing_fn. --- cli/src/commands/bookmark/forget.rs | 4 +++- cli/src/commands/bookmark/mod.rs | 13 ++++++++----- cli/src/commands/bookmark/move.rs | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cli/src/commands/bookmark/forget.rs b/cli/src/commands/bookmark/forget.rs index 3a7e699383..24957473f2 100644 --- a/cli/src/commands/bookmark/forget.rs +++ b/cli/src/commands/bookmark/forget.rs @@ -73,6 +73,8 @@ fn find_forgettable_bookmarks<'a>( name_patterns: &[StringPattern], ) -> Result)>, CommandError> { find_bookmarks_with(name_patterns, |pattern| { - view.bookmarks().filter(|(name, _)| pattern.matches(name)) + view.bookmarks() + .filter(|(name, _)| pattern.matches(name)) + .map(Ok) }) } diff --git a/cli/src/commands/bookmark/mod.rs b/cli/src/commands/bookmark/mod.rs index 689793f740..3373971b2b 100644 --- a/cli/src/commands/bookmark/mod.rs +++ b/cli/src/commands/bookmark/mod.rs @@ -104,22 +104,25 @@ fn find_local_bookmarks<'a>( name_patterns: &[StringPattern], ) -> Result, 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>( +fn find_bookmarks_with<'a, 'b, V, I>( name_patterns: &'b [StringPattern], mut find_matches: impl FnMut(&'b StringPattern) -> I, -) -> Result, CommandError> { - let mut matching_bookmarks: Vec = vec![]; +) -> Result, CommandError> +where + I: Iterator>, +{ + 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[..] { [] => { diff --git a/cli/src/commands/bookmark/move.rs b/cli/src/commands/bookmark/move.rs index 0708d47f62..25a394f627 100644 --- a/cli/src/commands/bookmark/move.rs +++ b/cli/src/commands/bookmark/move.rs @@ -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()