From 5b568cabcc3ac70bb3a3abf436fe78110d8f40ee Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 23 May 2023 17:59:45 +0900 Subject: [PATCH] revset: add iterator of (CommitId, ChangeId) pairs, use it in id_index There are a few more places where we need these pairs. --- lib/src/default_revset_engine.rs | 8 ++++++++ lib/src/id_prefix.rs | 11 ++++------- lib/src/revset.rs | 3 +++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/src/default_revset_engine.rs b/lib/src/default_revset_engine.rs index 9d78225c2..eaa6034c6 100644 --- a/lib/src/default_revset_engine.rs +++ b/lib/src/default_revset_engine.rs @@ -93,6 +93,14 @@ impl<'index> Revset<'index> for RevsetImpl<'index> { Box::new(self.inner.iter().map(|index_entry| index_entry.commit_id())) } + fn commit_change_ids(&self) -> Box + '_> { + Box::new( + self.inner + .iter() + .map(|index_entry| (index_entry.commit_id(), index_entry.change_id())), + ) + } + fn iter_graph(&self) -> Box)> + '_> { Box::new(RevsetGraphIterator::new(self.inner.iter())) } diff --git a/lib/src/id_prefix.rs b/lib/src/id_prefix.rs index e38088ea5..2c1357f0d 100644 --- a/lib/src/id_prefix.rs +++ b/lib/src/id_prefix.rs @@ -20,7 +20,7 @@ use crate::backend::{self, ChangeId, CommitId, ObjectId}; use crate::index::{HexPrefix, PrefixResolution}; use crate::op_store::WorkspaceId; use crate::repo::Repo; -use crate::revset::{DefaultSymbolResolver, RevsetExpression, RevsetIteratorExt}; +use crate::revset::{DefaultSymbolResolver, RevsetExpression}; struct PrefixDisambiguationError; @@ -48,14 +48,11 @@ impl DisambiguationData { .evaluate(repo) .map_err(|_| PrefixDisambiguationError)?; - // TODO: We should be able to get the change IDs from the revset, without having - // to read the whole commit objects let mut commit_id_vec = vec![]; let mut change_id_vec = vec![]; - for commit in revset.iter().commits(repo.store()) { - let commit = commit.map_err(|_| PrefixDisambiguationError)?; - commit_id_vec.push((commit.id().clone(), ())); - change_id_vec.push((commit.change_id().clone(), commit.id().clone())); + for (commit_id, change_id) in revset.commit_change_ids() { + commit_id_vec.push((commit_id.clone(), ())); + change_id_vec.push((change_id, commit_id)); } Ok(Indexes { commit_index: IdIndex::from_vec(commit_id_vec), diff --git a/lib/src/revset.rs b/lib/src/revset.rs index e7b4f201c..08f155334 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -2029,6 +2029,9 @@ pub trait Revset<'index>: fmt::Debug { /// Iterate in topological order with children before parents. fn iter(&self) -> Box + '_>; + /// Iterates commit/change id pairs in topological order. + fn commit_change_ids(&self) -> Box + '_>; + fn iter_graph(&self) -> Box)> + '_>; fn change_id_index(&self) -> Box;