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