Skip to content

Commit

Permalink
Start making the library build with alpha compiler
Browse files Browse the repository at this point in the history
Mostly fixing issues related to rust-lang/rust#20507

The examples still aren't compiling, but I figured this might be a good starting
point for finishing the upgrade.
  • Loading branch information
zmbush committed Jan 10, 2015
1 parent b22ff68 commit 4849ec9
Show file tree
Hide file tree
Showing 30 changed files with 240 additions and 225 deletions.
1 change: 1 addition & 0 deletions examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![feature(macro_rules)]
#![deny(warnings)]
#![allow(unstable)]

extern crate "rustc-serialize" as rustc_serialize;
extern crate docopt;
Expand Down
1 change: 1 addition & 0 deletions examples/rev-parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

#![deny(warnings)]
#![allow(unstable)]

extern crate git2;
extern crate docopt;
Expand Down
4 changes: 2 additions & 2 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(globs, phase)]
#![allow(non_camel_case_types, missing_copy_implementations)]

extern crate libc;
Expand Down Expand Up @@ -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],
}
Expand Down
2 changes: 1 addition & 1 deletion src/blob.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::kinds::marker;
use std::marker;
use std::mem;
use std::raw as stdraw;

Expand Down
10 changes: 5 additions & 5 deletions src/branch.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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)))
}
}
Expand Down Expand Up @@ -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));
Expand Down
24 changes: 12 additions & 12 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -342,34 +342,34 @@ 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<T: ToCStr>(&mut self, path: T) -> &mut CheckoutBuilder<'cb> {
let path = path.to_c_str();
pub fn path<T: Str>(&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
}

/// 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
}

Expand Down Expand Up @@ -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);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![macro_escape]
#![macro_use]
use libc;

use Error;
Expand Down Expand Up @@ -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};
Expand Down
10 changes: 5 additions & 5 deletions src/commit.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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))
}
Expand Down
32 changes: 16 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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(())
}
}
Expand All @@ -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})
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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())
}
}
Expand All @@ -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))
}
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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(())
Expand All @@ -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(())
Expand All @@ -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(())
Expand All @@ -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(())
}
Expand Down
16 changes: 8 additions & 8 deletions src/cred.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::c_str::ToCStr;
use std::ffi::CString;
use std::mem;
use std::io::Command;
use url::{self, UrlParser};
Expand Down Expand Up @@ -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))
}
}
Expand All @@ -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))
}
}
Expand All @@ -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))
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/diff.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<T: ToCStr>(&mut self, t: T) -> &mut DiffOptions {
self.old_prefix = Some(t.to_c_str());
pub fn old_prefix<T: Str>(&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<T: ToCStr>(&mut self, t: T) -> &mut DiffOptions {
self.new_prefix = Some(t.to_c_str());
pub fn new_prefix<T: Str>(&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<T: ToCStr>(&mut self, pathspec: T) -> &mut DiffOptions {
let s = pathspec.to_c_str();
pub fn pathspec<T: Str>(&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
Expand Down
Loading

0 comments on commit 4849ec9

Please sign in to comment.