From 1508f285672172608fc5a54d9d642d44b58c1204 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 7 Jan 2024 06:37:39 -0800 Subject: [PATCH] tests: update ChangeIdIndex test to include ancestors in set I plan to replace `Revset::change_id_index()` by `Index::change_id_index(heads)`, but one of the tests currently uses a set of commits that does not include ancestors. This patch updates it to include ancestors (and changes the set of heads to keep the set small enough for the test). --- lib/tests/test_revset.rs | 49 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 83f41a11f..a32365acb 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -2805,30 +2805,26 @@ fn test_change_id_index() { .write() .unwrap() }; - let commit_1 = commit_with_change_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + let commit_1 = commit_with_change_id("abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); let commit_2 = commit_with_change_id("aaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); - let commit_3 = commit_with_change_id("abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); + let commit_3 = commit_with_change_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); let commit_4 = commit_with_change_id("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); let commit_5 = commit_with_change_id("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); - let revset = revset_for_commits( - tx.repo(), - &[ - &root_commit, - &commit_1, - &commit_2, - &commit_3, - &commit_4, - &commit_5, - ], - ); - let change_id_index = revset.change_id_index(); + let index_for_heads = |commits: &[&Commit]| { + RevsetExpression::commits(commits.iter().map(|commit| commit.id().clone()).collect()) + .ancestors() + .evaluate_programmatic(tx.repo()) + .unwrap() + .change_id_index() + }; + let change_id_index = index_for_heads(&[&commit_1, &commit_2, &commit_3, &commit_4, &commit_5]); let prefix_len = |commit: &Commit| change_id_index.shortest_unique_prefix_len(commit.change_id()); assert_eq!(prefix_len(&root_commit), 1); - assert_eq!(prefix_len(&commit_1), 6); + assert_eq!(prefix_len(&commit_1), 2); assert_eq!(prefix_len(&commit_2), 6); - assert_eq!(prefix_len(&commit_3), 2); + assert_eq!(prefix_len(&commit_3), 6); assert_eq!(prefix_len(&commit_4), 1); assert_eq!(prefix_len(&commit_5), 1); let resolve_prefix = @@ -2843,7 +2839,7 @@ fn test_change_id_index() { ); assert_eq!( resolve_prefix("aaaaaa"), - PrefixResolution::SingleMatch(vec![commit_1.id().clone()]) + PrefixResolution::SingleMatch(vec![commit_3.id().clone()]) ); assert_eq!( resolve_prefix("aaaaab"), @@ -2851,7 +2847,7 @@ fn test_change_id_index() { ); assert_eq!( resolve_prefix("ab"), - PrefixResolution::SingleMatch(vec![commit_3.id().clone()]) + PrefixResolution::SingleMatch(vec![commit_1.id().clone()]) ); assert_eq!( resolve_prefix("b"), @@ -2860,32 +2856,35 @@ fn test_change_id_index() { // Longer than necessary assert_eq!( resolve_prefix("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), - PrefixResolution::SingleMatch(vec![commit_1.id().clone()]) + PrefixResolution::SingleMatch(vec![commit_3.id().clone()]) ); // No match assert_eq!(resolve_prefix("ba"), PrefixResolution::NoMatch); // Test with a revset containing only some of the commits. We should get shorter // prefixes and be able to resolve shorter prefixes. - let revset = revset_for_commits(tx.repo(), &[&commit_2, &commit_3]); - let change_id_index = revset.change_id_index(); + let change_id_index = index_for_heads(&[&commit_1, &commit_2]); let prefix_len = |commit: &Commit| change_id_index.shortest_unique_prefix_len(commit.change_id()); - assert_eq!(prefix_len(&commit_1), 6); + assert_eq!(prefix_len(&commit_1), 2); assert_eq!(prefix_len(&commit_2), 2); - assert_eq!(prefix_len(&commit_3), 2); + assert_eq!(prefix_len(&commit_3), 6); let resolve_prefix = |prefix: &str| change_id_index.resolve_prefix(&HexPrefix::new(prefix).unwrap()); - assert_eq!(resolve_prefix("0"), PrefixResolution::NoMatch); + assert_eq!( + resolve_prefix("0"), + PrefixResolution::SingleMatch(vec![root_commit.id().clone()]) + ); assert_eq!( resolve_prefix("aa"), PrefixResolution::SingleMatch(vec![commit_2.id().clone()]) ); assert_eq!( resolve_prefix("ab"), - PrefixResolution::SingleMatch(vec![commit_3.id().clone()]) + PrefixResolution::SingleMatch(vec![commit_1.id().clone()]) ); assert_eq!(resolve_prefix("a"), PrefixResolution::AmbiguousMatch); + assert_eq!(resolve_prefix("b"), PrefixResolution::NoMatch); } #[test]