index: make topo_order() return commit ids instead of index entries

`IndexEntry` is specific to the default index store; we don't want it
in the interface.
This commit is contained in:
Martin von Zweigbergk 2023-03-22 22:14:03 -07:00 committed by Martin von Zweigbergk
parent 772cb1a0e9
commit a5b79f9b0e
3 changed files with 7 additions and 8 deletions

View file

@ -724,7 +724,7 @@ impl Index for MutableIndexImpl {
CompositeIndex(self).heads(candidates)
}
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
CompositeIndex(self).topo_order(input)
}
@ -1109,10 +1109,10 @@ impl<'a> CompositeIndex<'a> {
}
/// Parents before children
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry<'a>> {
let mut entries_by_generation = input.map(|id| self.entry_by_id(id).unwrap()).collect_vec();
entries_by_generation.sort_unstable_by_key(|e| e.pos);
entries_by_generation
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
let mut ids = input.cloned().collect_vec();
ids.sort_by_cached_key(|id| self.commit_id_to_pos(id).unwrap());
ids
}
}
@ -1802,7 +1802,7 @@ impl Index for ReadonlyIndexImpl {
CompositeIndex(self).heads(candidates)
}
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
CompositeIndex(self).topo_order(input)
}

View file

@ -67,7 +67,7 @@ pub trait Index: Send + Sync {
fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId>;
/// Parents before children
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry>;
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId>;
// TODO: It's weird that we pass in the repo here since the repo is a
// higher-level concept. We should probably pass in the view and store

View file

@ -1902,7 +1902,6 @@ fn cmd_duplicate(
.index()
.topo_order(&mut to_duplicate.iter().map(|c| c.id()))
.into_iter()
.map(|index_entry| index_entry.commit_id())
{
// Topological order ensures that any parents of `original_commit` are
// either not in `to_duplicate` or were already duplicated.