From 96b839a5e872e452382a0878ff9dc8ec6935bda5 Mon Sep 17 00:00:00 2001 From: Christoph Koehler Date: Sun, 31 Mar 2024 19:40:19 -0600 Subject: [PATCH] revset: add working_copies() function It includes the working copy commit of every workspace of the repo. Implements #3384 --- CHANGELOG.md | 2 ++ docs/revsets.md | 2 ++ lib/src/revset.rs | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d93e165f5..2216ace5ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `--all` is now named `--all-remotes` for `jj branch list` +* new function `working_copies()` for revsets to show the working copy commits of all workspaces. + ### Fixed bugs ## [0.15.1] - 2024-03-06 diff --git a/docs/revsets.md b/docs/revsets.md index 2f947c6321..26319bc393 100644 --- a/docs/revsets.md +++ b/docs/revsets.md @@ -171,6 +171,8 @@ given [string pattern](#string-patterns). * `present(x)`: Same as `x`, but evaluated to `none()` if any of the commits in `x` doesn't exist (e.g. is an unknown branch name.) +* `working_copies()`: The working copy commits across all the workspaces. + ## String patterns Functions that perform string matching support the following pattern syntax: diff --git a/lib/src/revset.rs b/lib/src/revset.rs index de61b438cc..0e94c27adb 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -275,6 +275,7 @@ pub const GENERATION_RANGE_EMPTY: Range = 0..0; #[derive(Clone, Debug, Eq, PartialEq)] pub enum RevsetCommitRef { WorkingCopy(WorkspaceId), + WorkingCopies(), Symbol(String), RemoteSymbol { name: String, @@ -371,6 +372,10 @@ impl RevsetExpression { ))) } + pub fn working_copies() -> Rc { + Rc::new(RevsetExpression::CommitRef(RevsetCommitRef::WorkingCopies())) + } + pub fn symbol(value: String) -> Rc { Rc::new(RevsetExpression::CommitRef(RevsetCommitRef::Symbol(value))) } @@ -1157,6 +1162,10 @@ static BUILTIN_FUNCTION_MAP: Lazy> = 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)?; @@ -2139,6 +2148,15 @@ fn resolve_commit_ref( }) } } + RevsetCommitRef::WorkingCopies() => { + let wc_commits: Vec = 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) => {