Skip to content

Commit

Permalink
Avoid MaybeUninit in OdbPackwriter, too
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Feb 14, 2023
1 parent a3067e7 commit f36cf67
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/odb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::io;
use std::marker;
use std::mem::MaybeUninit;
use std::ptr;
use std::slice;

Expand Down Expand Up @@ -162,7 +161,6 @@ impl<'repo> Odb<'repo> {
/// Create stream for writing a pack file to the ODB
pub fn packwriter(&self) -> Result<OdbPackwriter<'_>, Error> {
let mut out = ptr::null_mut();
let progress = MaybeUninit::uninit();
let progress_cb: raw::git_indexer_progress_cb = Some(write_pack_progress_cb);
let progress_payload = Box::new(OdbPackwriterCb { cb: None });
let progress_payload_ptr = Box::into_raw(progress_payload);
Expand All @@ -178,7 +176,7 @@ impl<'repo> Odb<'repo> {

Ok(OdbPackwriter {
raw: out,
progress,
progress: Default::default(),
progress_payload_ptr,
})
}
Expand Down Expand Up @@ -445,7 +443,7 @@ pub(crate) struct OdbPackwriterCb<'repo> {
/// A stream to write a packfile to the ODB
pub struct OdbPackwriter<'repo> {
raw: *mut raw::git_odb_writepack,
progress: MaybeUninit<raw::git_indexer_progress>,
progress: raw::git_indexer_progress,
progress_payload_ptr: *mut OdbPackwriterCb<'repo>,
}

Expand All @@ -455,7 +453,7 @@ impl<'repo> OdbPackwriter<'repo> {
unsafe {
let writepack = &*self.raw;
let res = match writepack.commit {
Some(commit) => commit(self.raw, self.progress.as_mut_ptr()),
Some(commit) => commit(self.raw, &mut self.progress),
None => -1,
};

Expand Down Expand Up @@ -489,7 +487,7 @@ impl<'repo> io::Write for OdbPackwriter<'repo> {

let writepack = &*self.raw;
let res = match writepack.append {
Some(append) => append(self.raw, ptr, len, self.progress.as_mut_ptr()),
Some(append) => append(self.raw, ptr, len, &mut self.progress),
None => -1,
};

Expand Down

0 comments on commit f36cf67

Please sign in to comment.