11use libc::{c_char, c_int, c_uint, c_void, size_t};
2- use std::ffi::{ CStr, CString} ;
2+ use std::ffi::CStr;
33use std::mem;
44use std::ptr;
55use std::slice;
@@ -330,11 +330,7 @@ extern "C" fn credentials_cb(
330330
331331 let cred_type = CredentialType::from_bits_truncate(allowed_types as u32);
332332
333- callback(url, username_from_url, cred_type).map_err(|e| {
334- let s = CString::new(e.to_string()).unwrap();
335- raw::git_error_set_str(e.class() as c_int, s.as_ptr());
336- e.raw_code() as c_int
337- })
333+ callback(url, username_from_url, cred_type).map_err(|e| e.raw_set_git_error())
338334 });
339335 match ok {
340336 Some(Ok(cred)) => {
@@ -433,13 +429,7 @@ extern "C" fn certificate_check_cb(
433429 match ok {
434430 Some(Ok(CertificateCheckStatus::CertificateOk)) => 0,
435431 Some(Ok(CertificateCheckStatus::CertificatePassthrough)) => raw::GIT_PASSTHROUGH as c_int,
436- Some(Err(e)) => {
437- let s = CString::new(e.message()).unwrap();
438- unsafe {
439- raw::git_error_set_str(e.class() as c_int, s.as_ptr());
440- }
441- e.raw_code() as c_int
442- }
432+ Some(Err(e)) => unsafe { e.raw_set_git_error() },
443433 None => {
444434 // Panic. The *should* get resumed by some future call to check().
445435 -1
@@ -466,7 +456,7 @@ extern "C" fn push_update_reference_cb(
466456 };
467457 match callback(refname, status) {
468458 Ok(()) => 0,
469- Err(e) => e.raw_code (),
459+ Err(e) => e.raw_set_git_error (),
470460 }
471461 })
472462 .unwrap_or(-1)
@@ -529,7 +519,7 @@ extern "C" fn push_negotiation_cb(
529519 let updates = slice::from_raw_parts(updates as *mut PushUpdate<'_>, len);
530520 match callback(updates) {
531521 Ok(()) => 0,
532- Err(e) => e.raw_code (),
522+ Err(e) => e.raw_set_git_error (),
533523 }
534524 })
535525 .unwrap_or(-1)
0 commit comments