mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-01 00:50:57 +00:00
cli: propagate error from find_bookmarks_with() callback
An error may be returned from revset containing_fn.
This commit is contained in:
parent
825b6670b3
commit
9d98ca491e
3 changed files with 12 additions and 6 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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[..] {
|
||||
[] => {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue