History

[pack] also put counts in order for stable packs

Sebastian Thiel committed 5 years ago

Commit f2991601 parent e7ecdc16 files · +35 −28Browse files

Unified · Split

6 files
  1. git-pack/src/data/output/count/from_objects_iter.rs +14 −10
  2. git-pack/src/data/output/entry/from_counts_iter.rs +5 −5
  3. git-pack/src/data/output/in_order.rs +8 −6
  4. git-pack/src/data/output/mod.rs +1 −1
  5. git-pack/tests/pack/data/output.rs +2 −2
  6. gitoxide-core/src/pack/create.rs +5 −4
git-pack/src/data/output/count/from_objects_iter.rs+14−10
@@ -1,4 +1,7 @@
1−use crate::{data::output, find, FindExt};
1+use crate::{
2+ data::{output, output::ChunkId},
3+ find, FindExt,
4+};
25 use dashmap::DashSet;
36 use git_features::{parallel, progress::Progress};
47 use git_hash::{oid, ObjectId};
@@ -29,7 +32,7 @@ pub fn from_objects_iter<Find, Iter, Oid, Cache>( · 24 unmodified lines
2932 input_object_expansion,
3033 chunk_size,
3134 }: Options,
32−) -> impl Iterator<Item = Result<Vec<output::Count>, Error<find::existing::Error<Find::Error>>>>
35+) -> impl Iterator<Item = Result<(ChunkId, Vec<output::Count>), Error<find::existing::Error<Find::Error>>>>
3336 + parallel::reduce::Finalize<Reduce = reduce::Statistics<Error<find::existing::Error<Find::Error>>>>
3437 where
3538 Find: crate::Find + Clone + Send + Sync + 'static,
@@ -48,7 +51,8 @@ where · 12 unmodified lines
4851 let chunks = util::Chunks {
4952 iter: objects,
5053 size: chunk_size,
51− };
54+ }
55+ .enumerate();
5256 let seen_objs = Arc::new(dashmap::DashSet::<ObjectId>::new());
5357 let progress = Arc::new(parking_lot::Mutex::new(progress));
5458
@@ -72,7 +76,7 @@ where · 17 unmodified lines
7276 },
7377 {
7478 let seen_objs = Arc::clone(&seen_objs);
75− move |oids: Vec<Oid>, (buf1, buf2, cache, progress)| {
79+ move |(chunk_id, oids): (ChunkId, Vec<Oid>), (buf1, buf2, cache, progress)| {
7680 use ObjectExpansion::*;
7781 let mut out = Vec::new();
7882 let mut tree_traversal_state = git_traverse::tree::breadthfirst::State::default();
@@ -243,7 +247,7 @@ where · 164 unmodified lines
243247 AsIs => push_obj_count_unique(&mut out, seen_objs, id, &obj, progress, stats, false),
244248 }
245249 }
246− Ok((out, outcome))
250+ Ok((chunk_id, out, outcome))
247251 }
248252 },
249253 reduce::Statistics::default(),
@@ -525,7 +529,7 @@ pub use types::{Error, ObjectExpansion, Options, Outcome}; · 275 unmodified lines
525529
526530 mod reduce {
527531 use super::Outcome;
528− use crate::data::output;
532+ use crate::data::{output, output::ChunkId};
529533 use git_features::parallel;
530534 use std::marker::PhantomData;
531535
@@ -544,16 +548,16 @@ mod reduce { · 12 unmodified lines
544548 }
545549
546550 impl<Error> parallel::Reduce for Statistics<Error> {
547− type Input = Result<(Vec<output::Count>, Outcome), Error>;
548− type FeedProduce = Vec<output::Count>;
551+ type Input = Result<(ChunkId, Vec<output::Count>, Outcome), Error>;
552+ type FeedProduce = (ChunkId, Vec<output::Count>);
549553 type Output = Outcome;
550554 type Error = Error;
551555
552556 fn feed(&mut self, item: Self::Input) -> Result<Self::FeedProduce, Self::Error> {
553− item.map(|(counts, mut stats)| {
557+ item.map(|(chunk_id, counts, mut stats)| {
554558 stats.total_objects = counts.len();
555559 self.total.aggregate(stats);
556− counts
560+ (chunk_id, counts)
557561 })
558562 }
559563
git-pack/src/data/output/entry/from_counts_iter.rs+5−5
@@ -1,4 +1,7 @@
1−use crate::{data::output, find, FindExt};
1+use crate::{
2+ data::{output, output::ChunkId},
3+ find, FindExt,
4+};
25 use git_features::{parallel, progress::Progress};
36 use std::sync::Arc;
47
@@ -185,9 +188,6 @@ mod reduce { · 180 unmodified lines
185188 mod types {
186189 use crate::data::output::entry;
187190
188− /// A counter for chunks to be able to put them back into original order later.
189− pub type ChunkId = usize;
190−
191191 /// Information gathered during the run of [`from_counts_iter()`][super::from_counts_iter()].
192192 #[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
193193 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
@@ -248,4 +248,4 @@ mod types { · 54 unmodified lines
248248 NewEntry(#[from] entry::Error),
249249 }
250250 }
251−pub use types::{ChunkId, Error, Options, Outcome};
251+pub use types::{Error, Options, Outcome};
git-pack/src/data/output/in_order.rs+8−6
@@ -1,5 +1,7 @@
1−use std::cmp::Ordering;
2−use std::collections::BTreeMap;
1+use std::{cmp::Ordering, collections::BTreeMap};
2+
3+/// A counter for chunks to be able to put them back into original order later.
4+pub type ChunkId = usize;
35
46 /// An iterator which olds iterated items with a **sequential** ID starting at 0 long enough to dispense them in order.
57 ///
@@ -8,14 +10,14 @@ use std::collections::BTreeMap; · 2 unmodified lines
810 pub struct InOrderIter<T, I> {
911 /// The iterator yielding the out-of-order elements we are to yield in order.
1012 pub inner: I,
11− store: BTreeMap<usize, T>,
12− next_chunk: usize,
13+ store: BTreeMap<ChunkId, T>,
14+ next_chunk: ChunkId,
1315 is_done: bool,
1416 }
1517
1618 impl<T, E, I> From<I> for InOrderIter<T, I>
1719 where
18− I: Iterator<Item = Result<(usize, T), E>>,
20+ I: Iterator<Item = Result<(ChunkId, T), E>>,
1921 {
2022 fn from(iter: I) -> Self {
2123 InOrderIter {
@@ -29,7 +31,7 @@ where · 7 unmodified lines
2931
3032 impl<T, E, I> Iterator for InOrderIter<T, I>
3133 where
32− I: Iterator<Item = Result<(usize, T), E>>,
34+ I: Iterator<Item = Result<(ChunkId, T), E>>,
3335 {
3436 type Item = Result<T, E>;
3537
git-pack/src/data/output/mod.rs+1−1
@@ -12,4 +12,4 @@ pub use entry::Entry; · 11 unmodified lines
1212 pub mod bytes;
1313
1414 mod in_order;
15−pub use in_order::InOrderIter;
15+pub use in_order::{ChunkId, InOrderIter};
git-pack/tests/pack/data/output.rs+2−2
@@ -50,6 +50,7 @@ mod count_and_entries { · 49 unmodified lines
5050 data::output::{db, DbKind},
5151 hex_to_id,
5252 };
53+ use git_odb::data::output::InOrderIter;
5354
5455 #[test]
5556 fn traversals() -> crate::Result {
@@ -153,8 +154,7 @@ mod count_and_entries { · 97 unmodified lines
153154 ..Default::default()
154155 },
155156 );
156− let counts: Vec<_> = counts_iter
157− .by_ref()
157+ let counts: Vec<_> = InOrderIter::from(counts_iter.by_ref())
158158 .collect::<Result<Vec<_>, _>>()?
159159 .into_iter()
160160 .flatten()
gitoxide-core/src/pack/create.rs+5−4
@@ -1,5 +1,6 @@
11 use crate::OutputFormat;
22 use anyhow::bail;
3+use git_repository::odb::data::output::InOrderIter;
34 use git_repository::{
45 hash,
56 hash::ObjectId,
@@ -117,7 +118,7 @@ where · 111 unmodified lines
117118 let counts = {
118119 let mut progress = progress.add_child("counting");
119120 progress.init(None, progress::count("objects"));
120− let mut counts_iter = pack::data::output::count::from_objects_iter(
121+ let mut in_order_counts_iter = InOrderIter::from(pack::data::output::count::from_objects_iter(
121122 Arc::clone(&db),
122123 pack::cache::lru::StaticLinkedList::<64>::default,
123124 input,
@@ -127,9 +128,9 @@ where · 3 unmodified lines
127128 chunk_size,
128129 input_object_expansion: expansion.into(),
129130 },
130− );
131+ ));
131132 let mut counts = Vec::new();
132− for c in counts_iter.by_ref() {
133+ for c in in_order_counts_iter.by_ref() {
133134 if interrupt::is_triggered() {
134135 bail!("Cancelled by user")
135136 }
@@ -137,7 +138,7 @@ where · 1 unmodified line
137138 progress.inc_by(c.len());
138139 counts.extend(c.into_iter());
139140 }
140− stats.counts = counts_iter.finalize()?;
141+ stats.counts = in_order_counts_iter.inner.finalize()?;
141142 progress.show_throughput(start);
142143 counts.shrink_to_fit();
143144 counts