From 4f59b82eba247dcdf79df6e70f3026d90884a6db Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Fri, 28 Jun 2024 15:35:13 -0700 Subject: [PATCH] Fix #2476, change ids --- lib/src/id_prefix.rs | 15 ++++++++------- lib/tests/test_id_prefix.rs | 9 ++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/src/id_prefix.rs b/lib/src/id_prefix.rs index f3a47e706d..5f8fd2ea36 100644 --- a/lib/src/id_prefix.rs +++ b/lib/src/id_prefix.rs @@ -168,13 +168,14 @@ impl IdPrefixContext { prefix: &HexPrefix, ) -> PrefixResolution> { if let Some(indexes) = self.disambiguation_indexes(repo) { - let resolution = indexes.change_index.resolve_prefix_with( - &*indexes.commit_change_ids, - prefix, - |(commit_id, _)| commit_id.clone(), - ); - if let PrefixResolution::SingleMatch((_, ids)) = resolution { - return PrefixResolution::SingleMatch(ids); + let resolution = indexes + .change_index + .resolve_prefix_to_key(&*indexes.commit_change_ids, prefix); + if let PrefixResolution::SingleMatch(change_id) = resolution { + // There may be more commits with this change id outside the narrower sets. + return PrefixResolution::SingleMatch(repo.resolve_change_id(&change_id).expect( + "Change ids present in narrower search set should be present globally.", + )); } } repo.resolve_change_id_prefix(prefix) diff --git a/lib/tests/test_id_prefix.rs b/lib/tests/test_id_prefix.rs index f80c8a52c3..682f43b613 100644 --- a/lib/tests/test_id_prefix.rs +++ b/lib/tests/test_id_prefix.rs @@ -377,10 +377,13 @@ fn test_id_prefix_divergent() { SingleMatch(vec![first_commit.id().clone()]) ); // Short prefix does not find the first commit. (This is correct) - // TODO(#2476): Looking up the divergent commits by their change id prefix only - // finds the id within the lookup set. + // We find both commits with this change ids, even though + // `third_commit_divergent_with_second` is not in the short prefix set (#2476). assert_eq!( c.resolve_change_prefix(repo.as_ref(), &prefix("7")), - SingleMatch(vec![second_commit.id().clone()]) + SingleMatch(vec![ + second_commit.id().clone(), + third_commit_divergent_with_second.id().clone() + ]) ); }