Skip to content

Commit

Permalink
revset: propagate BackendError from inner file() predicate function
Browse files Browse the repository at this point in the history
We should probably add error propagation path to Revset iterator, and predicate
functions will return Result<bool, RevsetEvaluationError>.
  • Loading branch information
yuja committed Jul 17, 2024
1 parent bb33d86 commit ba19226
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/src/default_index/revset_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use itertools::Itertools;

use super::rev_walk::{EagerRevWalk, PeekableRevWalk, RevWalk, RevWalkBuilder};
use super::revset_graph_iterator::RevsetGraphWalk;
use crate::backend::{ChangeId, CommitId, MillisSinceEpoch};
use crate::backend::{BackendResult, ChangeId, CommitId, MillisSinceEpoch};
use crate::commit::Commit;
use crate::default_index::{AsCompositeIndex, CompositeIndex, IndexPosition};
use crate::graph::GraphEdge;
Expand Down Expand Up @@ -1034,6 +1034,7 @@ fn build_predicate_fn(
store: Arc<Store>,
predicate: &RevsetFilterPredicate,
) -> Box<dyn ToPredicateFn> {
// TODO: propagate BackendError
match predicate {
RevsetFilterPredicate::ParentCount(parent_count_range) => {
let parent_count_range = parent_count_range.clone();
Expand Down Expand Up @@ -1074,7 +1075,7 @@ fn build_predicate_fn(
box_pure_predicate_fn(move |index, pos| {
let entry = index.entry_by_pos(pos);
let commit = store.get_commit(&entry.commit_id()).unwrap();
has_diff_from_parent(&store, index, &commit, matcher.as_ref())
has_diff_from_parent(&store, index, &commit, matcher.as_ref()).unwrap()
})
}
RevsetFilterPredicate::HasConflict => box_pure_predicate_fn(move |index, pos| {
Expand All @@ -1098,20 +1099,20 @@ fn has_diff_from_parent(
index: &CompositeIndex,
commit: &Commit,
matcher: &dyn Matcher,
) -> bool {
let parents: Vec<_> = commit.parents().try_collect().unwrap();
) -> BackendResult<bool> {
let parents: Vec<_> = commit.parents().try_collect()?;
if let [parent] = parents.as_slice() {
// Fast path: no need to load the root tree
let unchanged = commit.tree_id() == parent.tree_id();
if matcher.visit(RepoPath::root()) == Visit::AllRecursively {
return !unchanged;
return Ok(!unchanged);
} else if unchanged {
return false;
return Ok(false);
}
}
let from_tree = rewrite::merge_commit_trees_without_repo(store, &index, &parents).unwrap();
let to_tree = commit.tree().unwrap();
from_tree.diff(&to_tree, matcher).next().is_some()
let from_tree = rewrite::merge_commit_trees_without_repo(store, &index, &parents)?;
let to_tree = commit.tree()?;
Ok(from_tree.diff(&to_tree, matcher).next().is_some())
}

#[cfg(test)]
Expand Down

0 comments on commit ba19226

Please sign in to comment.