revset: group RevsetExpression constructors by resolved/user/generic

They'll become different in State types.
This commit is contained in:
Yuya Nishihara 2024-09-04 18:54:20 +09:00
parent 1372b39341
commit 78d68f98f5

View file

@ -238,6 +238,7 @@ pub enum RevsetExpression {
Difference(Rc<Self>, Rc<Self>), Difference(Rc<Self>, Rc<Self>),
} }
// Leaf expression that never contains unresolved commit refs
impl RevsetExpression { impl RevsetExpression {
pub fn none() -> Rc<Self> { pub fn none() -> Rc<Self> {
Rc::new(Self::None) Rc::new(Self::None)
@ -247,6 +248,34 @@ impl RevsetExpression {
Rc::new(Self::All) Rc::new(Self::All)
} }
pub fn visible_heads() -> Rc<Self> {
Rc::new(Self::VisibleHeads)
}
pub fn root() -> Rc<Self> {
Rc::new(Self::Root)
}
pub fn commit(commit_id: CommitId) -> Rc<Self> {
Self::commits(vec![commit_id])
}
pub fn commits(commit_ids: Vec<CommitId>) -> Rc<Self> {
Rc::new(Self::Commits(commit_ids))
}
pub fn filter(predicate: RevsetFilterPredicate) -> Rc<Self> {
Rc::new(Self::Filter(predicate))
}
/// Find any empty commits.
pub fn is_empty() -> Rc<Self> {
Self::filter(RevsetFilterPredicate::File(FilesetExpression::all())).negated()
}
}
// Leaf expression that represents unresolved commit refs
impl RevsetExpression {
pub fn working_copy(workspace_id: WorkspaceId) -> Rc<Self> { pub fn working_copy(workspace_id: WorkspaceId) -> Rc<Self> {
Rc::new(Self::CommitRef(RevsetCommitRef::WorkingCopy(workspace_id))) Rc::new(Self::CommitRef(RevsetCommitRef::WorkingCopy(workspace_id)))
} }
@ -264,22 +293,6 @@ impl RevsetExpression {
Rc::new(Self::CommitRef(commit_ref)) Rc::new(Self::CommitRef(commit_ref))
} }
pub fn commit(commit_id: CommitId) -> Rc<Self> {
Self::commits(vec![commit_id])
}
pub fn commits(commit_ids: Vec<CommitId>) -> Rc<Self> {
Rc::new(Self::Commits(commit_ids))
}
pub fn visible_heads() -> Rc<Self> {
Rc::new(Self::VisibleHeads)
}
pub fn root() -> Rc<Self> {
Rc::new(Self::Root)
}
pub fn bookmarks(pattern: StringPattern) -> Rc<Self> { pub fn bookmarks(pattern: StringPattern) -> Rc<Self> {
Rc::new(Self::CommitRef(RevsetCommitRef::Bookmarks(pattern))) Rc::new(Self::CommitRef(RevsetCommitRef::Bookmarks(pattern)))
} }
@ -307,7 +320,10 @@ impl RevsetExpression {
pub fn git_head() -> Rc<Self> { pub fn git_head() -> Rc<Self> {
Rc::new(Self::CommitRef(RevsetCommitRef::GitHead)) Rc::new(Self::CommitRef(RevsetCommitRef::GitHead))
} }
}
// Compound expression
impl RevsetExpression {
pub fn latest(self: &Rc<Self>, count: usize) -> Rc<Self> { pub fn latest(self: &Rc<Self>, count: usize) -> Rc<Self> {
Rc::new(Self::Latest { Rc::new(Self::Latest {
candidates: self.clone(), candidates: self.clone(),
@ -315,15 +331,6 @@ impl RevsetExpression {
}) })
} }
pub fn filter(predicate: RevsetFilterPredicate) -> Rc<Self> {
Rc::new(Self::Filter(predicate))
}
/// Find any empty commits.
pub fn is_empty() -> Rc<Self> {
Self::filter(RevsetFilterPredicate::File(FilesetExpression::all())).negated()
}
/// Commits in `self` that don't have descendants in `self`. /// Commits in `self` that don't have descendants in `self`.
pub fn heads(self: &Rc<Self>) -> Rc<Self> { pub fn heads(self: &Rc<Self>) -> Rc<Self> {
Rc::new(Self::Heads(self.clone())) Rc::new(Self::Heads(self.clone()))
@ -386,6 +393,7 @@ impl RevsetExpression {
pub fn filtered(self: &Rc<Self>, predicate: RevsetFilterPredicate) -> Rc<Self> { pub fn filtered(self: &Rc<Self>, predicate: RevsetFilterPredicate) -> Rc<Self> {
self.intersection(&Self::filter(predicate)) self.intersection(&Self::filter(predicate))
} }
/// Commits that are descendants of `self` and ancestors of `heads`, both /// Commits that are descendants of `self` and ancestors of `heads`, both
/// inclusive. /// inclusive.
pub fn dag_range_to(self: &Rc<Self>, heads: &Rc<Self>) -> Rc<Self> { pub fn dag_range_to(self: &Rc<Self>, heads: &Rc<Self>) -> Rc<Self> {
@ -470,7 +478,9 @@ impl RevsetExpression {
} }
} }
} }
}
impl RevsetExpression {
/// Returns symbol string if this expression is of that type. /// Returns symbol string if this expression is of that type.
pub fn as_symbol(&self) -> Option<&str> { pub fn as_symbol(&self) -> Option<&str> {
match self { match self {