History

[pack] write packs to a directory with the proper name

Sebastian Thiel committed 5 years ago

Commit 3fbca7d1 parent f10adea8 files · +31 −25Browse files

Showing the changes to gitoxide-core/src (1 of 8 files). Show all

Unified · Split

gitoxide-core/src/pack/create.rs+6−4
@@ -74,7 +74,7 @@ pub fn create( · 73 unmodified lines
7474 repository: impl AsRef<Path>,
7575 tips: impl IntoIterator<Item = impl AsRef<OsStr>>,
7676 input: Option<impl io::BufRead + Send + 'static>,
77− out: impl io::Write,
77+ output_directory: impl AsRef<Path>,
7878 mut progress: impl Progress,
7979 ctx: Context,
8080 ) -> anyhow::Result<()> {
@@ -154,25 +154,27 @@ pub fn create( · 73 unmodified lines
154154 write_progress.init(None, progress::bytes());
155155 let start = Instant::now();
156156
157+ let mut pack_file = tempfile::NamedTempFile::new_in(&output_directory)?;
157158 let mut output_iter = pack::data::output::bytes::FromEntriesIter::new(
158159 entries.inspect(|e| {
159160 if let Ok(entries) = e {
160161 entries_progress.inc_by(entries.len())
161162 }
162163 }),
163− out,
164+ &mut pack_file,
164165 num_objects as u32,
165166 pack::data::Version::default(),
166167 hash::Kind::default(),
167168 );
168− while let Some(io_res) = output_iter.next() {
169+ for io_res in output_iter.by_ref() {
169170 if interrupt::is_triggered() {
170171 bail!("Cancelled by user")
171172 }
172173 let written = io_res?;
173174 write_progress.inc_by(written as usize);
174175 }
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)))?;
176178
177179 write_progress.show_throughput(start);
178180 entries_progress.show_throughput(start);