Skip to content

Commit 4849ec9

Browse files
committed
Start making the library build with alpha compiler
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.
1 parent b22ff68 commit 4849ec9

30 files changed

+240
-225
lines changed

examples/log.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#![feature(macro_rules)]
1616
#![deny(warnings)]
17+
#![allow(unstable)]
1718

1819
extern crate "rustc-serialize" as rustc_serialize;
1920
extern crate docopt;

examples/rev-parse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#![deny(warnings)]
16+
#![allow(unstable)]
1617

1718
extern crate git2;
1819
extern crate docopt;

libgit2-sys/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(globs, phase)]
21
#![allow(non_camel_case_types, missing_copy_implementations)]
32

43
extern crate libc;
@@ -78,13 +77,14 @@ pub struct git_revspec {
7877
}
7978

8079
#[repr(C)]
80+
#[derive(Show)]
8181
pub struct git_error {
8282
pub message: *mut c_char,
8383
pub klass: c_int,
8484
}
8585

8686
#[repr(C)]
87-
#[derive(Copy)]
87+
#[derive(Copy,Show)]
8888
pub struct git_oid {
8989
pub id: [u8; GIT_OID_RAWSZ],
9090
}

src/blob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::kinds::marker;
1+
use std::marker;
22
use std::mem;
33
use std::raw as stdraw;
44

src/branch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::c_str::ToCStr;
2-
use std::kinds::marker;
1+
use std::ffi::CString;
2+
use std::marker;
33
use std::str;
44
use libc;
55

@@ -49,11 +49,11 @@ impl<'repo> Branch<'repo> {
4949
let mut ret = 0 as *mut raw::git_reference;
5050
unsafe {
5151
try_call!(raw::git_branch_move(&mut ret, self.get().raw(),
52-
new_branch_name.to_c_str(),
52+
CString::from_slice(new_branch_name.as_bytes()),
5353
force,
5454
&*signature.map(|s| s.raw())
5555
.unwrap_or(0 as *mut _),
56-
log_message.to_c_str()));
56+
CString::from_slice(log_message.as_bytes())));
5757
Ok(Branch::wrap(Reference::from_raw(ret)))
5858
}
5959
}
@@ -90,7 +90,7 @@ impl<'repo> Branch<'repo> {
9090
/// provided is the name of the branch to set as upstream.
9191
pub fn set_upstream(&mut self,
9292
upstream_name: Option<&str>) -> Result<(), Error> {
93-
let upstream_name = upstream_name.map(|s| s.to_c_str());
93+
let upstream_name = upstream_name.map(|s| CString::from_slice(s.as_bytes()));
9494
unsafe {
9595
try_call!(raw::git_branch_set_upstream(self.get().raw(),
9696
upstream_name));

src/build.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Builder-pattern objects for configuration various git operations.
22
3-
use std::c_str::{CString, ToCStr};
3+
use std::ffi::{CString, c_str_to_bytes};
44
use std::io;
55
use std::mem;
66
use libc::{c_char, size_t, c_void, c_uint, c_int};
@@ -70,7 +70,7 @@ impl<'cb> RepoBuilder<'cb> {
7070
///
7171
/// If not specified, the remote's default branch will be used.
7272
pub fn branch(&mut self, branch: &str) -> &mut RepoBuilder<'cb> {
73-
self.branch = Some(branch.to_c_str());
73+
self.branch = Some(CString::from_slice(branch.as_bytes()));
7474
self
7575
}
7676

@@ -154,8 +154,8 @@ impl<'cb> RepoBuilder<'cb> {
154154

155155
let mut raw = 0 as *mut raw::git_repository;
156156
unsafe {
157-
try_call!(raw::git_clone(&mut raw, url.to_c_str(),
158-
into.to_c_str(), &opts));
157+
try_call!(raw::git_clone(&mut raw, CString::from_slice(url.as_bytes()),
158+
CString::from_slice(into.as_vec()), &opts));
159159
Ok(Repository::from_raw(raw))
160160
}
161161
}
@@ -342,34 +342,34 @@ impl<'cb> CheckoutBuilder<'cb> {
342342
///
343343
/// If no paths are specified, then all files are checked out. Otherwise
344344
/// only these specified paths are checked out.
345-
pub fn path<T: ToCStr>(&mut self, path: T) -> &mut CheckoutBuilder<'cb> {
346-
let path = path.to_c_str();
345+
pub fn path<T: Str>(&mut self, path: T) -> &mut CheckoutBuilder<'cb> {
346+
let path = CString::from_slice(path.as_slice().as_bytes());
347347
self.path_ptrs.push(path.as_ptr());
348348
self.paths.push(path);
349349
self
350350
}
351351

352352
/// Set the directory to check out to
353353
pub fn target_dir(&mut self, dst: Path) -> &mut CheckoutBuilder<'cb> {
354-
self.target_dir = Some(dst.to_c_str());
354+
self.target_dir = Some(CString::from_slice(dst.as_vec()));
355355
self
356356
}
357357

358358
/// The name of the common ancestor side of conflicts
359359
pub fn ancestor_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> {
360-
self.ancestor_label = Some(label.to_c_str());
360+
self.ancestor_label = Some(CString::from_slice(label.as_bytes()));
361361
self
362362
}
363363

364364
/// The name of the common our side of conflicts
365365
pub fn our_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> {
366-
self.our_label = Some(label.to_c_str());
366+
self.our_label = Some(CString::from_slice(label.as_bytes()));
367367
self
368368
}
369369

370370
/// The name of the common their side of conflicts
371371
pub fn their_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> {
372-
self.their_label = Some(label.to_c_str());
372+
self.their_label = Some(CString::from_slice(label.as_bytes()));
373373
self
374374
}
375375

@@ -430,9 +430,9 @@ extern fn progress_cb(path: *const c_char,
430430
Some(ref mut c) => c,
431431
None => return,
432432
};
433-
let path = CString::new(path, false);
433+
let path = CString::from_slice(c_str_to_bytes(&path));
434434
panic::wrap(|| {
435-
callback(path.as_bytes_no_nul(), completed as uint, total as uint);
435+
callback(path.as_bytes(), completed as uint, total as uint);
436436
});
437437
}
438438
}

