forked from mirrors/jj
revset: reimplement parents() as ancestors() with generation filter
This wouldn't make things any better by itself, but it allows us to merge nested parents().
This commit is contained in:
parent
46b1465324
commit
069a8ed9bc
1 changed files with 16 additions and 25 deletions
|
@ -341,7 +341,6 @@ pub enum RevsetExpression {
|
||||||
All,
|
All,
|
||||||
Commits(Vec<CommitId>),
|
Commits(Vec<CommitId>),
|
||||||
Symbol(String),
|
Symbol(String),
|
||||||
Parents(Rc<RevsetExpression>),
|
|
||||||
Children(Rc<RevsetExpression>),
|
Children(Rc<RevsetExpression>),
|
||||||
Ancestors {
|
Ancestors {
|
||||||
heads: Rc<RevsetExpression>,
|
heads: Rc<RevsetExpression>,
|
||||||
|
@ -442,7 +441,10 @@ impl RevsetExpression {
|
||||||
|
|
||||||
/// Parents of `self`.
|
/// Parents of `self`.
|
||||||
pub fn parents(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> {
|
pub fn parents(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> {
|
||||||
Rc::new(RevsetExpression::Parents(self.clone()))
|
Rc::new(RevsetExpression::Ancestors {
|
||||||
|
heads: self.clone(),
|
||||||
|
generation: 1..2,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ancestors of `self`, including `self`.
|
/// Ancestors of `self`, including `self`.
|
||||||
|
@ -1082,9 +1084,6 @@ fn transform_expression_bottom_up(
|
||||||
RevsetExpression::All => None,
|
RevsetExpression::All => None,
|
||||||
RevsetExpression::Commits(_) => None,
|
RevsetExpression::Commits(_) => None,
|
||||||
RevsetExpression::Symbol(_) => None,
|
RevsetExpression::Symbol(_) => None,
|
||||||
RevsetExpression::Parents(base) => {
|
|
||||||
transform_rec(base, f).map(RevsetExpression::Parents)
|
|
||||||
}
|
|
||||||
RevsetExpression::Children(roots) => {
|
RevsetExpression::Children(roots) => {
|
||||||
transform_rec(roots, f).map(RevsetExpression::Children)
|
transform_rec(roots, f).map(RevsetExpression::Children)
|
||||||
}
|
}
|
||||||
|
@ -1776,19 +1775,6 @@ pub fn evaluate_expression<'repo>(
|
||||||
let commit_ids = resolve_symbol(repo, symbol, workspace_ctx.map(|c| c.workspace_id))?;
|
let commit_ids = resolve_symbol(repo, symbol, workspace_ctx.map(|c| c.workspace_id))?;
|
||||||
evaluate_expression(repo, &RevsetExpression::Commits(commit_ids), workspace_ctx)
|
evaluate_expression(repo, &RevsetExpression::Commits(commit_ids), workspace_ctx)
|
||||||
}
|
}
|
||||||
RevsetExpression::Parents(base_expression) => {
|
|
||||||
// TODO: Make this lazy
|
|
||||||
let base_set = base_expression.evaluate(repo, workspace_ctx)?;
|
|
||||||
let mut parent_entries = base_set
|
|
||||||
.iter()
|
|
||||||
.flat_map(|entry| entry.parents())
|
|
||||||
.collect_vec();
|
|
||||||
parent_entries.sort_by_key(|b| Reverse(b.position()));
|
|
||||||
parent_entries.dedup();
|
|
||||||
Ok(Box::new(EagerRevset {
|
|
||||||
index_entries: parent_entries,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
RevsetExpression::Children(roots) => {
|
RevsetExpression::Children(roots) => {
|
||||||
let root_set = roots.evaluate(repo, workspace_ctx)?;
|
let root_set = roots.evaluate(repo, workspace_ctx)?;
|
||||||
let candidates_expression = roots.descendants();
|
let candidates_expression = roots.descendants();
|
||||||
|
@ -2113,7 +2099,10 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wc_symbol.parents(),
|
wc_symbol.parents(),
|
||||||
Rc::new(RevsetExpression::Parents(wc_symbol.clone()))
|
Rc::new(RevsetExpression::Ancestors {
|
||||||
|
heads: wc_symbol.clone(),
|
||||||
|
generation: 1..2,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wc_symbol.ancestors(),
|
wc_symbol.ancestors(),
|
||||||
|
@ -3035,13 +3024,14 @@ mod tests {
|
||||||
Symbol(
|
Symbol(
|
||||||
"foo",
|
"foo",
|
||||||
),
|
),
|
||||||
Parents(
|
Ancestors {
|
||||||
Filter(
|
heads: Filter(
|
||||||
Author(
|
Author(
|
||||||
"baz",
|
"baz",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
generation: 1..2,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
Symbol(
|
Symbol(
|
||||||
"qux",
|
"qux",
|
||||||
|
@ -3061,8 +3051,8 @@ mod tests {
|
||||||
Symbol(
|
Symbol(
|
||||||
"foo",
|
"foo",
|
||||||
),
|
),
|
||||||
Parents(
|
Ancestors {
|
||||||
Intersection(
|
heads: Intersection(
|
||||||
Symbol(
|
Symbol(
|
||||||
"qux",
|
"qux",
|
||||||
),
|
),
|
||||||
|
@ -3072,7 +3062,8 @@ mod tests {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
generation: 1..2,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
Filter(
|
Filter(
|
||||||
Description(
|
Description(
|
||||||
|
|
Loading…
Reference in a new issue