From aebdd4e8fd1fc788c53f0eee19863d2ee43dce12 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 13 Oct 2021 09:12:50 -0700 Subject: [PATCH] revset: add all() function --- lib/src/revset.rs | 10 ++++++++++ lib/tests/test_revset.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 54113b49d..91e54cfb7 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -562,6 +562,16 @@ fn parse_function_expression( }) } } + "all" => { + if arg_count == 0 { + Ok(RevsetExpression::all()) + } else { + Err(RevsetParseError::InvalidFunctionArguments { + name, + message: "Expected 0 arguments".to_string(), + }) + } + } "heads" => { if arg_count == 0 { Ok(RevsetExpression::heads()) diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 1aa063eb2..c688ad06b 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -775,6 +775,37 @@ fn test_evaluate_expression_none(use_git: bool) { assert_eq!(resolve_commit_ids(repo.as_repo_ref(), "none()"), vec![]); } +#[test_case(false ; "local backend")] +#[test_case(true ; "git backend")] +fn test_evaluate_expression_all(use_git: bool) { + let settings = testutils::user_settings(); + let (_temp_dir, repo) = testutils::init_repo(&settings, use_git); + + let mut tx = repo.start_transaction("test"); + let mut_repo = tx.mut_repo(); + let root_commit = repo.store().root_commit(); + let wc_commit = repo.working_copy_locked().current_commit(); + let mut graph_builder = CommitGraphBuilder::new(&settings, mut_repo); + let commit1 = graph_builder.initial_commit(); + let commit2 = graph_builder.commit_with_parents(&[&commit1]); + let commit3 = graph_builder.commit_with_parents(&[&commit1]); + let commit4 = graph_builder.commit_with_parents(&[&commit2, &commit3]); + + assert_eq!( + resolve_commit_ids(mut_repo.as_repo_ref(), "all()"), + vec![ + commit4.id().clone(), + commit3.id().clone(), + commit2.id().clone(), + commit1.id().clone(), + wc_commit.id().clone(), + root_commit.id().clone(), + ] + ); + + tx.discard(); +} + #[test_case(false ; "local backend")] #[test_case(true ; "git backend")] fn test_evaluate_expression_heads(use_git: bool) {