Skip to content

Commit

Permalink
revset: add working_copies() function
Browse files Browse the repository at this point in the history
It includes the working copy commit of every workspace of the repo.

Implements #3384
  • Loading branch information
ckoehler committed Apr 1, 2024
1 parent 2dc95bb commit d77c841
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub const GENERATION_RANGE_EMPTY: Range<u64> = 0..0;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum RevsetCommitRef {
WorkingCopy(WorkspaceId),
WorkingCopies(),
Symbol(String),
RemoteSymbol {
name: String,
Expand Down Expand Up @@ -371,6 +372,10 @@ impl RevsetExpression {
)))
}

pub fn working_copies() -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::CommitRef(RevsetCommitRef::WorkingCopies()))
}

pub fn symbol(value: String) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::CommitRef(RevsetCommitRef::Symbol(value)))
}
Expand Down Expand Up @@ -1157,6 +1162,10 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, RevsetFunction>> = Lazy:
expect_no_arguments(name, arguments_pair)?;
Ok(RevsetExpression::all())
});
map.insert("working_copies", |name, arguments_pair, _state| {
expect_no_arguments(name, arguments_pair)?;
Ok(RevsetExpression::working_copies())
});
map.insert("heads", |name, arguments_pair, state| {
let arg = expect_one_argument(name, arguments_pair)?;
let candidates = parse_expression_rule(arg.into_inner(), state)?;
Expand Down Expand Up @@ -2139,6 +2148,15 @@ fn resolve_commit_ref(
})
}
}
RevsetCommitRef::WorkingCopies() => {
let wc_commits: Vec<CommitId> = repo
.view()
.wc_commit_ids()
.iter()
.map(|(_, v)| v.clone())
.collect();
Ok(wc_commits)
}
RevsetCommitRef::VisibleHeads => Ok(repo.view().heads().iter().cloned().collect_vec()),
RevsetCommitRef::Root => Ok(vec![repo.store().root_commit_id().clone()]),
RevsetCommitRef::Branches(pattern) => {
Expand Down

0 comments on commit d77c841

Please sign in to comment.