From a5b79f9b0ed96eae73a3b0f45cee67b240374e16 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 22 Mar 2023 22:14:03 -0700 Subject: [PATCH] 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. --- lib/src/default_index_store.rs | 12 ++++++------ lib/src/index.rs | 2 +- src/commands/mod.rs | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index 1dc1e8a6b..38b98c391 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -724,7 +724,7 @@ impl Index for MutableIndexImpl { CompositeIndex(self).heads(candidates) } - fn topo_order(&self, input: &mut dyn Iterator) -> Vec { + fn topo_order(&self, input: &mut dyn Iterator) -> Vec { CompositeIndex(self).topo_order(input) } @@ -1109,10 +1109,10 @@ impl<'a> CompositeIndex<'a> { } /// Parents before children - fn topo_order(&self, input: &mut dyn Iterator) -> Vec> { - 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) -> Vec { + 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) -> Vec { + fn topo_order(&self, input: &mut dyn Iterator) -> Vec { CompositeIndex(self).topo_order(input) } diff --git a/lib/src/index.rs b/lib/src/index.rs index c6d1fa0e7..e9cc3964f 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -67,7 +67,7 @@ pub trait Index: Send + Sync { fn heads(&self, candidates: &mut dyn Iterator) -> Vec; /// Parents before children - fn topo_order(&self, input: &mut dyn Iterator) -> Vec; + fn topo_order(&self, input: &mut dyn Iterator) -> Vec; // 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 diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 0bd6c56c9..7207b13f6 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -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.