1use std::{io, time::Instant};
2
3use git_features::progress::{self, Progress};
4
5pub(crate) fn index_entries_sorted_by_offset_ascending(
6 idx: &crate::index::File,
7 mut progress: impl Progress,
8) -> Vec<crate::index::Entry> {
9 progress.init(Some(idx.num_objects as usize), progress::count("entries"));
10 let start = Instant::now();
11
12 let mut v = Vec::with_capacity(idx.num_objects as usize);
13 for entry in idx.iter() {
14 v.push(entry);
15 progress.inc();
16 }
17 v.sort_by_key(|e| e.pack_offset);
18
19 progress.show_throughput(start);
20 v
21}
22
23pub(crate) struct Count<W> {
24 pub bytes: u64,
25 pub inner: W,
26}
27
28impl<W> Count<W> {
29 pub fn new(inner: W) -> Self {
30 Count { bytes: 0, inner }
31 }
32}
33
34impl<W> io::Write for Count<W>
35where
36 W: io::Write,
37{
38 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
39 let written = self.inner.write(buf)?;
40 self.bytes += written as u64;
41 Ok(written)
42 }
43
44 fn flush(&mut self) -> io::Result<()> {
45 self.inner.flush()
46 }
47}