src/call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![macro_escape]
1+
#![macro_use]
22
use libc;
33

44
use Error;
@@ -41,7 +41,7 @@ fn last_error() -> Error {
4141
}
4242

4343
mod impls {
44-
use std::c_str::CString;
44+
use std::ffi::CString;
4545
use libc;
4646

4747
use {raw, ConfigLevel, ResetType, ObjectType, BranchType, Direction};

src/commit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::c_str::ToCStr;
1+
use std::ffi::CString;
22
use std::iter::Range;
3-
use std::kinds::marker;
3+
use std::marker;
44
use std::str;
55
use libc;
66

@@ -206,11 +206,11 @@ impl<'repo> Commit<'repo> {
206206
unsafe {
207207
try_call!(raw::git_commit_amend(&mut raw,
208208
&*self.raw(),
209-
update_ref.map(|s| s.to_c_str()),
209+
update_ref.map(|s| CString::from_slice(s.as_bytes())),
210210
author.map(|s| &*s.raw()),
211211
committer.map(|s| &*s.raw()),
212-
message_encoding.map(|s| s.to_c_str()),
213-
message.map(|s| s.to_c_str()),
212+
message_encoding.map(|s| CString::from_slice(s.as_bytes())),
213+
message.map(|s| CString::from_slice(s.as_bytes())),
214214
tree.map(|t| &*t.raw())));
215215
Ok(Oid::from_raw(&raw))
216216
}

src/config.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::c_str::ToCStr;
2-
use std::kinds::marker;
1+
use std::ffi::CString;
2+
use std::marker;
33
use std::str;
44
use libc;
55

@@ -44,7 +44,7 @@ impl Config {
4444
::init();
4545
let mut raw = 0 as *mut raw::git_config;
4646
unsafe {
47-
try_call!(raw::git_config_open_ondisk(&mut raw, path.to_c_str()));
47+
try_call!(raw::git_config_open_ondisk(&mut raw, CString::from_slice(path.as_vec())));
4848
Ok(Config::from_raw(raw))
4949
}
5050
}
@@ -124,7 +124,7 @@ impl Config {
124124
pub fn add_file(&mut self, path: &Path, level: ConfigLevel,
125125
force: bool) -> Result<(), Error> {
126126
unsafe {
127-
try_call!(raw::git_config_add_file_ondisk(self.raw, path.to_c_str(),
127+
try_call!(raw::git_config_add_file_ondisk(self.raw, CString::from_slice(path.as_vec()),
128128
level, force));
129129
Ok(())
130130
}
@@ -134,7 +134,7 @@ impl Config {
134134
/// (usually the local one).
135135
pub fn remove(&mut self, name: &str) -> Result<(), Error> {
136136
unsafe {
137-
try_call!(raw::git_config_delete_entry(self.raw, name.to_c_str()));
137+
try_call!(raw::git_config_delete_entry(self.raw, CString::from_slice(name.as_bytes())));
138138
Ok(())
139139
}
140140
}
@@ -148,7 +148,7 @@ impl Config {
148148
let mut out = 0 as libc::c_int;
149149
unsafe {
150150
try_call!(raw::git_config_get_bool(&mut out, &*self.raw,
151-
name.to_c_str()));
151+
CString::from_slice(name.as_bytes())));
152152
}
153153
Ok(if out == 0 {false} else {true})
154154
}
@@ -162,7 +162,7 @@ impl Config {
162162
let mut out = 0i32;
163163
unsafe {
164164
try_call!(raw::git_config_get_int32(&mut out, &*self.raw,
165-
name.to_c_str()));
165+
CString::from_slice(name.as_bytes())));
166166
}
167167
Ok(out)
168168
}
@@ -176,7 +176,7 @@ impl Config {
176176
let mut out = 0i64;
177177
unsafe {
178178
try_call!(raw::git_config_get_int64(&mut out, &*self.raw,
179-
name.to_c_str()));
179+
CString::from_slice(name.as_bytes())));
180180
}
181181
Ok(out)
182182
}
@@ -196,7 +196,7 @@ impl Config {
196196
let mut ret = 0 as *const libc::c_char;
197197
unsafe {
198198
try_call!(raw::git_config_get_string(&mut ret, &*self.raw,
199-
name.to_c_str()));
199+
CString::from_slice(name.as_bytes())));
200200
Ok(::opt_bytes(self, ret).unwrap())
201201
}
202202
}
@@ -206,7 +206,7 @@ impl Config {
206206
let mut ret = 0 as *const raw::git_config_entry;
207207
unsafe {
208208
try_call!(raw::git_config_get_entry(&mut ret, &*self.raw,
209-
name.to_c_str()));
209+
CString::from_slice(name.as_bytes())));
210210
Ok(ConfigEntry::from_raw(ret))
211211
}
212212
}
@@ -234,7 +234,7 @@ impl Config {
234234
Some(s) => {
235235
try_call!(raw::git_config_iterator_glob_new(&mut ret,
236236
&*self.raw,
237-
s.to_c_str()));
237+
CString::from_slice(s.as_bytes())));
238238
}
239239
None => {
240240
try_call!(raw::git_config_iterator_new(&mut ret, &*self.raw));
@@ -274,7 +274,7 @@ impl Config {
274274
/// highest level (usually the local one).
275275
pub fn set_bool(&mut self, name: &str, value: bool) -> Result<(), Error> {
276276
unsafe {
277-
try_call!(raw::git_config_set_bool(self.raw, name.to_c_str(),
277+
try_call!(raw::git_config_set_bool(self.raw, CString::from_slice(name.as_bytes()),
278278
value));
279279
}
280280
Ok(())
@@ -284,7 +284,7 @@ impl Config {
284284
/// highest level (usually the local one).
285285
pub fn set_i32(&mut self, name: &str, value: i32) -> Result<(), Error> {
286286
unsafe {
287-
try_call!(raw::git_config_set_int32(self.raw, name.to_c_str(),
287+
try_call!(raw::git_config_set_int32(self.raw, CString::from_slice(name.as_bytes()),
288288
value));
289289
}
290290
Ok(())
@@ -294,7 +294,7 @@ impl Config {
294294
/// highest level (usually the local one).
295295
pub fn set_i64(&mut self, name: &str, value: i64) -> Result<(), Error> {
296296
unsafe {
297-
try_call!(raw::git_config_set_int64(self.raw, name.to_c_str(),
297+
try_call!(raw::git_config_set_int64(self.raw, CString::from_slice(name.as_bytes()),
298298
value));
299299
}
300300
Ok(())
@@ -304,8 +304,8 @@ impl Config {
304304
/// highest level (usually the local one).
305305
pub fn set_str(&mut self, name: &str, value: &str) -> Result<(), Error> {
306306
unsafe {
307-
try_call!(raw::git_config_set_string(self.raw, name.to_c_str(),
308-
value.to_c_str()));
307+
try_call!(raw::git_config_set_string(self.raw, CString::from_slice(name.as_bytes()),
308+
CString::from_slice(value.as_bytes())));
309309
}
310310
Ok(())
311311
}

src/cred.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::c_str::ToCStr;
1+
use std::ffi::CString;
22
use std::mem;
33
use std::io::Command;
44
use url::{self, UrlParser};
@@ -49,7 +49,7 @@ impl Cred {
4949
let mut out = 0 as *mut raw::git_cred;
5050
unsafe {
5151
try_call!(raw::git_cred_ssh_key_from_agent(&mut out,
52-
username.to_c_str()));
52+
CString::from_slice(username.as_bytes())));
5353
Ok(Cred::from_raw(out))
5454
}
5555
}
@@ -63,10 +63,10 @@ impl Cred {
6363
let mut out = 0 as *mut raw::git_cred;
6464
unsafe {
6565
try_call!(raw::git_cred_ssh_key_new(&mut out,
66-
username.to_c_str(),
67-
publickey.map(|s| s.to_c_str()),
68-
privatekey.to_c_str(),
69-
passphrase.map(|s| s.to_c_str())));
66+
CString::from_slice(username.as_bytes()),
67+
publickey.map(|s| CString::from_slice(s.as_vec())),
68+
CString::from_slice(privatekey.as_vec()),
69+
passphrase.map(|s| CString::from_slice(s.as_bytes()))));
7070
Ok(Cred::from_raw(out))
7171
}
7272
}
@@ -78,8 +78,8 @@ impl Cred {
7878
let mut out = 0 as *mut raw::git_cred;
7979
unsafe {
8080
try_call!(raw::git_cred_userpass_plaintext_new(&mut out,
81-
username.to_c_str(),
82-
password.to_c_str()));
81+
CString::from_slice(username.as_bytes()),
82+
CString::from_slice(password.as_bytes())));
8383
Ok(Cred::from_raw(out))
8484
}
8585
}

src/diff.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::c_str::{CString, ToCStr};
1+
use std::ffi::CString;
22
use std::iter::Range;
3-
use std::kinds::marker;
3+
use std::marker;
44
use std::mem;
55
use std::slice;
66
use libc::{c_char, size_t, c_void, c_int};
@@ -609,22 +609,22 @@ impl DiffOptions {
609609
/// The virtual "directory" to prefix old file names with in hunk headers.
610610
///
611611
/// The default value for this is "a".
612-
pub fn old_prefix<T: ToCStr>(&mut self, t: T) -> &mut DiffOptions {
613-
self.old_prefix = Some(t.to_c_str());
612+
pub fn old_prefix<T: Str>(&mut self, t: T) -> &mut DiffOptions {
613+
self.old_prefix = Some(CString::from_slice(t.as_slice().as_bytes()));
614614
self
615615
}
616616

617617
/// The virtual "directory" to prefix new file names with in hunk headers.
618618
///
619619
/// The default value for this is "b".
620-
pub fn new_prefix<T: ToCStr>(&mut self, t: T) -> &mut DiffOptions {
621-
self.new_prefix = Some(t.to_c_str());
620+
pub fn new_prefix<T: Str>(&mut self, t: T) -> &mut DiffOptions {
621+
self.new_prefix = Some(CString::from_slice(t.as_slice().as_bytes()));
622622
self
623623
}
624624

625625
/// Add to the array of paths/fnmatch patterns to constrain the diff.
626-
pub fn pathspec<T: ToCStr>(&mut self, pathspec: T) -> &mut DiffOptions {
627-
let s = pathspec.to_c_str();
626+
pub fn pathspec<T: Str>(&mut self, pathspec: T) -> &mut DiffOptions {
627+
let s = CString::from_slice(pathspec.as_slice().as_bytes());
628628
self.pathspec_ptrs.push(s.as_ptr());
629629
self.pathspec.push(s);
630630
self

0 commit comments

Comments
 (0)