Showing the changes to gitoxide-core/src (1 of 8 files). Show all
Unified · Split
| @@ -74,7 +74,7 @@ pub fn create( · 73 unmodified lines | ||
| 74 | 74 | repository: impl AsRef<Path>, |
| 75 | 75 | tips: impl IntoIterator<Item = impl AsRef<OsStr>>, |
| 76 | 76 | input: Option<impl io::BufRead + Send + 'static>, |
| 77 | − out: impl io::Write, | |
| 77 | + output_directory: impl AsRef<Path>, | |
| 78 | 78 | mut progress: impl Progress, |
| 79 | 79 | ctx: Context, |
| 80 | 80 | ) -> anyhow::Result<()> { |
| @@ -154,25 +154,27 @@ pub fn create( · 73 unmodified lines | ||
| 154 | 154 | write_progress.init(None, progress::bytes()); |
| 155 | 155 | let start = Instant::now(); |
| 156 | 156 | |
| 157 | + let mut pack_file = tempfile::NamedTempFile::new_in(&output_directory)?; | |
| 157 | 158 | let mut output_iter = pack::data::output::bytes::FromEntriesIter::new( |
| 158 | 159 | entries.inspect(|e| { |
| 159 | 160 | if let Ok(entries) = e { |
| 160 | 161 | entries_progress.inc_by(entries.len()) |
| 161 | 162 | } |
| 162 | 163 | }), |
| 163 | − out, | |
| 164 | + &mut pack_file, | |
| 164 | 165 | num_objects as u32, |
| 165 | 166 | pack::data::Version::default(), |
| 166 | 167 | hash::Kind::default(), |
| 167 | 168 | ); |
| 168 | − while let Some(io_res) = output_iter.next() { | |
| 169 | + for io_res in output_iter.by_ref() { | |
| 169 | 170 | if interrupt::is_triggered() { |
| 170 | 171 | bail!("Cancelled by user") |
| 171 | 172 | } |
| 172 | 173 | let written = io_res?; |
| 173 | 174 | write_progress.inc_by(written as usize); |
| 174 | 175 | } |
| 175 | − output_iter.into_write().flush()?; | |
| 176 | + let hash = output_iter.digest().expect("iteration is done"); | |
| 177 | + pack_file.persist(output_directory.as_ref().join(format!("{}.pack", hash)))?; | |
| 176 | 178 | |
| 177 | 179 | write_progress.show_throughput(start); |
| 178 | 180 | entries_progress.show_throughput(start); |