From 13a000caa70cb5be2a6742d58c7f4ada453a925c Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 20 Mar 2023 16:19:19 -0700 Subject: [PATCH] repo: get change id index from revset also for mutable repo I don't know if we ever resolve revsets in a mutable repo, but now that we can get a change id index from a revset, it's easier to implement this functionality that way. --- lib/src/repo.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 53b1a9deb..80ee50b95 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1158,29 +1158,15 @@ impl Repo for MutableRepo { } fn resolve_change_id_prefix(&self, prefix: &HexPrefix) -> PrefixResolution> { - // TODO: Create a persistent lookup from change id to (visible?) commit ids. - let mut found_change_id = None; - let mut found_commits = vec![]; - let heads = self.view().heads().iter().cloned().collect_vec(); - for entry in self.index().walk_revs(&heads, &[]) { - let change_id = entry.change_id(); - if prefix.matches(&change_id) { - if let Some(previous_change_id) = found_change_id.replace(change_id.clone()) { - if previous_change_id != change_id { - return PrefixResolution::AmbiguousMatch; - } - } - found_commits.push(entry.commit_id()); - } - } - if found_change_id.is_none() { - return PrefixResolution::NoMatch; - } - PrefixResolution::SingleMatch(found_commits) + let revset = RevsetExpression::all().evaluate(self).unwrap(); + let change_id_index = revset.change_id_index(); + change_id_index.resolve_prefix(prefix) } fn shortest_unique_change_id_prefix_len(&self, target_id: &ChangeId) -> usize { - target_id.as_bytes().len() * 2 // TODO + let revset = RevsetExpression::all().evaluate(self).unwrap(); + let change_id_index = revset.change_id_index(); + change_id_index.shortest_unique_prefix_len(target_id) } }