From fa6b14f166d0ad0c0c84a7b693377a9bb30c2f9e Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 13 Apr 2022 13:27:00 -0700 Subject: [PATCH] revset: rename internal `head()` to `visible_heads()` --- lib/src/revset.rs | 38 ++++++++++++++++++-------------------- lib/tests/test_revset.rs | 4 ++-- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index c1347e0a8..cfc02f82f 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -213,8 +213,8 @@ pub enum RevsetExpression { roots: Rc, heads: Rc, }, - Heads, - HeadsOf(Rc), + VisibleHeads, + Heads(Rc), PublicHeads, Branches, RemoteBranches, @@ -250,7 +250,7 @@ impl RevsetExpression { } pub fn all() -> Rc { - RevsetExpression::heads().ancestors() + RevsetExpression::visible_heads().ancestors() } pub fn symbol(value: String) -> Rc { @@ -265,8 +265,8 @@ impl RevsetExpression { Rc::new(RevsetExpression::Commits(commit_ids)) } - pub fn heads() -> Rc { - Rc::new(RevsetExpression::Heads) + pub fn visible_heads() -> Rc { + Rc::new(RevsetExpression::VisibleHeads) } pub fn public_heads() -> Rc { @@ -294,10 +294,8 @@ impl RevsetExpression { } /// Commits in `self` that don't have descendants in `self`. - // TODO: Perhaps this should be renamed to just `heads()` and the current - // `heads()` should become `visible_heads()` or `current_heads()`. - pub fn heads_of(self: &Rc) -> Rc { - Rc::new(RevsetExpression::HeadsOf(self.clone())) + pub fn heads(self: &Rc) -> Rc { + Rc::new(RevsetExpression::Heads(self.clone())) } /// Parents of `self`. @@ -317,7 +315,7 @@ impl RevsetExpression { /// Descendants of `self`, including `self`. pub fn descendants(self: &Rc) -> Rc { - self.dag_range_to(&RevsetExpression::heads()) + self.dag_range_to(&RevsetExpression::visible_heads()) } /// Commits that are descendants of `self` and ancestors of `heads`, both @@ -481,7 +479,7 @@ fn parse_range_expression_rule( parse_neighbors_expression_rule(heads_pair.into_inner())?; expression = expression.range(&heads_expression); } else { - expression = expression.range(&RevsetExpression::heads()); + expression = expression.range(&RevsetExpression::visible_heads()); } } _ => { @@ -624,11 +622,11 @@ fn parse_function_expression( } "heads" => { if arg_count == 0 { - Ok(RevsetExpression::heads()) + Ok(RevsetExpression::visible_heads()) } else if arg_count == 1 { let candidates = parse_expression_rule(argument_pairs.next().unwrap().into_inner())?; - Ok(candidates.heads_of()) + Ok(candidates.heads()) } else { Err(RevsetParseError::InvalidFunctionArguments { name, @@ -1157,11 +1155,11 @@ pub fn evaluate_expression<'repo>( index_entries: result, })) } - RevsetExpression::Heads => Ok(revset_for_commit_ids( + RevsetExpression::VisibleHeads => Ok(revset_for_commit_ids( repo, &repo.view().heads().iter().cloned().collect_vec(), )), - RevsetExpression::HeadsOf(candidates) => { + RevsetExpression::Heads(candidates) => { let candidate_set = candidates.evaluate(repo, workspace_id)?; let candidate_ids = candidate_set.iter().commit_ids().collect_vec(); Ok(revset_for_commit_ids( @@ -1324,8 +1322,8 @@ mod tests { Rc::new(RevsetExpression::Symbol("@".to_string())) ); assert_eq!( - checkout_symbol.heads_of(), - Rc::new(RevsetExpression::HeadsOf(checkout_symbol.clone())) + checkout_symbol.heads(), + Rc::new(RevsetExpression::Heads(checkout_symbol.clone())) ); assert_eq!( checkout_symbol.parents(), @@ -1343,7 +1341,7 @@ mod tests { foo_symbol.descendants(), Rc::new(RevsetExpression::DagRange { roots: foo_symbol.clone(), - heads: RevsetExpression::heads(), + heads: RevsetExpression::visible_heads(), }) ); assert_eq!( @@ -1438,7 +1436,7 @@ mod tests { assert_eq!(parse("..@"), Ok(checkout_symbol.ancestors())); assert_eq!( parse("@.."), - Ok(checkout_symbol.range(&RevsetExpression::heads())) + Ok(checkout_symbol.range(&RevsetExpression::visible_heads())) ); assert_eq!(parse("foo..bar"), Ok(foo_symbol.range(&bar_symbol))); // Parse the "intersection" operator @@ -1461,7 +1459,7 @@ mod tests { Ok(RevsetExpression::symbol("arg2".to_string()) .with_description("arg1".to_string()) .minus(&RevsetExpression::symbol("arg1".to_string()).parents()) - .minus(&RevsetExpression::heads())) + .minus(&RevsetExpression::visible_heads())) ); } diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 81d4b4465..deb71eaca 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -462,7 +462,7 @@ fn test_evaluate_expression_root_and_checkout(use_git: bool) { #[test_case(false ; "local backend")] #[test_case(true ; "git backend")] -fn test_evaluate_expression_heads_of(use_git: bool) { +fn test_evaluate_expression_heads(use_git: bool) { let settings = testutils::user_settings(); let test_repo = testutils::init_repo(&settings, use_git); let repo = &test_repo.repo; @@ -896,7 +896,7 @@ fn test_evaluate_expression_all(use_git: bool) { #[test_case(false ; "local backend")] #[test_case(true ; "git backend")] -fn test_evaluate_expression_heads(use_git: bool) { +fn test_evaluate_expression_visible_heads(use_git: bool) { let settings = testutils::user_settings(); let test_repo = testutils::init_repo(&settings, use_git); let repo = &test_repo.repo;