Skip to content

Commit

Permalink
Update libgit2 dep and don't bulid debuginfo
Browse files Browse the repository at this point in the history
In debugging a segfault on win32 with gcc 4.9.2, I ended up updating the libgit2
dep as well as figuring out that the RelWithDebInfo profile causes a segfault
while Release does not! This looks to be a bug in gcc 4.9.2, but it'll be tough
to track down, so let's just stick with this for now.
  • Loading branch information
alexcrichton committed Dec 8, 2014
1 parent aabcf9c commit a20191d
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 97 deletions.
2 changes: 1 addition & 1 deletion libgit2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() {
run(cmd.arg("-DTHREADSAFE=ON")
.arg("-DBUILD_SHARED_LIBS=OFF")
.arg("-DBUILD_CLAR=OFF")
.arg("-DCMAKE_BUILD_TYPE=RelWithDebInfo")
.arg("-DCMAKE_BUILD_TYPE=Release")
.arg(format!("-DCMAKE_INSTALL_PREFIX={}", dst.display()))
.arg("-DBUILD_EXAMPLES=OFF")
.arg(format!("-DCMAKE_C_FLAGS={}", cflags)));
Expand Down
48 changes: 37 additions & 11 deletions libgit2-sys/lib.rs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use git_credtype_t::*;
pub use git_repository_init_flag_t::*;
pub use git_repository_init_mode_t::*;
pub use git_index_add_option_t::*;
pub use git_cert_t::*;

use libc::{c_int, c_char, c_uint, size_t, c_uchar, c_void, c_ushort};

Expand Down Expand Up @@ -207,11 +208,17 @@ pub struct git_remote_callbacks {
pub completion: Option<extern fn(git_remote_completion_type,
*mut c_void) -> c_int>,
pub credentials: Option<git_cred_acquire_cb>,
pub certificate_check: Option<git_transport_certificate_check_cb>,
pub transfer_progress: Option<git_transfer_progress_cb>,
pub update_tips: Option<extern fn(*const c_char,
*const git_oid,
*const git_oid,
*mut c_void) -> c_int>,
pub pack_progress: Option<git_packbuilder_progress>,
pub push_transfer_progress: Option<git_push_transfer_progress>,
pub push_update_reference: Option<extern fn(*const c_char,
*const c_char,
*mut c_void) -> c_int>,
pub payload: *mut c_void,
}

Expand All @@ -229,6 +236,25 @@ pub type git_cred_acquire_cb = extern fn(*mut *mut git_cred,
c_uint, *mut c_void) -> c_int;
pub type git_transfer_progress_cb = extern fn(*const git_transfer_progress,
*mut c_void) -> c_int;
pub type git_packbuilder_progress = extern fn(c_int, c_uint, c_uint,
*mut c_void) -> c_int;
pub type git_push_transfer_progress = extern fn(c_uint, c_uint, size_t,
*mut c_void) -> c_int;
pub type git_transport_certificate_check_cb = extern fn(*mut git_cert,
c_int,
*const c_char,
*mut c_void) -> c_int;

#[repr(C)]
pub enum git_cert_t {
GIT_CERT_X509,
GIT_CERT_HOSTKEY_LIBSSH2,
}

#[repr(C)]
pub struct git_cert {
pub cert_type: git_cert_t,
}

#[repr(C)]
pub struct git_transfer_progress {
Expand Down Expand Up @@ -635,8 +661,8 @@ pub fn openssl_init() {}

extern {
// threads
pub fn git_threads_init() -> c_int;
pub fn git_threads_shutdown();
pub fn git_libgit2_init() -> c_int;
pub fn git_libgit2_shutdown();

// repository
pub fn git_repository_free(repo: *mut git_repository);
Expand Down Expand Up @@ -719,14 +745,15 @@ extern {
repo: *mut git_repository,
name: *const c_char,
url: *const c_char) -> c_int;
pub fn git_remote_load(out: *mut *mut git_remote,
repo: *mut git_repository,
name: *const c_char) -> c_int;
pub fn git_remote_lookup(out: *mut *mut git_remote,
repo: *mut git_repository,
name: *const c_char) -> c_int;
pub fn git_remote_create_anonymous(out: *mut *mut git_remote,
repo: *mut git_repository,
url: *const c_char,
fetch: *const c_char) -> c_int;
pub fn git_remote_delete(remote: *mut git_remote) -> c_int;
pub fn git_remote_delete(repo: *mut git_repository,
name: *const c_char) -> c_int;
pub fn git_remote_free(remote: *mut git_remote);
pub fn git_remote_name(remote: *const git_remote) -> *const c_char;
pub fn git_remote_pushurl(remote: *const git_remote) -> *const c_char;
Expand All @@ -741,7 +768,6 @@ extern {
refspec: *const c_char) -> c_int;
pub fn git_remote_add_push(remote: *mut git_remote,
refspec: *const c_char) -> c_int;
pub fn git_remote_check_cert(remote: *mut git_remote, check: c_int);
pub fn git_remote_clear_refspecs(remote: *mut git_remote);
pub fn git_remote_download(remote: *mut git_remote) -> c_int;
pub fn git_remote_dup(dest: *mut *mut git_remote,
Expand All @@ -751,14 +777,14 @@ extern {
pub fn git_remote_get_refspec(remote: *const git_remote,
n: size_t) -> *const git_refspec;
pub fn git_remote_is_valid_name(remote_name: *const c_char) -> c_int;
pub fn git_remote_valid_url(url: *const c_char) -> c_int;
pub fn git_remote_supported_url(url: *const c_char) -> c_int;
pub fn git_remote_list(out: *mut git_strarray,
repo: *mut git_repository) -> c_int;
pub fn git_remote_rename(problems: *mut git_strarray,
remote: *mut git_remote,
repo: *mut git_repository,
name: *const c_char,
new_name: *const c_char) -> c_int;
pub fn git_remote_fetch(remote: *mut git_remote,
refspecs: *const git_strarray,
signature: *const git_signature,
reflog_message: *const c_char) -> c_int;
pub fn git_remote_update_tips(remote: *mut git_remote,
Expand Down Expand Up @@ -822,6 +848,7 @@ extern {
pub fn git_reset(repo: *mut git_repository,
target: *mut git_object,
reset_type: git_reset_t,
checkout_opts: *mut git_checkout_options,
signature: *mut git_signature,
log_message: *const c_char) -> c_int;
pub fn git_reset_default(repo: *mut git_repository,
Expand Down Expand Up @@ -1178,7 +1205,6 @@ extern {
value: *const c_char) -> c_int;
pub fn git_config_parse_int64(out: *mut i64,
value: *const c_char) -> c_int;
pub fn git_config_refresh(cfg: *mut git_config) -> c_int;
pub fn git_config_set_bool(cfg: *mut git_config,
name: *const c_char,
value: c_int) -> c_int;
Expand Down
2 changes: 1 addition & 1 deletion libgit2-sys/libgit2
Submodule libgit2 updated 500 files
12 changes: 0 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,6 @@ impl Config {
}
}

/// Reload changed config files
///
/// A config file may be changed on disk out from under the in-memory
/// config object. This function causes us to look for files that have been
/// modified since we last loaded them and refresh the config with the
/// latest information.
pub fn refresh(&mut self) -> Result<(), Error> {
unsafe { try_call!(raw::git_config_refresh(self.raw)); }
Ok(())
}

/// Set the value of a boolean config variable in the config file with the
/// highest level (usually the local one).
pub fn set_bool(&mut self, name: &str, value: bool) -> Result<(), Error> {
Expand Down Expand Up @@ -450,7 +439,6 @@ mod tests {
cfg.set_i64("foo.k3", 2).unwrap();
cfg.set_str("foo.k4", "bar").unwrap();
cfg.snapshot().unwrap();
cfg.refresh().unwrap();
drop(cfg);

let cfg = Config::open(&path).unwrap();
Expand Down
21 changes: 10 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,16 @@ mod tree;
#[cfg(test)] mod test;

fn init() {
static mut INIT: Once = ONCE_INIT;
unsafe {
INIT.doit(|| {
raw::openssl_init();
assert!(raw::git_threads_init() == 0,
"couldn't initialize the libgit2 library!");
rt::at_exit(proc() {
raw::git_threads_shutdown();
});
})
}
static INIT: Once = ONCE_INIT;
INIT.doit(|| unsafe {
raw::openssl_init();
let r = raw::git_libgit2_init();
assert!(r >= 0,
"couldn't initialize the libgit2 library: {}", r);
rt::at_exit(proc() {
raw::git_libgit2_shutdown();
});
});
}

unsafe fn opt_bytes<'a, T>(_: &'a T,
Expand Down
82 changes: 22 additions & 60 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::kinds::marker;
use std::str;
use libc;

use {raw, Repository, Direction, Error, Refspec, StringArray};
use {raw, Repository, Direction, Error, Refspec};
use {Signature, Push, RemoteCallbacks};

/// A structure representing a [remote][1] of a git repository.
Expand Down Expand Up @@ -50,21 +50,6 @@ impl<'a, 'b> Remote<'a, 'b> {
unsafe { raw::git_remote_is_valid_name(remote_name.as_ptr()) == 1 }
}

/// Return whether a string is a valid remote URL
pub fn is_valid_url(url: &str) -> bool {
::init();
let url = url.to_c_str();
unsafe { raw::git_remote_valid_url(url.as_ptr()) == 1 }
}

/// Return whether the passed URL is supported by this version of the
/// library.
pub fn is_supported_url(url: &str) -> bool {
::init();
let url = url.to_c_str();
unsafe { raw::git_remote_supported_url(url.as_ptr()) == 1 }
}

/// Get the remote's name.
///
/// Returns `None` if this remote has not yet been named or if the name is
Expand Down Expand Up @@ -147,13 +132,6 @@ impl<'a, 'b> Remote<'a, 'b> {
Ok(())
}

/// Choose whether to check the server's certificate (applies to HTTPS only)
///
/// The default is yes.
pub fn set_check_cert(&mut self, check: bool) {
unsafe { raw::git_remote_check_cert(self.raw, check as libc::c_int) }
}

/// Set the remote's url
///
/// Existing connections will not be updated.
Expand Down Expand Up @@ -224,15 +202,6 @@ impl<'a, 'b> Remote<'a, 'b> {
unsafe { raw::git_remote_clear_refspecs(self.raw) }
}

/// Delete an existing persisted remote.
///
/// All remote-tracking branches and configuration settings for the remote
/// will be removed.
pub fn delete(&mut self) -> Result<(), Error> {
unsafe { try_call!(raw::git_remote_delete(self.raw)); }
Ok(())
}

/// Download and index the packfile
///
/// Connect to the remote if it hasn't been done yet, negotiate with the
Expand All @@ -254,34 +223,24 @@ impl<'a, 'b> Remote<'a, 'b> {
Refspecs { cur: 0, cnt: cnt, remote: self }
}

/// Give the remote a new name
///
/// All remote-tracking branches and configuration settings for the remote
/// are updated.
///
/// A temporary in-memory remote cannot be given a name with this method.
pub fn rename(&mut self, new_name: &str) -> Result<(), Error> {
let mut problems = raw::git_strarray {
count: 0,
strings: 0 as *mut *mut libc::c_char,
};
unsafe {
try_call!(raw::git_remote_rename(&mut problems, self.raw,
new_name.to_c_str()));
let _s = StringArray::from_raw(problems);
}
Ok(())
}

/// Download new data and update tips
///
/// Convenience function to connect to a remote, download the data,
/// disconnect and update the remote-tracking branches.
pub fn fetch(&mut self, signature: Option<&Signature>,
pub fn fetch(&mut self,
refspecs: &[&str],
signature: Option<&Signature>,
msg: Option<&str>) -> Result<(), Error> {
let refspecs = refspecs.iter().map(|s| s.to_c_str()).collect::<Vec<_>>();
let ptrs = refspecs.iter().map(|s| s.as_ptr()).collect::<Vec<_>>();
let arr = raw::git_strarray {
strings: ptrs.as_ptr() as *mut _,
count: ptrs.len() as libc::size_t,
};
unsafe {
try!(self.set_raw_callbacks());
try_call!(raw::git_remote_fetch(self.raw,
&arr,
&*signature.map(|s| s.raw())
.unwrap_or(0 as *mut _),
msg.map(|s| s.to_c_str())));
Expand Down Expand Up @@ -439,19 +398,24 @@ mod tests {

origin.add_fetch("foo").unwrap();
origin.add_fetch("bar").unwrap();
origin.set_check_cert(true);
origin.clear_refspecs();

origin.set_fetch_refspecs(["foo"].iter().map(|a| *a)).unwrap();
origin.set_push_refspecs(["foo"].iter().map(|a| *a)).unwrap();

origin.rename("origin2").unwrap();
let sig = repo.signature().unwrap();
origin.fetch(Some(&sig), None).unwrap();
origin.fetch(None, Some("foo")).unwrap();
origin.fetch(&[], Some(&sig), None).unwrap();
origin.fetch(&[], None, Some("foo")).unwrap();
origin.update_tips(Some(&sig), None).unwrap();
origin.update_tips(None, Some("foo")).unwrap();
origin.delete().unwrap();
}

#[test]
fn rename_remote() {
let (_td, repo) = ::test::repo_init();
repo.remote("origin", "foo").unwrap();
repo.remote_rename("origin", "foo").unwrap();
repo.remote_delete("foo").unwrap();
}

#[test]
Expand All @@ -469,8 +433,6 @@ mod tests {
fn is_valid() {
assert!(Remote::is_valid_name("foobar"));
assert!(!Remote::is_valid_name("\x01"));
assert!(Remote::is_valid_url("http://example.com/foo/bar"));
assert!(!Remote::is_valid_url("test"));
}

#[test]
Expand All @@ -489,7 +451,7 @@ mod tests {
true
});
origin.set_callbacks(&mut callbacks);
origin.fetch(None, None).unwrap();
origin.fetch(&[], None, None).unwrap();
assert!(progress_hit.get());
}
}
Loading

0 comments on commit a20191d

Please sign in to comment.