Skip to content

Commit 3e2c8ce

Browse files
committed
Expose git_packbuilder_write fn
1 parent 1742e6b commit 3e2c8ce

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: src/packbuilder.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use libc::{c_int, c_uint, c_void, size_t};
22
use std::marker;
3+
use std::path::Path;
34
use std::ptr;
45
use std::slice;
56
use std::str;
67

8+
use crate::odb::{write_pack_progress_cb, OdbPackwriterCb};
79
use crate::util::Binding;
10+
use crate::IntoCString;
811
use crate::{panic, raw, Buf, Error, Oid, Repository, Revwalk};
912

1013
#[derive(PartialEq, Eq, Clone, Debug, Copy)]
@@ -84,6 +87,27 @@ impl<'repo> PackBuilder<'repo> {
8487
Ok(())
8588
}
8689

90+
/// Write the contents of the packfile to the specified path. The contents
91+
/// of the buffer will become a valid packfile, even though there will be
92+
/// no attached index.
93+
pub fn write(&mut self, path: &Path, mode: u32) -> Result<(), Error> {
94+
let path = path.into_c_string()?;
95+
let progress_cb: raw::git_indexer_progress_cb = Some(write_pack_progress_cb);
96+
let progress_payload = Box::new(OdbPackwriterCb { cb: None });
97+
let progress_payload_ptr = Box::into_raw(progress_payload);
98+
99+
unsafe {
100+
try_call!(raw::git_packbuilder_write(
101+
self.raw,
102+
path,
103+
mode,
104+
progress_cb,
105+
progress_payload_ptr as *mut _
106+
));
107+
}
108+
Ok(())
109+
}
110+
87111
/// Create the new pack and pass each object to the callback.
88112
pub fn foreach<F>(&mut self, mut cb: F) -> Result<(), Error>
89113
where

0 commit comments

Comments
 (0)