Skip to content

Commit 071902a

Browse files
committed
Push init into libgit2-sys
1 parent 741036f commit 071902a

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

libgit2-sys/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ path = "lib.rs"
1616
[dependencies]
1717
curl-sys = { version = "0.3", optional = true }
1818
libc = "0.2"
19-
libssh2-sys = { version = "0.2", optional = true }
19+
libssh2-sys = { version = "0.2.4", optional = true }
2020
libz-sys = ">= 0"
2121

2222
[build-dependencies]

libgit2-sys/lib.rs

+33-6
Original file line numberDiff line numberDiff line change
@@ -1334,9 +1334,6 @@ git_enum! {
13341334
pub type git_packbuilder_foreach_cb = extern fn(*const c_void, size_t,
13351335
*mut c_void) -> c_int;
13361336

1337-
#[doc(hidden)]
1338-
pub fn openssl_init() {}
1339-
13401337
extern {
13411338
// threads
13421339
pub fn git_libgit2_init() -> c_int;
@@ -2524,7 +2521,37 @@ extern {
25242521
pub fn git_packbuilder_free(pb: *mut git_packbuilder);
25252522
}
25262523

2527-
#[test]
2528-
fn smoke() {
2529-
unsafe { git_threads_init(); }
2524+
pub fn init() {
2525+
use std::sync::{Once, ONCE_INIT};
2526+
2527+
static INIT: Once = ONCE_INIT;
2528+
INIT.call_once(|| unsafe {
2529+
openssl_init();
2530+
ssh_init();
2531+
let r = git_libgit2_init();
2532+
assert!(r >= 0,
2533+
"couldn't initialize the libgit2 library: {}", r);
2534+
assert_eq!(libc::atexit(shutdown), 0);
2535+
});
2536+
extern fn shutdown() {
2537+
unsafe { git_libgit2_shutdown(); }
2538+
}
2539+
}
2540+
2541+
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), feature = "https"))]
2542+
#[doc(hidden)]
2543+
pub fn openssl_init() {
2544+
openssl_sys::init();
25302545
}
2546+
2547+
#[cfg(any(windows, target_os = "macos", target_os = "ios", not(feature = "https")))]
2548+
#[doc(hidden)]
2549+
pub fn openssl_init() {}
2550+
2551+
#[cfg(feature = "ssh")]
2552+
fn ssh_init() {
2553+
libssh2::init();
2554+
}
2555+
2556+
#[cfg(not(feature = "ssh"))]
2557+
fn ssh_init() {}

src/lib.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -528,26 +528,19 @@ mod tree;
528528
mod treebuilder;
529529

530530
fn init() {
531+
raw::init();
532+
531533
static INIT: Once = ONCE_INIT;
532-
INIT.call_once(|| unsafe {
533-
openssl_init();
534-
let r = raw::git_libgit2_init();
535-
assert!(r >= 0,
536-
"couldn't initialize the libgit2 library: {}", r);
537-
assert_eq!(libc::atexit(shutdown), 0);
534+
535+
INIT.call_once(|| {
536+
openssl_env_init();
538537
});
539-
extern fn shutdown() {
540-
unsafe { raw::git_libgit2_shutdown(); }
541-
}
542538
}
543539

544540
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), feature = "https"))]
545-
fn openssl_init() {
546-
extern crate openssl_sys;
541+
fn openssl_env_init() {
547542
extern crate openssl_probe;
548543

549-
openssl_sys::init();
550-
551544
// Currently, libgit2 leverages OpenSSL for SSL support when cloning
552545
// repositories over HTTPS. This means that we're picking up an OpenSSL
553546
// dependency on non-Windows platforms (where it has its own HTTPS
@@ -663,7 +656,7 @@ fn openssl_init() {
663656
}
664657

665658
#[cfg(any(windows, target_os = "macos", target_os = "ios", not(feature = "https")))]
666-
fn openssl_init() {}
659+
fn openssl_env_init() {}
667660

668661
unsafe fn opt_bytes<'a, T>(_anchor: &'a T,
669662
c: *const libc::c_char) -> Option<&'a [u8]> {

0 commit comments

Comments
 (0)