diff --git a/examples/add.rs b/examples/add.rs index 371ad960c5..861c5d1077 100644 --- a/examples/add.rs +++ b/examples/add.rs @@ -13,6 +13,7 @@ */ #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; diff --git a/examples/clone.rs b/examples/clone.rs index 5682332dbf..f1ac1bccee 100644 --- a/examples/clone.rs +++ b/examples/clone.rs @@ -13,6 +13,7 @@ */ #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; diff --git a/examples/fetch.rs b/examples/fetch.rs index deff2b443f..3069469acc 100644 --- a/examples/fetch.rs +++ b/examples/fetch.rs @@ -13,6 +13,7 @@ */ #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; diff --git a/examples/init.rs b/examples/init.rs index 4dece1bf8e..066664501c 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -13,6 +13,7 @@ */ #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; diff --git a/examples/log.rs b/examples/log.rs index 7be0285385..a69fe5c309 100644 --- a/examples/log.rs +++ b/examples/log.rs @@ -14,6 +14,7 @@ #![feature(macro_rules)] #![deny(warnings)] +#![allow(unstable)] extern crate "rustc-serialize" as rustc_serialize; extern crate docopt; diff --git a/examples/ls-remote.rs b/examples/ls-remote.rs index 4f641d0099..6b4cbed755 100644 --- a/examples/ls-remote.rs +++ b/examples/ls-remote.rs @@ -13,6 +13,7 @@ */ #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; diff --git a/examples/rev-list.rs b/examples/rev-list.rs index d9c6becdc8..bda32be1f5 100644 --- a/examples/rev-list.rs +++ b/examples/rev-list.rs @@ -15,6 +15,7 @@ #![feature(slicing_syntax)] #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; @@ -48,7 +49,7 @@ fn run(args: &Args) -> Result<(), git2::Error> { let mut specs = args.flag_not.iter().map(|s| (s, true)) .chain(args.arg_spec.iter().map(|s| (s, false))) .map(|(spec, hide)| { - if spec.starts_with("^") {(spec[1..], !hide)} else {(spec[], hide)} + if spec.starts_with("^") {(&spec[1..], !hide)} else {(&spec[], hide)} }); for (spec, hide) in specs { let id = if spec.contains("..") { diff --git a/examples/rev-parse.rs b/examples/rev-parse.rs index d6deda51d2..6c316d1234 100644 --- a/examples/rev-parse.rs +++ b/examples/rev-parse.rs @@ -13,6 +13,7 @@ */ #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; diff --git a/examples/status.rs b/examples/status.rs index 90483a277e..c15e72801b 100644 --- a/examples/status.rs +++ b/examples/status.rs @@ -13,6 +13,7 @@ */ #![deny(warnings)] +#![allow(unstable)] extern crate git2; extern crate docopt; diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 41fa5041b8..54edba1ae9 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -1,4 +1,3 @@ -#![feature(globs, phase)] #![allow(non_camel_case_types, missing_copy_implementations)] extern crate libc; @@ -78,13 +77,14 @@ pub struct git_revspec { } #[repr(C)] +#[derive(Show)] pub struct git_error { pub message: *mut c_char, pub klass: c_int, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy,Show)] pub struct git_oid { pub id: [u8; GIT_OID_RAWSZ], } diff --git a/src/blob.rs b/src/blob.rs index 2077d78e81..ab1354612d 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -1,4 +1,4 @@ -use std::kinds::marker; +use std::marker; use std::mem; use std::raw as stdraw; diff --git a/src/branch.rs b/src/branch.rs index 681f1c5327..f96b808721 100644 --- a/src/branch.rs +++ b/src/branch.rs @@ -1,5 +1,5 @@ -use std::c_str::ToCStr; -use std::kinds::marker; +use std::ffi::CString; +use std::marker; use std::str; use libc; @@ -49,11 +49,11 @@ impl<'repo> Branch<'repo> { let mut ret = 0 as *mut raw::git_reference; unsafe { try_call!(raw::git_branch_move(&mut ret, self.get().raw(), - new_branch_name.to_c_str(), + CString::from_slice(new_branch_name.as_bytes()), force, &*signature.map(|s| s.raw()) .unwrap_or(0 as *mut _), - log_message.to_c_str())); + CString::from_slice(log_message.as_bytes()))); Ok(Branch::wrap(Reference::from_raw(ret))) } } @@ -90,7 +90,7 @@ impl<'repo> Branch<'repo> { /// provided is the name of the branch to set as upstream. pub fn set_upstream(&mut self, upstream_name: Option<&str>) -> Result<(), Error> { - let upstream_name = upstream_name.map(|s| s.to_c_str()); + let upstream_name = upstream_name.map(|s| CString::from_slice(s.as_bytes())); unsafe { try_call!(raw::git_branch_set_upstream(self.get().raw(), upstream_name)); diff --git a/src/build.rs b/src/build.rs index 441ffd2f54..30ae3d503b 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,6 +1,6 @@ //! Builder-pattern objects for configuration various git operations. -use std::c_str::{CString, ToCStr}; +use std::ffi::{CString, c_str_to_bytes}; use std::io; use std::mem; use libc::{c_char, size_t, c_void, c_uint, c_int}; @@ -70,7 +70,7 @@ impl<'cb> RepoBuilder<'cb> { /// /// If not specified, the remote's default branch will be used. pub fn branch(&mut self, branch: &str) -> &mut RepoBuilder<'cb> { - self.branch = Some(branch.to_c_str()); + self.branch = Some(CString::from_slice(branch.as_bytes())); self } @@ -154,8 +154,8 @@ impl<'cb> RepoBuilder<'cb> { let mut raw = 0 as *mut raw::git_repository; unsafe { - try_call!(raw::git_clone(&mut raw, url.to_c_str(), - into.to_c_str(), &opts)); + try_call!(raw::git_clone(&mut raw, CString::from_slice(url.as_bytes()), + CString::from_slice(into.as_vec()), &opts)); Ok(Repository::from_raw(raw)) } } @@ -342,8 +342,8 @@ impl<'cb> CheckoutBuilder<'cb> { /// /// If no paths are specified, then all files are checked out. Otherwise /// only these specified paths are checked out. - pub fn path(&mut self, path: T) -> &mut CheckoutBuilder<'cb> { - let path = path.to_c_str(); + pub fn path(&mut self, path: T) -> &mut CheckoutBuilder<'cb> { + let path = CString::from_slice(path.as_slice().as_bytes()); self.path_ptrs.push(path.as_ptr()); self.paths.push(path); self @@ -351,25 +351,25 @@ impl<'cb> CheckoutBuilder<'cb> { /// Set the directory to check out to pub fn target_dir(&mut self, dst: Path) -> &mut CheckoutBuilder<'cb> { - self.target_dir = Some(dst.to_c_str()); + self.target_dir = Some(CString::from_slice(dst.as_vec())); self } /// The name of the common ancestor side of conflicts pub fn ancestor_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> { - self.ancestor_label = Some(label.to_c_str()); + self.ancestor_label = Some(CString::from_slice(label.as_bytes())); self } /// The name of the common our side of conflicts pub fn our_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> { - self.our_label = Some(label.to_c_str()); + self.our_label = Some(CString::from_slice(label.as_bytes())); self } /// The name of the common their side of conflicts pub fn their_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> { - self.their_label = Some(label.to_c_str()); + self.their_label = Some(CString::from_slice(label.as_bytes())); self } @@ -430,9 +430,9 @@ extern fn progress_cb(path: *const c_char, Some(ref mut c) => c, None => return, }; - let path = CString::new(path, false); + let path = CString::from_slice(c_str_to_bytes(&path)); panic::wrap(|| { - callback(path.as_bytes_no_nul(), completed as uint, total as uint); + callback(path.as_bytes(), completed as uint, total as uint); }); } } diff --git a/src/call.rs b/src/call.rs index d791793486..0e80d3ffff 100644 --- a/src/call.rs +++ b/src/call.rs @@ -1,4 +1,4 @@ -#![macro_escape] +#![macro_use] use libc; use Error; @@ -41,7 +41,7 @@ fn last_error() -> Error { } mod impls { - use std::c_str::CString; + use std::ffi::CString; use libc; use {raw, ConfigLevel, ResetType, ObjectType, BranchType, Direction}; diff --git a/src/commit.rs b/src/commit.rs index 804acda999..6854c46477 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -1,6 +1,6 @@ -use std::c_str::ToCStr; +use std::ffi::CString; use std::iter::Range; -use std::kinds::marker; +use std::marker; use std::str; use libc; @@ -206,11 +206,11 @@ impl<'repo> Commit<'repo> { unsafe { try_call!(raw::git_commit_amend(&mut raw, &*self.raw(), - update_ref.map(|s| s.to_c_str()), + update_ref.map(|s| CString::from_slice(s.as_bytes())), author.map(|s| &*s.raw()), committer.map(|s| &*s.raw()), - message_encoding.map(|s| s.to_c_str()), - message.map(|s| s.to_c_str()), + message_encoding.map(|s| CString::from_slice(s.as_bytes())), + message.map(|s| CString::from_slice(s.as_bytes())), tree.map(|t| &*t.raw()))); Ok(Oid::from_raw(&raw)) } diff --git a/src/config.rs b/src/config.rs index 2dac25b8eb..fea20a6a19 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,5 @@ -use std::c_str::ToCStr; -use std::kinds::marker; +use std::ffi::CString; +use std::marker; use std::str; use libc; @@ -44,7 +44,7 @@ impl Config { ::init(); let mut raw = 0 as *mut raw::git_config; unsafe { - try_call!(raw::git_config_open_ondisk(&mut raw, path.to_c_str())); + try_call!(raw::git_config_open_ondisk(&mut raw, CString::from_slice(path.as_vec()))); Ok(Config::from_raw(raw)) } } @@ -124,7 +124,7 @@ impl Config { pub fn add_file(&mut self, path: &Path, level: ConfigLevel, force: bool) -> Result<(), Error> { unsafe { - try_call!(raw::git_config_add_file_ondisk(self.raw, path.to_c_str(), + try_call!(raw::git_config_add_file_ondisk(self.raw, CString::from_slice(path.as_vec()), level, force)); Ok(()) } @@ -134,7 +134,7 @@ impl Config { /// (usually the local one). pub fn remove(&mut self, name: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_config_delete_entry(self.raw, name.to_c_str())); + try_call!(raw::git_config_delete_entry(self.raw, CString::from_slice(name.as_bytes()))); Ok(()) } } @@ -148,7 +148,7 @@ impl Config { let mut out = 0 as libc::c_int; unsafe { try_call!(raw::git_config_get_bool(&mut out, &*self.raw, - name.to_c_str())); + CString::from_slice(name.as_bytes()))); } Ok(if out == 0 {false} else {true}) } @@ -162,7 +162,7 @@ impl Config { let mut out = 0i32; unsafe { try_call!(raw::git_config_get_int32(&mut out, &*self.raw, - name.to_c_str())); + CString::from_slice(name.as_bytes()))); } Ok(out) } @@ -176,7 +176,7 @@ impl Config { let mut out = 0i64; unsafe { try_call!(raw::git_config_get_int64(&mut out, &*self.raw, - name.to_c_str())); + CString::from_slice(name.as_bytes()))); } Ok(out) } @@ -196,7 +196,7 @@ impl Config { let mut ret = 0 as *const libc::c_char; unsafe { try_call!(raw::git_config_get_string(&mut ret, &*self.raw, - name.to_c_str())); + CString::from_slice(name.as_bytes()))); Ok(::opt_bytes(self, ret).unwrap()) } } @@ -206,7 +206,7 @@ impl Config { let mut ret = 0 as *const raw::git_config_entry; unsafe { try_call!(raw::git_config_get_entry(&mut ret, &*self.raw, - name.to_c_str())); + CString::from_slice(name.as_bytes()))); Ok(ConfigEntry::from_raw(ret)) } } @@ -234,7 +234,7 @@ impl Config { Some(s) => { try_call!(raw::git_config_iterator_glob_new(&mut ret, &*self.raw, - s.to_c_str())); + CString::from_slice(s.as_bytes()))); } None => { try_call!(raw::git_config_iterator_new(&mut ret, &*self.raw)); @@ -274,7 +274,7 @@ impl Config { /// highest level (usually the local one). pub fn set_bool(&mut self, name: &str, value: bool) -> Result<(), Error> { unsafe { - try_call!(raw::git_config_set_bool(self.raw, name.to_c_str(), + try_call!(raw::git_config_set_bool(self.raw, CString::from_slice(name.as_bytes()), value)); } Ok(()) @@ -284,7 +284,7 @@ impl Config { /// highest level (usually the local one). pub fn set_i32(&mut self, name: &str, value: i32) -> Result<(), Error> { unsafe { - try_call!(raw::git_config_set_int32(self.raw, name.to_c_str(), + try_call!(raw::git_config_set_int32(self.raw, CString::from_slice(name.as_bytes()), value)); } Ok(()) @@ -294,7 +294,7 @@ impl Config { /// highest level (usually the local one). pub fn set_i64(&mut self, name: &str, value: i64) -> Result<(), Error> { unsafe { - try_call!(raw::git_config_set_int64(self.raw, name.to_c_str(), + try_call!(raw::git_config_set_int64(self.raw, CString::from_slice(name.as_bytes()), value)); } Ok(()) @@ -304,8 +304,8 @@ impl Config { /// highest level (usually the local one). pub fn set_str(&mut self, name: &str, value: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_config_set_string(self.raw, name.to_c_str(), - value.to_c_str())); + try_call!(raw::git_config_set_string(self.raw, CString::from_slice(name.as_bytes()), + CString::from_slice(value.as_bytes()))); } Ok(()) } diff --git a/src/cred.rs b/src/cred.rs index 7c8d6e9de3..e26b82def0 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -1,4 +1,4 @@ -use std::c_str::ToCStr; +use std::ffi::CString; use std::mem; use std::io::Command; use url::{self, UrlParser}; @@ -49,7 +49,7 @@ impl Cred { let mut out = 0 as *mut raw::git_cred; unsafe { try_call!(raw::git_cred_ssh_key_from_agent(&mut out, - username.to_c_str())); + CString::from_slice(username.as_bytes()))); Ok(Cred::from_raw(out)) } } @@ -63,10 +63,10 @@ impl Cred { let mut out = 0 as *mut raw::git_cred; unsafe { try_call!(raw::git_cred_ssh_key_new(&mut out, - username.to_c_str(), - publickey.map(|s| s.to_c_str()), - privatekey.to_c_str(), - passphrase.map(|s| s.to_c_str()))); + CString::from_slice(username.as_bytes()), + publickey.map(|s| CString::from_slice(s.as_vec())), + CString::from_slice(privatekey.as_vec()), + passphrase.map(|s| CString::from_slice(s.as_bytes())))); Ok(Cred::from_raw(out)) } } @@ -78,8 +78,8 @@ impl Cred { let mut out = 0 as *mut raw::git_cred; unsafe { try_call!(raw::git_cred_userpass_plaintext_new(&mut out, - username.to_c_str(), - password.to_c_str())); + CString::from_slice(username.as_bytes()), + CString::from_slice(password.as_bytes()))); Ok(Cred::from_raw(out)) } } diff --git a/src/diff.rs b/src/diff.rs index f1688c9f5d..dd5604f39b 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -1,6 +1,6 @@ -use std::c_str::{CString, ToCStr}; +use std::ffi::CString; use std::iter::Range; -use std::kinds::marker; +use std::marker; use std::mem; use std::slice; use libc::{c_char, size_t, c_void, c_int}; @@ -609,22 +609,22 @@ impl DiffOptions { /// The virtual "directory" to prefix old file names with in hunk headers. /// /// The default value for this is "a". - pub fn old_prefix(&mut self, t: T) -> &mut DiffOptions { - self.old_prefix = Some(t.to_c_str()); + pub fn old_prefix(&mut self, t: T) -> &mut DiffOptions { + self.old_prefix = Some(CString::from_slice(t.as_slice().as_bytes())); self } /// The virtual "directory" to prefix new file names with in hunk headers. /// /// The default value for this is "b". - pub fn new_prefix(&mut self, t: T) -> &mut DiffOptions { - self.new_prefix = Some(t.to_c_str()); + pub fn new_prefix(&mut self, t: T) -> &mut DiffOptions { + self.new_prefix = Some(CString::from_slice(t.as_slice().as_bytes())); self } /// Add to the array of paths/fnmatch patterns to constrain the diff. - pub fn pathspec(&mut self, pathspec: T) -> &mut DiffOptions { - let s = pathspec.to_c_str(); + pub fn pathspec(&mut self, pathspec: T) -> &mut DiffOptions { + let s = CString::from_slice(pathspec.as_slice().as_bytes()); self.pathspec_ptrs.push(s.as_ptr()); self.pathspec.push(s); self diff --git a/src/error.rs b/src/error.rs index 8b952b3276..abc20a6a95 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,4 @@ -use std::c_str::{CString, ToCStr}; +use std::ffi::{CString, c_str_to_bytes}; use std::error; use std::fmt; use std::str; @@ -8,6 +8,7 @@ use libc::c_int; use {raw, ErrorCode}; /// A structure to represent errors coming out of libgit2. +#[derive(Show)] pub struct Error { raw: raw::git_error, } @@ -32,7 +33,7 @@ impl Error { ::init(); Error { raw: raw::git_error { - message: unsafe { s.to_c_str().into_inner() as *mut _ }, + message: CString::from_slice(s.as_bytes()).as_ptr() as *mut _, klass: raw::GIT_ERROR as libc::c_int, } } @@ -92,8 +93,8 @@ impl Error { /// Return the message associated with this error pub fn message(&self) -> String { - let cstr = unsafe { CString::new(self.raw.message as *const _, false) }; - String::from_utf8_lossy(cstr.as_bytes_no_nul()).to_string() + let cstr = unsafe { CString::from_slice(c_str_to_bytes(&(self.raw.message as *const _))) }; + String::from_utf8_lossy(cstr.as_bytes()).to_string() } } @@ -101,17 +102,17 @@ unsafe impl Send for Error { } impl error::Error for Error { fn description(&self) -> &str { - unsafe { str::from_c_str(self.raw.message as *const _) } + "A git2-rs Error" } fn detail(&self) -> Option { Some(self.message()) } } -impl fmt::Show for Error { +impl fmt::String for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "[{}] ", self.raw.klass)); - let cstr = unsafe { CString::new(self.raw.message as *const _, false) }; - f.write_str(cstr.as_str().unwrap()) + let cstr = unsafe { CString::from_slice(c_str_to_bytes(&(self.raw.message as *const _))) }; + f.write_str(str::from_utf8(cstr.as_bytes()).unwrap()) } } diff --git a/src/index.rs b/src/index.rs index 90b714203f..63785d1ecf 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1,6 +1,6 @@ -use std::c_str::{CString, ToCStr}; +use std::ffi::{CString, c_str_to_bytes}; use std::iter::Range; -use std::kinds::marker; +use std::marker; use std::mem; use std::path::PosixPath; @@ -75,7 +75,7 @@ impl Index { ::init(); let mut raw = 0 as *mut raw::git_index; unsafe { - try_call!(raw::git_index_open(&mut raw, index_path.to_c_str())); + try_call!(raw::git_index_open(&mut raw, CString::from_slice(index_path.as_vec()))); Ok(Index::from_raw(raw)) } } @@ -121,7 +121,7 @@ impl Index { posix_path.push(comp); } unsafe { - try_call!(raw::git_index_add_bypath(self.raw, posix_path.to_c_str())); + try_call!(raw::git_index_add_bypath(self.raw, CString::from_slice(posix_path.as_vec()))); Ok(()) } } @@ -159,12 +159,13 @@ impl Index { /// updated in the index. Returning zero will add the item to the index, /// greater than zero will skip the item, and less than zero will abort the /// scan an return an error to the caller. - pub fn add_all(&mut self, + pub fn add_all(&mut self, pathspecs: &[T], flag: IndexAddOption, mut cb: Option<&mut IndexMatchedPath>) -> Result<(), Error> { - let arr = pathspecs.iter().map(|t| t.to_c_str()).collect::>(); + let arr = pathspecs.iter().map(|t| CString::from_slice(t.as_slice().as_bytes())) + .collect::>(); let strarray = arr.iter().map(|c| c.as_ptr()) .collect::>(); let ptr = cb.as_mut(); @@ -220,7 +221,7 @@ impl Index { /// Get one of the entries in the index by its path. pub fn get_path(&self, path: &Path, stage: int) -> Option { unsafe { - let ptr = call!(raw::git_index_get_bypath(self.raw, path.to_c_str(), + let ptr = call!(raw::git_index_get_bypath(self.raw, CString::from_slice(path.as_vec()), stage as libc::c_int)); if ptr.is_null() {None} else {Some(IndexEntry::from_raw(ptr))} } @@ -262,7 +263,7 @@ impl Index { /// Remove an entry from the index pub fn remove(&mut self, path: &Path, stage: int) -> Result<(), Error> { unsafe { - try_call!(raw::git_index_remove(self.raw, path.to_c_str(), + try_call!(raw::git_index_remove(self.raw, CString::from_slice(path.as_vec()), stage as libc::c_int)); } Ok(()) @@ -278,7 +279,7 @@ impl Index { /// moved to the "resolve undo" (REUC) section. pub fn remove_path(&mut self, path: &Path) -> Result<(), Error> { unsafe { - try_call!(raw::git_index_remove_bypath(self.raw, path.to_c_str())); + try_call!(raw::git_index_remove_bypath(self.raw, CString::from_slice(path.as_vec()))); } Ok(()) } @@ -286,7 +287,7 @@ impl Index { /// Remove all entries from the index under a given directory. pub fn remove_dir(&mut self, path: &Path, stage: int) -> Result<(), Error> { unsafe { - try_call!(raw::git_index_remove_directory(self.raw, path.to_c_str(), + try_call!(raw::git_index_remove_directory(self.raw, CString::from_slice(path.as_vec()), stage as libc::c_int)); } Ok(()) @@ -297,11 +298,12 @@ impl Index { /// If you provide a callback function, it will be invoked on each matching /// item in the index immediately before it is removed. Return 0 to remove /// the item, > 0 to skip the item, and < 0 to abort the scan. - pub fn remove_all(&mut self, + pub fn remove_all(&mut self, pathspecs: &[T], mut cb: Option<&mut IndexMatchedPath>) -> Result<(), Error> { - let arr = pathspecs.iter().map(|t| t.to_c_str()).collect::>(); + let arr = pathspecs.iter().map(|t| CString::from_slice(t.as_slice().as_bytes())) + .collect::>(); let strarray = arr.iter().map(|c| c.as_ptr()) .collect::>(); let ptr = cb.as_mut(); @@ -336,11 +338,12 @@ impl Index { /// item in the index immediately before it is updated (either refreshed or /// removed depending on working directory state). Return 0 to proceed with /// updating the item, > 0 to skip the item, and < 0 to abort the scan. - pub fn update_all(&mut self, + pub fn update_all(&mut self, pathspecs: &[T], mut cb: Option<&mut IndexMatchedPath>) -> Result<(), Error> { - let arr = pathspecs.iter().map(|t| t.to_c_str()).collect::>(); + let arr = pathspecs.iter().map(|t| CString::from_slice(t.as_slice().as_bytes())) + .collect::>(); let strarray = arr.iter().map(|c| c.as_ptr()) .collect::>(); let ptr = cb.as_mut(); @@ -406,11 +409,11 @@ extern fn index_matched_path_cb(path: *const libc::c_char, matched_pathspec: *const libc::c_char, payload: *mut libc::c_void) -> libc::c_int { unsafe { - let path = CString::new(path, false); - let matched_pathspec = CString::new(matched_pathspec, false); + let path = CString::from_slice(c_str_to_bytes(&path)); + let matched_pathspec = CString::from_slice(c_str_to_bytes(&matched_pathspec)); let payload = payload as *mut &mut IndexMatchedPath; - (*payload)(path.as_bytes_no_nul(), - matched_pathspec.as_bytes_no_nul()) as libc::c_int + (*payload)(path.as_bytes(), + matched_pathspec.as_bytes()) as libc::c_int } } @@ -444,7 +447,7 @@ impl IndexEntry { id: Oid::from_raw(&id), flags: flags as u16, flags_extended: flags_extended as u16, - path: CString::new(path, false).clone(), + path: CString::from_slice(c_str_to_bytes(&path)).clone(), mtime: IndexTime::from_raw(&mtime), ctime: IndexTime::from_raw(&ctime), } diff --git a/src/lib.rs b/src/lib.rs index d1191233cf..3dc436aeef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,16 +63,18 @@ //! source `Repository`, to ensure that they do not outlive the repository //! itself. -#![feature(macro_rules, unsafe_destructor)] -#![feature(associated_types)] +#![feature(unsafe_destructor)] +#![feature(box_syntax)] +#![feature(int_uint)] #![deny(missing_docs)] #![cfg_attr(test, deny(warnings))] +#![allow(unstable)] extern crate libc; extern crate url; extern crate "libgit2-sys" as raw; -use std::c_str::{CString, ToCStr}; +use std::ffi::{CString, c_str_to_bytes}; use std::fmt; use std::mem; use std::str; @@ -327,8 +329,8 @@ unsafe fn opt_bytes<'a, T>(_: &'a T, if c.is_null() { None } else { - let s = CString::new(c, false); - Some(mem::transmute(s.as_bytes_no_nul())) + let s = CString::from_slice(c_str_to_bytes(&c)); + Some(mem::transmute(s.as_bytes())) } } @@ -337,7 +339,9 @@ impl ObjectType { pub fn str(&self) -> &'static str { unsafe { let ptr = call!(raw::git_object_type2string(*self)); - mem::transmute::<&str, &'static str>(str::from_c_str(ptr as *const _)) + mem::transmute::<&str, &'static str>( + str::from_utf8(c_str_to_bytes(&(ptr as *const _))).ok().unwrap_or("") + ) } } @@ -369,7 +373,7 @@ impl ObjectType { /// Convert a string object type representation to its object type. pub fn from_str(s: &str) -> Option { - let raw = unsafe { call!(raw::git_object_string2type(s.to_c_str())) }; + let raw = unsafe { call!(raw::git_object_string2type(CString::from_slice(s.as_bytes()))) }; ObjectType::from_raw(raw) } } diff --git a/src/note.rs b/src/note.rs index 2b2e72fc3e..b20baa0f70 100644 --- a/src/note.rs +++ b/src/note.rs @@ -1,4 +1,4 @@ -use std::kinds::marker; +use std::marker; use std::str; use {raw, Signature, Oid}; diff --git a/src/object.rs b/src/object.rs index 4758b96156..579ca58518 100644 --- a/src/object.rs +++ b/src/object.rs @@ -1,4 +1,4 @@ -use std::kinds::marker; +use std::marker; use std::mem; use {raw, Oid, ObjectType, Error, Buf}; diff --git a/src/oid.rs b/src/oid.rs index 82f7441f74..71303651b1 100644 --- a/src/oid.rs +++ b/src/oid.rs @@ -1,13 +1,13 @@ use std::fmt; use std::cmp::Ordering; -use std::hash::{sip, Hash}; +use std::hash::{Hasher, Writer, Hash}; use std::str; use libc; use {raw, Error}; /// Unique identity of any object (commit, tree, blob, tag). -#[derive(Copy)] +#[derive(Copy,Show)] pub struct Oid { raw: raw::git_oid, } @@ -63,7 +63,7 @@ impl Oid { } } -impl fmt::Show for Oid { +impl fmt::String for Oid { /// Hex-encode this Oid into a formatter. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut dst = [0u8; raw::GIT_OID_HEXSZ + 1]; @@ -103,8 +103,8 @@ impl Clone for Oid { fn clone(&self) -> Oid { *self } } -impl Hash for Oid { - fn hash(&self, into: &mut sip::SipState) { +impl Hash for Oid { + fn hash(&self, into: &mut S) { self.raw.id.as_slice().hash(into) } } diff --git a/src/pathspec.rs b/src/pathspec.rs index be6844b386..e287dd438d 100644 --- a/src/pathspec.rs +++ b/src/pathspec.rs @@ -1,5 +1,5 @@ -use std::c_str::ToCStr; -use std::kinds::marker; +use std::ffi::CString; +use std::marker; use std::iter::Range; use libc::size_t; @@ -38,8 +38,9 @@ pub struct PathspecFailedEntries<'list> { impl Pathspec { /// Creates a new pathspec from a list of specs to match against. pub fn new(specs: I) -> Result - where T: ToCStr, I: Iterator { - let strs = specs.map(|s| s.to_c_str()).collect::>(); + where T: Str, I: Iterator { + let strs = specs.map(|s| CString::from_slice(s.as_slice().as_bytes())) + .collect::>(); let ptrs = strs.iter().map(|c| c.as_ptr()).collect::>(); let arr = raw::git_strarray { strings: ptrs.as_ptr() as *mut _, @@ -122,7 +123,7 @@ impl Pathspec { /// explicitly pass flags to control case sensitivity or else this will fall /// back on being case sensitive. pub fn matches_path(&self, path: &Path, flags: PathspecFlags) -> bool { - let path = path.to_c_str(); + let path = CString::from_slice(path.as_vec()); unsafe { raw::git_pathspec_matches_path(&*self.raw, flags.bits(), path.as_ptr()) == 1 diff --git a/src/push.rs b/src/push.rs index 83e082df61..c41827b040 100644 --- a/src/push.rs +++ b/src/push.rs @@ -1,5 +1,6 @@ -use std::c_str::{CString, ToCStr}; -use std::kinds::marker; +use std::ffi::{CString, c_str_to_bytes}; +use std::marker; +use std::str; use libc; use {raw, Error, Signature}; @@ -40,7 +41,7 @@ impl<'remote> Push<'remote> { /// Add a refspec to be pushed pub fn add_refspec(&mut self, refspec: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_push_add_refspec(self.raw, refspec.to_c_str())); + try_call!(raw::git_push_add_refspec(self.raw, CString::from_slice(refspec.as_bytes()))); Ok(()) } } @@ -64,7 +65,7 @@ impl<'remote> Push<'remote> { unsafe { try_call!(raw::git_push_update_tips(self.raw, signature.map(|s| &*s.raw()), - reflog_message.map(|s| s.to_c_str()))); + reflog_message.map(|s| CString::from_slice(s.as_bytes())))); Ok(()) } } @@ -83,14 +84,14 @@ impl<'remote> Push<'remote> { msg: *const libc::c_char, data: *mut libc::c_void) -> libc::c_int { unsafe { - let git_ref = match CString::new(git_ref, false).as_str() { - Some(s) => s.to_string(), - None => return 0, + let git_ref = match str::from_utf8(c_str_to_bytes(&git_ref)) { + Ok(s) => s.to_string(), + Err(_) => return 0, }; let msg = if !msg.is_null() { - match CString::new(msg, false).as_str() { - Some(s) => Some(s.to_string()), - None => return 0, + match str::from_utf8(c_str_to_bytes(&msg)) { + Ok(s) => Some(s.to_string()), + Err(_) => return 0, } } else { None diff --git a/src/reference.rs b/src/reference.rs index 2d38ed1c8c..e31e076aa6 100644 --- a/src/reference.rs +++ b/src/reference.rs @@ -1,8 +1,8 @@ -use std::c_str::ToCStr; use std::cmp::Ordering; -use std::kinds::marker; +use std::marker; use std::mem; use std::str; +use std::ffi::CString; use libc; use {raw, Error, Oid, Signature}; @@ -41,7 +41,7 @@ impl<'repo> Reference<'repo> { /// Ensure the reference name is well-formed. pub fn is_valid_name(refname: &str) -> bool { ::init(); - let refname = refname.to_c_str(); + let refname = CString::from_slice(refname.as_bytes()); unsafe { raw::git_reference_is_valid_name(refname.as_ptr()) == 1 } } @@ -168,11 +168,11 @@ impl<'repo> Reference<'repo> { let mut raw = 0 as *mut raw::git_reference; unsafe { try_call!(raw::git_reference_rename(&mut raw, self.raw, - new_name.to_c_str(), + CString::from_slice(new_name.as_bytes()), force, &*sig.map(|s| s.raw()) .unwrap_or(0 as *mut _), - msg.to_c_str())); + CString::from_slice(msg.as_bytes()))); } Ok(Reference { raw: raw, diff --git a/src/refspec.rs b/src/refspec.rs index e861b375e3..cda540dc04 100644 --- a/src/refspec.rs +++ b/src/refspec.rs @@ -1,5 +1,5 @@ -use std::c_str::ToCStr; -use std::kinds::marker; +use std::marker; +use std::ffi::CString; use std::str; use {raw, Direction}; @@ -47,7 +47,7 @@ impl<'remote> Refspec<'remote> { /// Check if a refspec's destination descriptor matches a reference pub fn dst_matches(&self, refname: &str) -> bool { - let refname = refname.to_c_str(); + let refname = CString::from_slice(refname.as_bytes()); unsafe { raw::git_refspec_dst_matches(self.raw, refname.as_ptr()) == 1 } } @@ -65,7 +65,7 @@ impl<'remote> Refspec<'remote> { /// Check if a refspec's source descriptor matches a reference pub fn src_matches(&self, refname: &str) -> bool { - let refname = refname.to_c_str(); + let refname = CString::from_slice(refname.as_bytes()); unsafe { raw::git_refspec_src_matches(self.raw, refname.as_ptr()) == 1 } } diff --git a/src/remote.rs b/src/remote.rs index 5e9bbc231b..81329799c1 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -1,5 +1,5 @@ -use std::c_str::{CString, ToCStr}; -use std::kinds::marker; +use std::ffi::CString; +use std::marker; use std::mem; use std::slice; use std::str; @@ -50,7 +50,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { /// Ensure the remote name is well-formed. pub fn is_valid_name(remote_name: &str) -> bool { ::init(); - let remote_name = remote_name.to_c_str(); + let remote_name = CString::from_slice(remote_name.as_bytes()); unsafe { raw::git_remote_is_valid_name(remote_name.as_ptr()) == 1 } } @@ -123,7 +123,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { /// Add a fetch refspec to the remote pub fn add_fetch(&mut self, spec: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_remote_add_fetch(self.raw, spec.to_c_str())); + try_call!(raw::git_remote_add_fetch(self.raw, CString::from_slice(spec.as_bytes()))); } Ok(()) } @@ -131,7 +131,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { /// Add a push refspec to the remote pub fn add_push(&mut self, spec: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_remote_add_push(self.raw, spec.to_c_str())); + try_call!(raw::git_remote_add_push(self.raw, CString::from_slice(spec.as_bytes()))); } Ok(()) } @@ -141,7 +141,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { /// Existing connections will not be updated. pub fn set_url(&mut self, url: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_remote_set_url(self.raw, url.to_c_str())); + try_call!(raw::git_remote_set_url(self.raw, CString::from_slice(url.as_bytes()))); } Ok(()) } @@ -152,7 +152,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { /// /// Existing connections will not be updated. pub fn set_pushurl(&mut self, pushurl: Option<&str>) -> Result<(), Error> { - let pushurl = pushurl.map(|s| s.to_c_str()); + let pushurl = pushurl.map(|s| CString::from_slice(s.as_bytes())); unsafe { try_call!(raw::git_remote_set_pushurl(self.raw, pushurl)); } @@ -168,9 +168,10 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { } /// Set the remote's list of fetch refspecs - pub fn set_fetch_refspecs>(&mut self, i: I) + pub fn set_fetch_refspecs>(&mut self, i: I) -> Result<(), Error> { - let v = i.map(|t| t.to_c_str()).collect::>(); + let v = i.map(|t| CString::from_slice(t.as_slice().as_bytes())) + .collect::>(); let v2 = v.iter().map(|v| v.as_ptr()).collect::>(); let mut arr = raw::git_strarray { strings: v2.as_ptr() as *mut _, @@ -184,9 +185,10 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { } /// Set the remote's list of push refspecs - pub fn set_push_refspecs>(&mut self, i: I) + pub fn set_push_refspecs>(&mut self, i: I) -> Result<(), Error> { - let v = i.map(|t| t.to_c_str()).collect::>(); + let v = i.map(|t| CString::from_slice(t.as_slice().as_bytes())) + .collect::>(); let v2 = v.iter().map(|v| v.as_ptr()).collect::>(); let mut arr = raw::git_strarray { strings: v2.as_ptr() as *mut _, @@ -236,7 +238,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { refspecs: &[&str], signature: Option<&Signature>, msg: Option<&str>) -> Result<(), Error> { - let refspecs = refspecs.iter().map(|s| s.to_c_str()).collect::>(); + let refspecs = refspecs.iter().map(|s| CString::from_slice(s.as_bytes())).collect::>(); let ptrs = refspecs.iter().map(|s| s.as_ptr()).collect::>(); let arr = raw::git_strarray { strings: ptrs.as_ptr() as *mut _, @@ -248,7 +250,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { &arr, &*signature.map(|s| s.raw()) .unwrap_or(0 as *mut _), - msg.map(|s| s.to_c_str()))); + msg.map(|s| CString::from_slice(s.as_bytes())))); } Ok(()) } @@ -260,7 +262,7 @@ impl<'repo, 'cb> Remote<'repo, 'cb> { try_call!(raw::git_remote_update_tips(self.raw, &*signature.map(|s| s.raw()) .unwrap_or(0 as *mut _), - msg.map(|s| s.to_c_str()))); + msg.map(|s| CString::from_slice(s.as_bytes())))); } Ok(()) } diff --git a/src/remote_callbacks.rs b/src/remote_callbacks.rs index a63038c702..e66257225a 100644 --- a/src/remote_callbacks.rs +++ b/src/remote_callbacks.rs @@ -1,7 +1,8 @@ -use std::c_str::CString; -use std::kinds::marker; +use std::ffi::c_str_to_bytes; +use std::marker; use std::mem; use std::slice; +use std::str; use libc::{c_void, c_int, c_char, c_uint}; use {raw, panic, Error, Cred, CredentialType, Oid}; @@ -203,20 +204,19 @@ extern fn credentials_cb(ret: *mut *mut raw::git_cred, None => return raw::GIT_PASSTHROUGH as c_int, }; *ret = 0 as *mut raw::git_cred; - let url = CString::new(url, false); - let url = match url.as_str() { - Some(url) => url, - None => return raw::GIT_PASSTHROUGH as c_int, + let url = match str::from_utf8(c_str_to_bytes(&url)) { + Ok(url) => url, + Err(_) => return raw::GIT_PASSTHROUGH as c_int, }; let username_from_url = if username_from_url.is_null() { None } else { - Some(CString::new(username_from_url, false)) + Some(c_str_to_bytes(&username_from_url)) }; let username_from_url = match username_from_url { - Some(ref username) => match username.as_str() { - Some(s) => Some(s), - None => return raw::GIT_PASSTHROUGH as c_int, + Some(username) => match str::from_utf8(username) { + Ok(s) => Some(s), + Err(_) => return raw::GIT_PASSTHROUGH as c_int, }, None => None, }; @@ -286,8 +286,7 @@ extern fn update_tips_cb(refname: *const c_char, Some(ref mut c) => c, None => return 0, }; - let refname = CString::new(refname, false); - let refname = refname.as_str().unwrap(); + let refname = str::from_utf8(c_str_to_bytes(&refname)).ok().unwrap(); let a = Oid::from_raw(a); let b = Oid::from_raw(b); let ok = panic::wrap(|| { diff --git a/src/repo.rs b/src/repo.rs index 57d0b14329..e8659b84a9 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,5 +1,5 @@ -use std::c_str::{CString, ToCStr}; -use std::kinds::marker; +use std::ffi::{CString, c_str_to_bytes}; +use std::marker; use std::mem; use std::str; use libc::{c_int, c_char, size_t, c_void, c_uint}; @@ -46,7 +46,7 @@ impl Repository { init(); let mut ret = 0 as *mut raw::git_repository; unsafe { - try_call!(raw::git_repository_open(&mut ret, path.to_c_str())); + try_call!(raw::git_repository_open(&mut ret, CString::from_slice(path.as_vec()))); } Ok(unsafe { Repository::from_raw(ret) }) } @@ -60,7 +60,7 @@ impl Repository { unsafe { let mut raw: raw::git_buf = mem::zeroed(); try_call!(raw::git_repository_discover(&mut raw, - path.to_c_str(), + CString::from_slice(path.as_vec()), 1i32, 0 as *const c_char)); let buf = Buf::from_raw(raw); @@ -94,7 +94,7 @@ impl Repository { unsafe { let mut opts = opts.raw(); try_call!(raw::git_repository_init_ext(&mut ret, - path.to_c_str(), + CString::from_slice(path.as_vec()), &mut opts)); } Ok(unsafe { Repository::from_raw(ret) }) @@ -130,7 +130,7 @@ impl Repository { flags: 0, }; unsafe { - try_call!(raw::git_revparse(&mut raw, self.raw, spec.to_c_str())); + try_call!(raw::git_revparse(&mut raw, self.raw, CString::from_slice(spec.as_bytes()))); } let to = if raw.to.is_null() { @@ -152,7 +152,7 @@ impl Repository { let mut obj = 0 as *mut raw::git_object; unsafe { try_call!(raw::git_revparse_single(&mut obj, self.raw, - spec.to_c_str())); + CString::from_slice(spec.as_bytes()))); } assert!(!obj.is_null()); Ok(unsafe { Object::from_raw(obj) }) @@ -182,7 +182,7 @@ impl Repository { unsafe { let ptr = raw::git_repository_path(self.raw); assert!(!ptr.is_null()); - Path::new(CString::new(ptr, false).as_bytes_no_nul()) + Path::new(CString::from_slice(c_str_to_bytes(&ptr))) } } @@ -221,7 +221,7 @@ impl Repository { if ptr.is_null() { None } else { - Some(Path::new(CString::new(ptr, false).as_bytes_no_nul())) + Some(Path::new(CString::from_slice(c_str_to_bytes(&ptr)))) } } } @@ -258,7 +258,7 @@ impl Repository { let mut ret = 0 as *mut raw::git_remote; unsafe { try_call!(raw::git_remote_lookup(&mut ret, self.raw, - name.to_c_str())); + CString::from_slice(name.as_bytes()))); Ok(Remote::from_raw(ret)) } } @@ -269,7 +269,8 @@ impl Repository { let mut ret = 0 as *mut raw::git_remote; unsafe { try_call!(raw::git_remote_create(&mut ret, self.raw, - name.to_c_str(), url.to_c_str())); + CString::from_slice(name.as_bytes()), + CString::from_slice(url.as_bytes()))); Ok(Remote::from_raw(ret)) } } @@ -283,10 +284,10 @@ impl Repository { url: &str, fetch: Option<&str>) -> Result { let mut ret = 0 as *mut raw::git_remote; - let fetch = fetch.map(|t| t.to_c_str()); + let fetch = fetch.map(|t| CString::from_slice(t.as_bytes())); unsafe { try_call!(raw::git_remote_create_anonymous(&mut ret, self.raw, - url.to_c_str(), + CString::from_slice(url.as_bytes()), fetch)); Ok(Remote::from_raw(ret)) } @@ -307,8 +308,8 @@ impl Repository { unsafe { try_call!(raw::git_remote_rename(&mut problems, self.raw, - name.to_c_str(), - new_name.to_c_str())); + CString::from_slice(name.as_bytes()), + CString::from_slice(new_name.as_bytes()))); let _s = StringArray::from_raw(problems); } Ok(()) @@ -319,7 +320,7 @@ impl Repository { /// All remote-tracking branches and configuration settings for the remote /// will be removed. pub fn remote_delete(&self, name: &str) -> Result<(), Error> { - unsafe { try_call!(raw::git_remote_delete(self.raw, name.to_c_str())); } + unsafe { try_call!(raw::git_remote_delete(self.raw, CString::from_slice(name.as_bytes()))); } Ok(()) } @@ -345,7 +346,7 @@ impl Repository { // FIXME: expose git_checkout_options_t 0 as *mut _, sig.map(|s| s.raw()).unwrap_or(0 as *mut _), - msg.map(|s| s.to_c_str()))); + msg.map(|s| CString::from_slice(s.as_bytes())))); } Ok(()) } @@ -358,11 +359,12 @@ impl Repository { /// Passing a `None` target will result in removing entries in the index /// matching the provided pathspecs. pub fn reset_default<'a, - T: ToCStr, + T: Str, I: Iterator>(&'a self, target: Option<&Object<'a>>, paths: I) -> Result<(), Error> { - let v = paths.map(|t| t.to_c_str()).collect::>(); + let v = paths.map(|t| CString::from_slice(t.as_slice().as_bytes())) + .collect::>(); let v2 = v.iter().map(|v| v.as_ptr()).collect::>(); let mut arr = raw::git_strarray { strings: v2.as_ptr() as *mut _, @@ -400,7 +402,7 @@ impl Repository { let mut ret = 0 as *mut raw::git_reference_iterator; unsafe { try_call!(raw::git_reference_iterator_glob_new(&mut ret, self.raw, - glob.to_c_str())); + CString::from_slice(glob.as_bytes()))); Ok(References::from_raw(ret)) } } @@ -469,7 +471,7 @@ impl Repository { let mut ret = 0 as c_int; unsafe { try_call!(raw::git_status_should_ignore(&mut ret, self.raw, - path.to_c_str())); + CString::from_slice(path.as_vec()))); } Ok(ret != 0) } @@ -494,7 +496,7 @@ impl Repository { let mut ret = 0 as c_uint; unsafe { try_call!(raw::git_status_file(&mut ret, self.raw, - path.to_c_str())); + CString::from_slice(path.as_vec()))); } Ok(Status::from_bits_truncate(ret as u32)) } @@ -558,7 +560,7 @@ impl Repository { let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ] }; unsafe { try_call!(raw::git_blob_create_fromdisk(&mut raw, self.raw(), - path.to_c_str())); + CString::from_slice(path.as_vec()))); Ok(Oid::from_raw(&raw)) } } @@ -587,12 +589,12 @@ impl Repository { unsafe { try_call!(raw::git_branch_create(&mut raw, self.raw(), - branch_name.to_c_str(), + CString::from_slice(branch_name.as_bytes()), &*target.raw(), force, &*signature.map(|s| s.raw()) .unwrap_or(0 as *mut _), - log_message.map(|s| s.to_c_str()))); + log_message.map(|s| CString::from_slice(s.as_bytes())))); Ok(Branch::wrap(Reference::from_raw(raw))) } } @@ -603,7 +605,7 @@ impl Repository { let mut ret = 0 as *mut raw::git_reference; unsafe { try_call!(raw::git_branch_lookup(&mut ret, self.raw(), - name.to_c_str(), branch_type)); + CString::from_slice(name.as_bytes()), branch_type)); Ok(Branch::wrap(Reference::from_raw(ret))) } } @@ -630,11 +632,11 @@ impl Repository { unsafe { try_call!(raw::git_commit_create(&mut raw, self.raw(), - update_ref.map(|s| s.to_c_str()), + update_ref.map(|s| CString::from_slice(s.as_bytes())), &*author.raw(), &*committer.raw(), 0 as *const c_char, - message.to_c_str(), + CString::from_slice(message.as_bytes()), &*tree.raw(), parents.len() as size_t, parent_ptrs.as_ptr())); @@ -674,11 +676,11 @@ impl Repository { let mut raw = 0 as *mut raw::git_reference; unsafe { try_call!(raw::git_reference_create(&mut raw, self.raw(), - name.to_c_str(), + CString::from_slice(name.as_bytes()), &*id.raw(), force, &*sig.map(|s| s.raw()) .unwrap_or(0 as *mut _), - log_message.to_c_str())); + CString::from_slice(log_message.as_bytes()))); Ok(Reference::from_raw(raw)) } } @@ -695,12 +697,12 @@ impl Repository { let mut raw = 0 as *mut raw::git_reference; unsafe { try_call!(raw::git_reference_symbolic_create(&mut raw, self.raw(), - name.to_c_str(), - target.to_c_str(), + CString::from_slice(name.as_bytes()), + CString::from_slice(target.as_bytes()), force, &*sig.map(|s| s.raw()) .unwrap_or(0 as *mut _), - log_message.to_c_str())); + CString::from_slice(log_message.as_bytes()))); Ok(Reference::from_raw(raw)) } } @@ -710,7 +712,7 @@ impl Repository { let mut raw = 0 as *mut raw::git_reference; unsafe { try_call!(raw::git_reference_lookup(&mut raw, self.raw(), - name.to_c_str())); + CString::from_slice(name.as_bytes()))); Ok(Reference::from_raw(raw)) } } @@ -724,7 +726,7 @@ impl Repository { let mut ret: raw::git_oid = unsafe { mem::zeroed() }; unsafe { try_call!(raw::git_reference_name_to_id(&mut ret, self.raw(), - name.to_c_str())); + CString::from_slice(name.as_bytes()))); Ok(Oid::from_raw(&ret)) } } @@ -760,8 +762,8 @@ impl Repository { let mut raw = 0 as *mut raw::git_submodule; unsafe { try_call!(raw::git_submodule_add_setup(&mut raw, self.raw(), - url.to_c_str(), - path.to_c_str(), + CString::from_slice(url.as_bytes()), + CString::from_slice(path.as_vec()), use_gitlink)); Ok(Submodule::from_raw(raw)) } @@ -775,7 +777,7 @@ impl Repository { let mut raw = 0 as *mut raw::git_submodule; unsafe { try_call!(raw::git_submodule_lookup(&mut raw, self.raw(), - name.to_c_str())); + CString::from_slice(name.as_bytes()))); Ok(Submodule::from_raw(raw)) } } @@ -805,9 +807,9 @@ impl Repository { force: bool) -> Result { let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ] }; unsafe { - try_call!(raw::git_tag_create(&mut raw, self.raw, name.to_c_str(), + try_call!(raw::git_tag_create(&mut raw, self.raw, CString::from_slice(name.as_bytes()), &*target.raw(), &*tagger.raw(), - message.to_c_str(), force)); + CString::from_slice(message.as_bytes()), force)); Ok(Oid::from_raw(&raw)) } } @@ -827,7 +829,7 @@ impl Repository { /// about valid names. pub fn tag_delete(&self, name: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_tag_delete(self.raw, name.to_c_str())); + try_call!(raw::git_tag_delete(self.raw, CString::from_slice(name.as_bytes()))); Ok(()) } } @@ -843,7 +845,7 @@ impl Repository { unsafe { match pattern { Some(s) => { - try_call!(raw::git_tag_list_match(&mut arr, s.to_c_str(), + try_call!(raw::git_tag_list_match(&mut arr, CString::from_slice(s.as_bytes()), self.raw)); } None => { try_call!(raw::git_tag_list(&mut arr, self.raw)); } @@ -928,11 +930,11 @@ impl Repository { unsafe { try_call!(raw::git_note_create(&mut ret, self.raw, - notes_ref.map(|s| s.to_c_str()), + notes_ref.map(|s| CString::from_slice(s.as_bytes())), &*author.raw(), &*committer.raw(), &*oid.raw(), - note.to_c_str(), + CString::from_slice(note.as_bytes()), force)); Ok(Oid::from_raw(&ret)) } @@ -959,7 +961,7 @@ impl Repository { let mut ret = 0 as *mut raw::git_note_iterator; unsafe { try_call!(raw::git_note_iterator_new(&mut ret, self.raw, - notes_ref.map(|s| s.to_c_str()))); + notes_ref.map(|s| CString::from_slice(s.as_bytes())))); Ok(Notes::from_raw(ret)) } } @@ -975,7 +977,7 @@ impl Repository { let mut ret = 0 as *mut raw::git_note; unsafe { try_call!(raw::git_note_read(&mut ret, self.raw, - notes_ref.map(|s| s.to_c_str()), + notes_ref.map(|s| CString::from_slice(s.as_bytes())), &*id.raw())); Ok(Note::from_raw(ret)) } @@ -994,7 +996,7 @@ impl Repository { committer: &Signature) -> Result<(), Error> { unsafe { try_call!(raw::git_note_remove(self.raw, - notes_ref.map(|s| s.to_c_str()), + notes_ref.map(|s| CString::from_slice(s.as_bytes())), &*author.raw(), &*committer.raw(), &*id.raw())); @@ -1152,14 +1154,14 @@ impl RepositoryInitOptions { /// path. If this is not the "natural" working directory, a .git gitlink /// file will be created here linking to the repo path. pub fn workdir_path(&mut self, path: &Path) -> &mut RepositoryInitOptions { - self.workdir_path = Some(path.to_c_str()); + self.workdir_path = Some(CString::from_slice(path.as_vec())); self } /// If set, this will be used to initialize the "description" file in the /// repository instead of using the template content. pub fn description(&mut self, desc: &str) -> &mut RepositoryInitOptions { - self.description = Some(desc.to_c_str()); + self.description = Some(CString::from_slice(desc.as_bytes())); self } @@ -1169,7 +1171,7 @@ impl RepositoryInitOptions { /// If this is not configured, then the default locations will be searched /// instead. pub fn template_path(&mut self, path: &Path) -> &mut RepositoryInitOptions { - self.template_path = Some(path.to_c_str()); + self.template_path = Some(CString::from_slice(path.as_vec())); self } @@ -1179,14 +1181,14 @@ impl RepositoryInitOptions { /// will be set to `refs/heads/master`. If this begins with `refs/` it will /// be used verbatim; otherwise `refs/heads/` will be prefixed pub fn initial_head(&mut self, head: &str) -> &mut RepositoryInitOptions { - self.initial_head = Some(head.to_c_str()); + self.initial_head = Some(CString::from_slice(head.as_bytes())); self } /// If set, then after the rest of the repository initialization is /// completed an `origin` remote will be added pointing to this URL. pub fn origin_url(&mut self, url: &str) -> &mut RepositoryInitOptions { - self.origin_url = Some(url.to_c_str()); + self.origin_url = Some(CString::from_slice(url.as_bytes())); self } diff --git a/src/revwalk.rs b/src/revwalk.rs index 338d399b00..61b18f9bbc 100644 --- a/src/revwalk.rs +++ b/src/revwalk.rs @@ -1,7 +1,7 @@ extern crate libc; -use std::c_str::ToCStr; -use std::kinds::marker; +use std::marker; +use std::ffi::CString; use {raw, Error, Sort, Oid}; @@ -80,7 +80,7 @@ impl<'repo> Revwalk<'repo> { /// will be ignored. pub fn push_glob(&mut self, glob: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_revwalk_push_glob(self.raw, glob.to_c_str())); + try_call!(raw::git_revwalk_push_glob(self.raw, CString::from_slice(glob.as_bytes()))); } Ok(()) } @@ -92,7 +92,7 @@ impl<'repo> Revwalk<'repo> { /// commit will be hidden and the right-hand commit pushed. pub fn push_range(&mut self, range: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_revwalk_push_range(self.raw, range.to_c_str())); + try_call!(raw::git_revwalk_push_range(self.raw, CString::from_slice(range.as_bytes()))); } Ok(()) } @@ -102,7 +102,7 @@ impl<'repo> Revwalk<'repo> { /// The reference must point to a committish. pub fn push_ref(&mut self, reference: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_revwalk_push_ref(self.raw, reference.to_c_str())); + try_call!(raw::git_revwalk_push_ref(self.raw, CString::from_slice(reference.as_bytes()))); } Ok(()) } @@ -137,7 +137,7 @@ impl<'repo> Revwalk<'repo> { /// will be ignored. pub fn hide_glob(&mut self, glob: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_revwalk_hide_glob(self.raw, glob.to_c_str())); + try_call!(raw::git_revwalk_hide_glob(self.raw, CString::from_slice(glob.as_bytes()))); } Ok(()) } @@ -147,7 +147,7 @@ impl<'repo> Revwalk<'repo> { /// The reference must point to a committish. pub fn hide_ref(&mut self, reference: &str) -> Result<(), Error> { unsafe { - try_call!(raw::git_revwalk_hide_ref(self.raw, reference.to_c_str())); + try_call!(raw::git_revwalk_hide_ref(self.raw, CString::from_slice(reference.as_bytes()))); } Ok(()) } diff --git a/src/signature.rs b/src/signature.rs index 8c9c54f126..6e292cf147 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -1,6 +1,6 @@ -use std::c_str::ToCStr; use std::str; -use std::kinds::marker; +use std::marker; +use std::ffi::CString; use libc; use {raw, Error, Time}; @@ -25,8 +25,8 @@ impl<'a> Signature<'a> { ::init(); let mut ret = 0 as *mut raw::git_signature; unsafe { - try_call!(raw::git_signature_now(&mut ret, name.to_c_str(), - email.to_c_str())); + try_call!(raw::git_signature_now(&mut ret, CString::from_slice(name.as_bytes()), + CString::from_slice(email.as_bytes()))); Ok(Signature::from_raw(ret)) } } @@ -42,8 +42,8 @@ impl<'a> Signature<'a> { ::init(); let mut ret = 0 as *mut raw::git_signature; unsafe { - try_call!(raw::git_signature_new(&mut ret, name.to_c_str(), - email.to_c_str(), + try_call!(raw::git_signature_new(&mut ret, CString::from_slice(name.as_bytes()), + CString::from_slice(email.as_bytes()), time as raw::git_time_t, offset as libc::c_int)); Ok(Signature::from_raw(ret)) diff --git a/src/status.rs b/src/status.rs index 3ccee1e024..7aa8ba287a 100644 --- a/src/status.rs +++ b/src/status.rs @@ -1,6 +1,6 @@ -use std::c_str::{CString, ToCStr}; +use std::ffi::CString; use std::iter::{range, Range}; -use std::kinds::marker; +use std::marker; use std::mem; use std::str; use libc::{c_char, size_t, c_uint}; @@ -89,8 +89,8 @@ impl StatusOptions { /// If the `disable_pathspec_match` option is given, then this is a literal /// path to match. If this is not called, then there will be no patterns to /// match and the entire directory will be used. - pub fn pathspec(&mut self, pathspec: T) -> &mut StatusOptions { - let s = pathspec.to_c_str(); + pub fn pathspec(&mut self, pathspec: T) -> &mut StatusOptions { + let s = CString::from_slice(pathspec.as_slice().as_bytes()); self.ptrs.push(s.as_ptr()); self.pathspec.push(s); self diff --git a/src/submodule.rs b/src/submodule.rs index ffcf17167c..e1d926828a 100644 --- a/src/submodule.rs +++ b/src/submodule.rs @@ -1,5 +1,5 @@ use std::str; -use std::kinds::marker; +use std::marker; use {raw, Oid, Repository, Error, SubmoduleStatus}; diff --git a/src/tag.rs b/src/tag.rs index d5177d67cb..60f9217ed8 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -1,4 +1,4 @@ -use std::kinds::marker; +use std::marker; use std::str; use {raw, Error, Oid, Object, Signature, ObjectType}; diff --git a/src/tree.rs b/src/tree.rs index 9f96393c01..0991baaef6 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -1,8 +1,8 @@ -use std::c_str::ToCStr; use std::cmp::Ordering; use std::io; -use std::kinds::marker; +use std::marker; use std::str; +use std::ffi::CString; use libc; use {raw, Oid, Repository, Error, Object, ObjectType}; @@ -77,7 +77,7 @@ impl<'repo> Tree<'repo> { pub fn get_name(&self, filename: &str) -> Option { unsafe { let ptr = call!(raw::git_tree_entry_byname(&*self.raw(), - filename.to_c_str())); + CString::from_slice(filename.as_bytes()))); if ptr.is_null() { None } else { @@ -93,7 +93,7 @@ impl<'repo> Tree<'repo> { unsafe { try_call!(raw::git_tree_entry_bypath(&mut ret, &*self.raw(), - path.to_c_str())); + CString::from_slice(path.as_vec()))); Ok(TreeEntry::from_raw(ret)) } }