revset: for roots:heads, terminate ancestor lookup at min(roots)

This commit is contained in:
Yuya Nishihara 2023-04-06 18:43:39 +09:00
parent ddff089286
commit 85fb1f74c3
3 changed files with 32 additions and 2 deletions

View file

@ -825,9 +825,14 @@ impl<'index, 'heads> EvaluationContext<'index, 'heads> {
S: InternalRevset<'a> + ?Sized,
T: InternalRevset<'b> + ?Sized,
{
let mut reachable: HashSet<_> = root_set.iter().map(|entry| entry.position()).collect();
let root_positions = root_set.iter().map(|entry| entry.position()).collect_vec();
let bottom_position = *root_positions.last().unwrap_or(&IndexPosition::MAX);
let mut reachable: HashSet<_> = root_positions.into_iter().collect();
let mut index_entries = vec![];
let candidates = self.walk_ancestors(head_set).collect_vec();
let candidates = self
.walk_ancestors(head_set)
.take_while(|entry| entry.position() >= bottom_position)
.collect_vec();
for candidate in candidates.into_iter().rev() {
if reachable.contains(&candidate.position())
|| candidate

View file

@ -976,6 +976,30 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
vec![]
);
// Empty root
assert_eq!(
resolve_commit_ids(mut_repo, &format!("none():{}", commit5.id().hex())),
vec![],
);
// Multiple root, commit1 shouldn't be hidden by commit2
assert_eq!(
resolve_commit_ids(
mut_repo,
&format!(
"({}|{}):{}",
commit1.id().hex(),
commit2.id().hex(),
commit3.id().hex()
)
),
vec![
commit3.id().clone(),
commit2.id().clone(),
commit1.id().clone()
]
);
// Including a merge
assert_eq!(
resolve_commit_ids(

View file

@ -13,6 +13,7 @@ v2.40.0
v2.39.0..v2.40.0
:v2.40.0 ~ :v2.39.0
v2.39.0:v2.40.0
v2.40.0+
# Tags and branches
tags()
branches()