diff --git a/Cargo.toml b/Cargo.toml index bf76d2e35b..e075984e99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ both threadsafe and memory safe and allows both reading and writing git repositories. """ categories = ["api-bindings"] +edition = "2018" [badges] travis-ci = { repository = "rust-lang/git2-rs" } diff --git a/examples/add.rs b/examples/add.rs index b4440ca5d8..47dc56b281 100644 --- a/examples/add.rs +++ b/examples/add.rs @@ -33,8 +33,8 @@ struct Args { } fn run(args: &Args) -> Result<(), git2::Error> { - let repo = try!(Repository::open(&Path::new("."))); - let mut index = try!(repo.index()); + let repo = Repository::open(&Path::new("."))?; + let mut index = repo.index()?; let cb = &mut |path: &Path, _matched_spec: &[u8]| -> i32 { let status = repo.status_file(path).unwrap(); @@ -61,12 +61,12 @@ fn run(args: &Args) -> Result<(), git2::Error> { }; if args.flag_update { - try!(index.update_all(args.arg_spec.iter(), cb)); + index.update_all(args.arg_spec.iter(), cb)?; } else { - try!(index.add_all(args.arg_spec.iter(), git2::IndexAddOption::DEFAULT, cb)); + index.add_all(args.arg_spec.iter(), git2::IndexAddOption::DEFAULT, cb)?; } - try!(index.write()); + index.write()?; Ok(()) } diff --git a/examples/blame.rs b/examples/blame.rs index 07452dde8d..68f1de20ac 100644 --- a/examples/blame.rs +++ b/examples/blame.rs @@ -33,7 +33,7 @@ struct Args { } fn run(args: &Args) -> Result<(), git2::Error> { - let repo = try!(Repository::open(".")); + let repo = Repository::open(".")?; let path = Path::new(&args.arg_path[..]); // Prepare our blame options @@ -46,7 +46,7 @@ fn run(args: &Args) -> Result<(), git2::Error> { // Parse spec if let Some(spec) = args.arg_spec.as_ref() { - let revspec = try!(repo.revparse(spec)); + let revspec = repo.revparse(spec)?; let (oldest, newest) = if revspec.mode().contains(git2::RevparseMode::SINGLE) { (None, revspec.from()) @@ -69,9 +69,9 @@ fn run(args: &Args) -> Result<(), git2::Error> { } let spec = format!("{}:{}", commit_id, path.display()); - let blame = try!(repo.blame_file(path, Some(&mut opts))); - let object = try!(repo.revparse_single(&spec[..])); - let blob = try!(repo.find_blob(object.id())); + let blame = repo.blame_file(path, Some(&mut opts))?; + let object = repo.revparse_single(&spec[..])?; + let blob = repo.find_blob(object.id())?; let reader = BufReader::new(blob.content()); for (i, line) in reader.lines().enumerate() { diff --git a/examples/cat-file.rs b/examples/cat-file.rs index ae7de5d179..07ead1bfcf 100644 --- a/examples/cat-file.rs +++ b/examples/cat-file.rs @@ -38,9 +38,9 @@ struct Args { fn run(args: &Args) -> Result<(), git2::Error> { let path = args.flag_git_dir.as_ref().map(|s| &s[..]).unwrap_or("."); - let repo = try!(Repository::open(path)); + let repo = Repository::open(path)?; - let obj = try!(repo.revparse_single(&args.arg_object)); + let obj = repo.revparse_single(&args.arg_object)?; if args.flag_v && !args.flag_q { println!("{} {}\n--", obj.kind().unwrap().str(), obj.id()); } diff --git a/examples/clone.rs b/examples/clone.rs index 86553b2d30..bd3a8122c2 100644 --- a/examples/clone.rs +++ b/examples/clone.rs @@ -111,10 +111,10 @@ fn run(args: &Args) -> Result<(), git2::Error> { let mut fo = FetchOptions::new(); fo.remote_callbacks(cb); - try!(RepoBuilder::new() + RepoBuilder::new() .fetch_options(fo) .with_checkout(co) - .clone(&args.arg_url, Path::new(&args.arg_path))); + .clone(&args.arg_url, Path::new(&args.arg_path))?; println!(""); Ok(()) diff --git a/examples/diff.rs b/examples/diff.rs index e4dee88aa1..d109db114d 100644 --- a/examples/diff.rs +++ b/examples/diff.rs @@ -79,7 +79,7 @@ enum Cache { fn run(args: &Args) -> Result<(), Error> { let path = args.flag_git_dir.as_ref().map(|s| &s[..]).unwrap_or("."); - let repo = try!(Repository::open(path)); + let repo = Repository::open(path)?; // Prepare our diff options based on the arguments given let mut opts = DiffOptions::new(); @@ -112,25 +112,25 @@ fn run(args: &Args) -> Result<(), Error> { } // Prepare the diff to inspect - let t1 = try!(tree_to_treeish(&repo, args.arg_from_oid.as_ref())); - let t2 = try!(tree_to_treeish(&repo, args.arg_to_oid.as_ref())); - let head = try!(tree_to_treeish(&repo, Some(&"HEAD".to_string()))).unwrap(); + let t1 = tree_to_treeish(&repo, args.arg_from_oid.as_ref())?; + let t2 = tree_to_treeish(&repo, args.arg_to_oid.as_ref())?; + let head = tree_to_treeish(&repo, Some(&"HEAD".to_string()))?.unwrap(); let mut diff = match (t1, t2, args.cache()) { (Some(t1), Some(t2), _) => { - try!(repo.diff_tree_to_tree(t1.as_tree(), t2.as_tree(), Some(&mut opts))) + repo.diff_tree_to_tree(t1.as_tree(), t2.as_tree(), Some(&mut opts))? } (t1, None, Cache::None) => { let t1 = t1.unwrap_or(head); - try!(repo.diff_tree_to_workdir(t1.as_tree(), Some(&mut opts))) + repo.diff_tree_to_workdir(t1.as_tree(), Some(&mut opts))? } (t1, None, Cache::Only) => { let t1 = t1.unwrap_or(head); - try!(repo.diff_tree_to_index(t1.as_tree(), None, Some(&mut opts))) + repo.diff_tree_to_index(t1.as_tree(), None, Some(&mut opts))? } (Some(t1), None, _) => { - try!(repo.diff_tree_to_workdir_with_index(t1.as_tree(), Some(&mut opts))) + repo.diff_tree_to_workdir_with_index(t1.as_tree(), Some(&mut opts))? } - (None, None, _) => try!(repo.diff_index_to_workdir(None, Some(&mut opts))), + (None, None, _) => repo.diff_index_to_workdir(None, Some(&mut opts))?, (None, Some(_), _) => unreachable!(), }; @@ -151,20 +151,20 @@ fn run(args: &Args) -> Result<(), Error> { } opts.copies_from_unmodified(args.flag_find_copies_harder) .rewrites(args.flag_break_rewrites); - try!(diff.find_similar(Some(&mut opts))); + diff.find_similar(Some(&mut opts))?; } // Generate simple output let stats = args.flag_stat | args.flag_numstat | args.flag_shortstat | args.flag_summary; if stats { - try!(print_stats(&diff, args)); + print_stats(&diff, args)?; } if args.flag_patch || !stats { if args.color() { print!("{}", RESET); } let mut last_color = None; - try!(diff.print(args.diff_format(), |_delta, _hunk, line| { + diff.print(args.diff_format(), |_delta, _hunk, line| { if args.color() { let next = match line.origin() { '+' => Some(GREEN), @@ -190,7 +190,7 @@ fn run(args: &Args) -> Result<(), Error> { } print!("{}", str::from_utf8(line.content()).unwrap()); true - })); + })?; if args.color() { print!("{}", RESET); } @@ -200,7 +200,7 @@ fn run(args: &Args) -> Result<(), Error> { } fn print_stats(diff: &Diff, args: &Args) -> Result<(), Error> { - let stats = try!(diff.stats()); + let stats = diff.stats()?; let mut format = git2::DiffStatsFormat::NONE; if args.flag_stat { format |= git2::DiffStatsFormat::FULL; @@ -214,7 +214,7 @@ fn print_stats(diff: &Diff, args: &Args) -> Result<(), Error> { if args.flag_summary { format |= git2::DiffStatsFormat::INCLUDE_SUMMARY; } - let buf = try!(stats.to_buf(format, 80)); + let buf = stats.to_buf(format, 80)?; print!("{}", str::from_utf8(&*buf).unwrap()); Ok(()) } @@ -227,8 +227,8 @@ fn tree_to_treeish<'a>( Some(s) => s, None => return Ok(None), }; - let obj = try!(repo.revparse_single(arg)); - let tree = try!(obj.peel(ObjectType::Tree)); + let obj = repo.revparse_single(arg)?; + let tree = obj.peel(ObjectType::Tree)?; Ok(Some(tree)) } diff --git a/examples/fetch.rs b/examples/fetch.rs index a4d36e8e76..a400eeacaf 100644 --- a/examples/fetch.rs +++ b/examples/fetch.rs @@ -30,15 +30,15 @@ struct Args { } fn run(args: &Args) -> Result<(), git2::Error> { - let repo = try!(Repository::open(".")); + let repo = Repository::open(".")?; let remote = args.arg_remote.as_ref().map(|s| &s[..]).unwrap_or("origin"); // Figure out whether it's a named remote or a URL println!("Fetching {} for repo", remote); let mut cb = RemoteCallbacks::new(); - let mut remote = try!(repo + let mut remote = repo .find_remote(remote) - .or_else(|_| { repo.remote_anonymous(remote) })); + .or_else(|_| repo.remote_anonymous(remote))?; cb.sideband_progress(|data| { print!("remote: {}", str::from_utf8(data).unwrap()); io::stdout().flush().unwrap(); @@ -85,7 +85,7 @@ fn run(args: &Args) -> Result<(), git2::Error> { // progress. let mut fo = FetchOptions::new(); fo.remote_callbacks(cb); - try!(remote.download(&[], Some(&mut fo))); + remote.download(&[], Some(&mut fo))?; { // If there are local objects (we got a thin pack), then tell the user @@ -117,7 +117,7 @@ fn run(args: &Args) -> Result<(), git2::Error> { // commits. This may be needed even if there was no packfile to download, // which can happen e.g. when the branches have been changed but all the // needed objects are available locally. - try!(remote.update_tips(None, true, AutotagOption::Unspecified, None)); + remote.update_tips(None, true, AutotagOption::Unspecified, None)?; Ok(()) } diff --git a/examples/init.rs b/examples/init.rs index b547efff83..3b9371bd1d 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -41,7 +41,7 @@ fn run(args: &Args) -> Result<(), Error> { && args.flag_shared.is_none() && args.flag_separate_git_dir.is_none() { - try!(Repository::init(&path)) + Repository::init(&path)? } else { let mut opts = RepositoryInitOptions::new(); opts.bare(args.flag_bare); @@ -58,9 +58,9 @@ fn run(args: &Args) -> Result<(), Error> { } if let Some(ref s) = args.flag_shared { - opts.mode(try!(parse_shared(s))); + opts.mode(parse_shared(s)?); } - try!(Repository::init_opts(&path, &opts)) + Repository::init_opts(&path, &opts)? }; // Print a message to stdout like "git init" does @@ -74,7 +74,7 @@ fn run(args: &Args) -> Result<(), Error> { } if args.flag_initial_commit { - try!(create_initial_commit(&repo)); + create_initial_commit(&repo)?; println!("Created empty initial commit"); } @@ -85,27 +85,27 @@ fn run(args: &Args) -> Result<(), Error> { /// commit in the repository. This is the helper function that does that. fn create_initial_commit(repo: &Repository) -> Result<(), Error> { // First use the config to initialize a commit signature for the user. - let sig = try!(repo.signature()); + let sig = repo.signature()?; // Now let's create an empty tree for this commit let tree_id = { - let mut index = try!(repo.index()); + let mut index = repo.index()?; // Outside of this example, you could call index.add_path() // here to put actual files into the index. For our purposes, we'll // leave it empty for now. - try!(index.write_tree()) + index.write_tree()? }; - let tree = try!(repo.find_tree(tree_id)); + let tree = repo.find_tree(tree_id)?; // Ready to create the initial commit. // // Normally creating a commit would involve looking up the current HEAD // commit and making that be the parent of the initial commit, but here this // is the first commit so there will be no parent. - try!(repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[])); + repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[])?; Ok(()) } diff --git a/examples/ls-remote.rs b/examples/ls-remote.rs index 4d66099ba9..b5935746af 100644 --- a/examples/ls-remote.rs +++ b/examples/ls-remote.rs @@ -28,19 +28,19 @@ struct Args { } fn run(args: &Args) -> Result<(), git2::Error> { - let repo = try!(Repository::open(".")); + let repo = Repository::open(".")?; let remote = &args.arg_remote; - let mut remote = try!(repo + let mut remote = repo .find_remote(remote) - .or_else(|_| { repo.remote_anonymous(remote) })); + .or_else(|_| repo.remote_anonymous(remote))?; // Connect to the remote and call the printing function for each of the // remote references. - let connection = try!(remote.connect_auth(Direction::Fetch, None, None)); + let connection = remote.connect_auth(Direction::Fetch, None, None)?; // Get the list of references on the remote and print out their name next to // what they point to. - for head in try!(connection.list()).iter() { + for head in connection.list()?.iter() { println!("{}\t{}", head.oid(), head.name()); } Ok(()) diff --git a/examples/rev-list.rs b/examples/rev-list.rs index 84a409e200..6aedb9af73 100644 --- a/examples/rev-list.rs +++ b/examples/rev-list.rs @@ -33,8 +33,8 @@ struct Args { } fn run(args: &Args) -> Result<(), git2::Error> { - let repo = try!(Repository::open(".")); - let mut revwalk = try!(repo.revwalk()); + let repo = Repository::open(".")?; + let mut revwalk = repo.revwalk()?; let base = if args.flag_reverse { git2::Sort::REVERSE @@ -65,20 +65,20 @@ fn run(args: &Args) -> Result<(), git2::Error> { }); for (spec, hide) in specs { let id = if spec.contains("..") { - let revspec = try!(repo.revparse(spec)); + let revspec = repo.revparse(spec)?; if revspec.mode().contains(git2::RevparseMode::MERGE_BASE) { return Err(Error::from_str("merge bases not implemented")); } - try!(push(&mut revwalk, revspec.from().unwrap().id(), !hide)); + push(&mut revwalk, revspec.from().unwrap().id(), !hide)?; revspec.to().unwrap().id() } else { - try!(repo.revparse_single(spec)).id() + repo.revparse_single(spec)?.id() }; - try!(push(&mut revwalk, id, hide)); + push(&mut revwalk, id, hide)?; } for id in revwalk { - let id = try!(id); + let id = id?; println!("{}", id); } Ok(()) diff --git a/examples/rev-parse.rs b/examples/rev-parse.rs index f0642f0416..86017974cb 100644 --- a/examples/rev-parse.rs +++ b/examples/rev-parse.rs @@ -30,9 +30,9 @@ struct Args { fn run(args: &Args) -> Result<(), git2::Error> { let path = args.flag_git_dir.as_ref().map(|s| &s[..]).unwrap_or("."); - let repo = try!(Repository::open(path)); + let repo = Repository::open(path)?; - let revspec = try!(repo.revparse(&args.arg_spec)); + let revspec = repo.revparse(&args.arg_spec)?; if revspec.mode().contains(git2::RevparseMode::SINGLE) { println!("{}", revspec.from().unwrap().id()); @@ -42,7 +42,7 @@ fn run(args: &Args) -> Result<(), git2::Error> { println!("{}", to.id()); if revspec.mode().contains(git2::RevparseMode::MERGE_BASE) { - let base = try!(repo.merge_base(from.id(), to.id())); + let base = repo.merge_base(from.id(), to.id())?; println!("{}", base); } diff --git a/examples/status.rs b/examples/status.rs index f5104d6584..a15c6c93f1 100644 --- a/examples/status.rs +++ b/examples/status.rs @@ -48,7 +48,7 @@ enum Format { fn run(args: &Args) -> Result<(), Error> { let path = args.flag_git_dir.clone().unwrap_or_else(|| ".".to_string()); - let repo = try!(Repository::open(&path)); + let repo = Repository::open(&path)?; if repo.is_bare() { return Err(Error::from_str("cannot report status on bare repository")); } @@ -85,13 +85,13 @@ fn run(args: &Args) -> Result<(), Error> { println!("\u{1b}[H\u{1b}[2J"); } - let statuses = try!(repo.statuses(Some(&mut opts))); + let statuses = repo.statuses(Some(&mut opts))?; if args.flag_branch { - try!(show_branch(&repo, &args.format())); + show_branch(&repo, &args.format())?; } if args.flag_list_submodules { - try!(print_submodules(&repo)); + print_submodules(&repo)?; } if args.format() == Format::Long { @@ -130,7 +130,7 @@ fn show_branch(repo: &Repository, format: &Format) -> Result<(), Error> { } fn print_submodules(repo: &Repository) -> Result<(), Error> { - let modules = try!(repo.submodules()); + let modules = repo.submodules()?; println!("# Submodules"); for sm in &modules { println!( diff --git a/examples/tag.rs b/examples/tag.rs index c95e5a5d27..e69b925f46 100644 --- a/examples/tag.rs +++ b/examples/tag.rs @@ -36,22 +36,22 @@ struct Args { } fn run(args: &Args) -> Result<(), Error> { - let repo = try!(Repository::open(".")); + let repo = Repository::open(".")?; if let Some(ref name) = args.arg_tagname { let target = args.arg_object.as_ref().map(|s| &s[..]).unwrap_or("HEAD"); - let obj = try!(repo.revparse_single(target)); + let obj = repo.revparse_single(target)?; if let Some(ref message) = args.flag_message { - let sig = try!(repo.signature()); - try!(repo.tag(name, &obj, &sig, message, args.flag_force)); + let sig = repo.signature()?; + repo.tag(name, &obj, &sig, message, args.flag_force)?; } else { - try!(repo.tag_lightweight(name, &obj, args.flag_force)); + repo.tag_lightweight(name, &obj, args.flag_force)?; } } else if let Some(ref name) = args.flag_delete { - let obj = try!(repo.revparse_single(name)); - let id = try!(obj.short_id()); - try!(repo.tag_delete(name)); + let obj = repo.revparse_single(name)?; + let id = obj.short_id()?; + repo.tag_delete(name)?; println!( "Deleted tag '{}' (was {})", name, @@ -59,9 +59,9 @@ fn run(args: &Args) -> Result<(), Error> { ); } else if args.flag_list { let pattern = args.arg_pattern.as_ref().map(|s| &s[..]).unwrap_or("*"); - for name in try!(repo.tag_names(Some(pattern))).iter() { + for name in repo.tag_names(Some(pattern))?.iter() { let name = name.unwrap(); - let obj = try!(repo.revparse_single(name)); + let obj = repo.revparse_single(name)?; if let Some(tag) = obj.as_tag() { print_tag(tag, args); diff --git a/git2-curl/Cargo.toml b/git2-curl/Cargo.toml index 0acfb14f0a..a6954ed43e 100644 --- a/git2-curl/Cargo.toml +++ b/git2-curl/Cargo.toml @@ -11,6 +11,7 @@ Backend for an HTTP transport in libgit2 powered by libcurl. Intended to be used with the git2 crate. """ +edition = "2018" [dependencies] curl = "0.4" diff --git a/git2-curl/src/lib.rs b/git2-curl/src/lib.rs index 81cf6546a7..17ba61c01b 100644 --- a/git2-curl/src/lib.rs +++ b/git2-curl/src/lib.rs @@ -140,8 +140,7 @@ impl CurlSubtransport { // Parse our input URL to figure out the host let url = format!("{}{}", self.base_url.lock().unwrap(), self.url_path); - let parsed = - try!(Url::parse(&url).map_err(|_| { self.err("invalid url, failed to parse") })); + let parsed = Url::parse(&url).map_err(|_| self.err("invalid url, failed to parse"))?; let host = match parsed.host_str() { Some(host) => host, None => return Err(self.err("invalid url, did not have a host")), @@ -150,34 +149,34 @@ impl CurlSubtransport { // Prep the request debug!("request to {}", url); let mut h = self.handle.lock().unwrap(); - try!(h.url(&url)); - try!(h.useragent(&agent)); - try!(h.follow_location(true)); + h.url(&url)?; + h.useragent(&agent)?; + h.follow_location(true)?; match self.method { - "GET" => try!(h.get(true)), - "PUT" => try!(h.put(true)), - "POST" => try!(h.post(true)), - other => try!(h.custom_request(other)), + "GET" => h.get(true)?, + "PUT" => h.put(true)?, + "POST" => h.post(true)?, + other => h.custom_request(other)?, } let mut headers = List::new(); - try!(headers.append(&format!("Host: {}", host))); + headers.append(&format!("Host: {}", host))?; if data.len() > 0 { - try!(h.post_fields_copy(data)); - try!(headers.append(&format!( + h.post_fields_copy(data)?; + headers.append(&format!( "Accept: application/x-git-{}-result", self.service - ))); - try!(headers.append(&format!( + ))?; + headers.append(&format!( "Content-Type: \ application/x-git-{}-request", self.service - ))); + ))?; } else { - try!(headers.append("Accept: */*")); + headers.append("Accept: */*")?; } - try!(headers.append("Expect:")); - try!(h.http_headers(headers)); + headers.append("Expect:")?; + h.http_headers(headers)?; let mut content_type = None; let mut data = Vec::new(); @@ -185,7 +184,7 @@ impl CurlSubtransport { let mut h = h.transfer(); // Look for the Content-Type header - try!(h.header_function(|header| { + h.header_function(|header| { let header = match str::from_utf8(header) { Ok(s) => s, Err(..) => return true, @@ -201,19 +200,19 @@ impl CurlSubtransport { } true - })); + })?; // Collect the request's response in-memory - try!(h.write_function(|buf| { + h.write_function(|buf| { data.extend_from_slice(buf); Ok(buf.len()) - })); + })?; // Send the request - try!(h.perform()); + h.perform()?; } - let code = try!(h.response_code()); + let code = h.response_code()?; if code != 200 { return Err(self.err( &format!( @@ -275,7 +274,7 @@ impl CurlSubtransport { impl Read for CurlSubtransport { fn read(&mut self, buf: &mut [u8]) -> io::Result { if self.reader.is_none() { - try!(self.execute(&[])); + self.execute(&[])?; } self.reader.as_mut().unwrap().read(buf) } @@ -284,7 +283,7 @@ impl Read for CurlSubtransport { impl Write for CurlSubtransport { fn write(&mut self, data: &[u8]) -> io::Result { if self.reader.is_none() { - try!(self.execute(data)); + self.execute(data)?; } Ok(data.len()) } diff --git a/libgit2-sys/Cargo.toml b/libgit2-sys/Cargo.toml index d883debb31..9cc8813396 100644 --- a/libgit2-sys/Cargo.toml +++ b/libgit2-sys/Cargo.toml @@ -10,6 +10,7 @@ description = "Native bindings to the libgit2 library" exclude = [ "libgit2/tests/*", ] +edition = "2018" [lib] name = "libgit2_sys" diff --git a/src/blame.rs b/src/blame.rs index 0dcb6a2c0e..f3d055e5d9 100644 --- a/src/blame.rs +++ b/src/blame.rs @@ -1,9 +1,9 @@ +use crate::util::{self, Binding}; +use crate::{raw, signature, Oid, Repository, Signature}; use std::marker; use std::mem; use std::ops::Range; use std::path::Path; -use util::{self, Binding}; -use {raw, signature, Oid, Repository, Signature}; /// Opaque structure to hold blame results. pub struct Blame<'repo> { @@ -124,7 +124,7 @@ impl<'blame> BlameHunk<'blame> { /// Note: `None` could be returned for non-unicode paths on Widnows. pub fn path(&self) -> Option<&Path> { unsafe { - if let Some(bytes) = ::opt_bytes(self, (*self.raw).orig_path) { + if let Some(bytes) = crate::opt_bytes(self, (*self.raw).orig_path) { Some(util::bytes2path(bytes)) } else { None @@ -292,7 +292,7 @@ mod tests { #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut index = repo.index().unwrap(); let root = repo.path().parent().unwrap(); diff --git a/src/blob.rs b/src/blob.rs index ced482bb3a..cdbb6941a3 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -3,8 +3,8 @@ use std::marker; use std::mem; use std::slice; -use util::Binding; -use {raw, Error, Object, Oid}; +use crate::util::Binding; +use crate::{raw, Error, Object, Oid}; /// A structure to represent a git [blob][1] /// @@ -60,8 +60,8 @@ impl<'repo> Binding for Blob<'repo> { } } -impl<'repo> ::std::fmt::Debug for Blob<'repo> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { +impl<'repo> std::fmt::Debug for Blob<'repo> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { f.debug_struct("Blob").field("id", &self.id()).finish() } } @@ -142,11 +142,11 @@ impl<'repo> io::Write for BlobWriter<'repo> { #[cfg(test)] mod tests { + use crate::Repository; use std::fs::File; use std::io::prelude::*; use std::path::Path; use tempdir::TempDir; - use Repository; #[test] fn buffer() { diff --git a/src/branch.rs b/src/branch.rs index b25f0592d5..a82734b336 100644 --- a/src/branch.rs +++ b/src/branch.rs @@ -3,8 +3,8 @@ use std::marker; use std::ptr; use std::str; -use util::Binding; -use {raw, BranchType, Error, Reference, References}; +use crate::util::Binding; +use crate::{raw, BranchType, Error, Reference, References}; /// A structure to represent a git [branch][1] /// @@ -54,7 +54,7 @@ impl<'repo> Branch<'repo> { /// Move/rename an existing local branch reference. pub fn rename(&mut self, new_branch_name: &str, force: bool) -> Result, Error> { let mut ret = ptr::null_mut(); - let new_branch_name = try!(CString::new(new_branch_name)); + let new_branch_name = CString::new(new_branch_name)?; unsafe { try_call!(raw::git_branch_move( &mut ret, @@ -78,7 +78,7 @@ impl<'repo> Branch<'repo> { let mut ret = ptr::null(); unsafe { try_call!(raw::git_branch_name(&mut ret, &*self.get().raw())); - Ok(::opt_bytes(self, ret).unwrap()) + Ok(crate::opt_bytes(self, ret).unwrap()) } } @@ -97,7 +97,7 @@ impl<'repo> Branch<'repo> { /// If `None` is specified, then the upstream branch is unset. The name /// 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 = try!(::opt_cstr(upstream_name)); + let upstream_name = crate::opt_cstr(upstream_name)?; unsafe { try_call!(raw::git_branch_set_upstream( self.get().raw(), @@ -146,11 +146,11 @@ impl<'repo> Drop for Branches<'repo> { #[cfg(test)] mod tests { - use BranchType; + use crate::BranchType; #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let head = repo.head().unwrap(); let target = head.target().unwrap(); let commit = repo.find_commit(target).unwrap(); diff --git a/src/buf.rs b/src/buf.rs index 0e8f3dbc69..0ab560ce80 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -3,8 +3,8 @@ use std::ptr; use std::slice; use std::str; -use raw; -use util::Binding; +use crate::raw; +use crate::util::Binding; /// A structure to wrap an intermediate buffer used by libgit2. /// @@ -23,7 +23,7 @@ impl Default for Buf { impl Buf { /// Creates a new empty buffer. pub fn new() -> Buf { - ::init(); + crate::init(); unsafe { Binding::from_raw(&mut raw::git_buf { ptr: ptr::null_mut(), diff --git a/src/build.rs b/src/build.rs index bd2b0c87ed..abec5295a1 100644 --- a/src/build.rs +++ b/src/build.rs @@ -6,9 +6,9 @@ use std::mem; use std::path::Path; use std::ptr; -use util::{self, Binding}; -use {panic, raw, Error, FetchOptions, IntoCString, Repository}; -use {CheckoutNotificationType, DiffFile, Remote}; +use crate::util::{self, Binding}; +use crate::{panic, raw, Error, FetchOptions, IntoCString, Repository}; +use crate::{CheckoutNotificationType, DiffFile, Remote}; /// A builder struct which is used to build configuration for cloning a new git /// repository. @@ -102,7 +102,7 @@ impl<'cb> RepoBuilder<'cb> { /// When ready, the `clone()` method can be used to clone a new repository /// using this configuration. pub fn new() -> RepoBuilder<'cb> { - ::init(); + crate::init(); RepoBuilder { bare: false, branch: None, @@ -231,8 +231,8 @@ impl<'cb> RepoBuilder<'cb> { opts.remote_cb_payload = callback as *mut _ as *mut _; } - let url = try!(CString::new(url)); - let into = try!(into.into_c_string()); + let url = CString::new(url)?; + let into = into.into_c_string()?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_clone(&mut raw, url, into, &opts)); @@ -256,7 +256,7 @@ extern "C" fn remote_create_cb( let f = payload as *mut Box; match (*f)(&repo, name, url) { Ok(remote) => { - *out = ::remote::remote_into_raw(remote); + *out = crate::remote::remote_into_raw(remote); 0 } Err(e) => e.raw_code(), @@ -277,7 +277,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// Creates a new builder for checkouts with all of its default /// configuration. pub fn new() -> CheckoutBuilder<'cb> { - ::init(); + crate::init(); CheckoutBuilder { disable_filters: false, dir_perm: None, @@ -642,10 +642,10 @@ extern "C" fn notify_cb( #[cfg(test)] mod tests { use super::{CheckoutBuilder, RepoBuilder}; + use crate::{CheckoutNotificationType, Repository}; use std::fs; use std::path::Path; use tempdir::TempDir; - use {CheckoutNotificationType, Repository}; #[test] fn smoke() { diff --git a/src/call.rs b/src/call.rs index 565f08d96f..1509517c0c 100644 --- a/src/call.rs +++ b/src/call.rs @@ -1,19 +1,19 @@ #![macro_use] use libc; -use Error; +use crate::Error; macro_rules! call { (raw::$p:ident ($($e:expr),*)) => ( - raw::$p($(::call::convert(&$e)),*) + raw::$p($(crate::call::convert(&$e)),*) ) } macro_rules! try_call { (raw::$p:ident ($($e:expr),*)) => ({ - match ::call::try(raw::$p($(::call::convert(&$e)),*)) { + match crate::call::c_try(raw::$p($(crate::call::convert(&$e)),*)) { Ok(o) => o, - Err(e) => { ::panic::check(); return Err(e) } + Err(e) => { crate::panic::check(); return Err(e) } } }) } @@ -23,7 +23,7 @@ macro_rules! try_call_iter { match call!($($f)*) { 0 => {} raw::GIT_ITEROVER => return None, - e => return Some(Err(::call::last_error(e))) + e => return Some(Err(crate::call::last_error(e))) } } } @@ -37,7 +37,7 @@ pub fn convert>(u: &U) -> T { u.convert() } -pub fn try(ret: libc::c_int) -> Result { +pub fn c_try(ret: libc::c_int) -> Result { match ret { n if n < 0 => Err(last_error(n)), n => Ok(n), @@ -56,9 +56,9 @@ mod impls { use libc; - use call::Convert; - use {raw, BranchType, ConfigLevel, Direction, ObjectType, ResetType}; - use {AutotagOption, DiffFormat, FetchPrune, FileFavor, SubmoduleIgnore}; + use crate::call::Convert; + use crate::{raw, BranchType, ConfigLevel, Direction, ObjectType, ResetType}; + use crate::{AutotagOption, DiffFormat, FetchPrune, FileFavor, SubmoduleIgnore}; impl Convert for T { fn convert(&self) -> T { diff --git a/src/cert.rs b/src/cert.rs index 4ca84e58aa..80c4ed345a 100644 --- a/src/cert.rs +++ b/src/cert.rs @@ -5,8 +5,8 @@ use std::marker; use std::mem; use std::slice; -use raw; -use util::Binding; +use crate::raw; +use crate::util::Binding; /// A certificate for a remote connection, viewable as one of `CertHostkey` or /// `CertX509` currently. diff --git a/src/commit.rs b/src/commit.rs index d478178790..636d1adede 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -5,8 +5,8 @@ use std::ops::Range; use std::ptr; use std::str; -use util::Binding; -use {raw, signature, Error, Object, Oid, Signature, Time, Tree}; +use crate::util::Binding; +use crate::{raw, signature, Error, Object, Oid, Signature, Time, Tree}; /// A structure to represent a git [commit][1] /// @@ -74,7 +74,7 @@ impl<'repo> Commit<'repo> { /// The returned message will be slightly prettified by removing any /// potential leading newlines. pub fn message_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_commit_message(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_commit_message(&*self.raw)).unwrap() } } /// Get the encoding for the message of a commit, as a string representing a @@ -82,7 +82,7 @@ impl<'repo> Commit<'repo> { /// /// `None` will be returned if the encoding is not known pub fn message_encoding(&self) -> Option<&str> { - let bytes = unsafe { ::opt_bytes(self, raw::git_commit_message_encoding(&*self.raw)) }; + let bytes = unsafe { crate::opt_bytes(self, raw::git_commit_message_encoding(&*self.raw)) }; bytes.and_then(|b| str::from_utf8(b).ok()) } @@ -95,7 +95,7 @@ impl<'repo> Commit<'repo> { /// Get the full raw message of a commit. pub fn message_raw_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_commit_message_raw(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_commit_message_raw(&*self.raw)).unwrap() } } /// Get the full raw text of the commit header. @@ -107,7 +107,7 @@ impl<'repo> Commit<'repo> { /// Get the full raw text of the commit header. pub fn raw_header_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_commit_raw_header(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_commit_raw_header(&*self.raw)).unwrap() } } /// Get the short "summary" of the git commit message. @@ -128,7 +128,7 @@ impl<'repo> Commit<'repo> { /// /// `None` may be returned if an error occurs pub fn summary_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_commit_summary(self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_commit_summary(self.raw)) } } /// Get the commit time (i.e. committer time) of a commit. @@ -198,9 +198,9 @@ impl<'repo> Commit<'repo> { let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; - let update_ref = try!(::opt_cstr(update_ref)); - let encoding = try!(::opt_cstr(message_encoding)); - let message = try!(::opt_cstr(message)); + let update_ref = crate::opt_cstr(update_ref)?; + let encoding = crate::opt_cstr(message_encoding)?; + let message = crate::opt_cstr(message)?; unsafe { try_call!(raw::git_commit_amend( &mut raw, @@ -280,8 +280,8 @@ impl<'repo> Binding for Commit<'repo> { } } -impl<'repo> ::std::fmt::Debug for Commit<'repo> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { +impl<'repo> std::fmt::Debug for Commit<'repo> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { let mut ds = f.debug_struct("Commit"); ds.field("id", &self.id()); if let Some(summary) = self.summary() { @@ -353,7 +353,7 @@ impl<'repo> Drop for Commit<'repo> { mod tests { #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let head = repo.head().unwrap(); let target = head.target().unwrap(); let commit = repo.find_commit(target).unwrap(); diff --git a/src/config.rs b/src/config.rs index b5fc72d2e6..6eb689cbb4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,8 +5,8 @@ use std::path::{Path, PathBuf}; use std::ptr; use std::str; -use util::{self, Binding}; -use {raw, Buf, ConfigLevel, Error, IntoCString}; +use crate::util::{self, Binding}; +use crate::{raw, Buf, ConfigLevel, Error, IntoCString}; /// A structure representing a git configuration key/value store pub struct Config { @@ -34,7 +34,7 @@ impl Config { /// This object is empty, so you have to add a file to it before you can do /// anything with it. pub fn new() -> Result { - ::init(); + crate::init(); let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_config_new(&mut raw)); @@ -44,9 +44,9 @@ impl Config { /// Create a new config instance containing a single on-disk file pub fn open(path: &Path) -> Result { - ::init(); + crate::init(); let mut raw = ptr::null_mut(); - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; unsafe { try_call!(raw::git_config_open_ondisk(&mut raw, path)); Ok(Binding::from_raw(raw)) @@ -59,7 +59,7 @@ impl Config { /// files and opens them into a single prioritized config object that can /// be used when accessing default config data outside a repository. pub fn open_default() -> Result { - ::init(); + crate::init(); let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_config_open_default(&mut raw)); @@ -79,7 +79,7 @@ impl Config { /// This method will not guess the path to the xdg compatible config file /// (`.config/git/config`). pub fn find_global() -> Result { - ::init(); + crate::init(); let buf = Buf::new(); unsafe { try_call!(raw::git_config_find_global(buf.raw())); @@ -91,7 +91,7 @@ impl Config { /// /// If /etc/gitconfig doesn't exist, it will look for %PROGRAMFILES% pub fn find_system() -> Result { - ::init(); + crate::init(); let buf = Buf::new(); unsafe { try_call!(raw::git_config_find_system(buf.raw())); @@ -104,7 +104,7 @@ impl Config { /// The xdg compatible configuration file is usually located in /// `$HOME/.config/git/config`. pub fn find_xdg() -> Result { - ::init(); + crate::init(); let buf = Buf::new(); unsafe { try_call!(raw::git_config_find_xdg(buf.raw())); @@ -122,7 +122,7 @@ impl Config { /// file instances in order (instances with a higher priority level will be /// accessed first). pub fn add_file(&mut self, path: &Path, level: ConfigLevel, force: bool) -> Result<(), Error> { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; unsafe { try_call!(raw::git_config_add_file_ondisk( self.raw, @@ -138,7 +138,7 @@ impl Config { /// Delete a config variable from the config file with the highest level /// (usually the local one). pub fn remove(&mut self, name: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_delete_entry(self.raw, name)); Ok(()) @@ -148,8 +148,8 @@ impl Config { /// Remove multivar config variables in the config file with the highest level (usually the /// local one). pub fn remove_multivar(&mut self, name: &str, regexp: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); - let regexp = try!(CString::new(regexp)); + let name = CString::new(name)?; + let regexp = CString::new(regexp)?; unsafe { try_call!(raw::git_config_delete_multivar(self.raw, name, regexp)); } @@ -163,7 +163,7 @@ impl Config { /// the variable will be returned here. pub fn get_bool(&self, name: &str) -> Result { let mut out = 0 as libc::c_int; - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_get_bool(&mut out, &*self.raw, name)); } @@ -177,7 +177,7 @@ impl Config { /// the variable will be returned here. pub fn get_i32(&self, name: &str) -> Result { let mut out = 0i32; - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_get_int32(&mut out, &*self.raw, name)); } @@ -191,7 +191,7 @@ impl Config { /// the variable will be returned here. pub fn get_i64(&self, name: &str) -> Result { let mut out = 0i64; - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_get_int64(&mut out, &*self.raw, name)); } @@ -203,7 +203,7 @@ impl Config { /// This is the same as `get_bytes` except that it may return `Err` if /// the bytes are not valid utf-8. pub fn get_str(&self, name: &str) -> Result<&str, Error> { - str::from_utf8(try!(self.get_bytes(name))) + str::from_utf8(self.get_bytes(name)?) .map_err(|_| Error::from_str("configuration value is not valid utf8")) } @@ -212,10 +212,10 @@ impl Config { /// This method will return an error if this `Config` is not a snapshot. pub fn get_bytes(&self, name: &str) -> Result<&[u8], Error> { let mut ret = ptr::null(); - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_get_string(&mut ret, &*self.raw, name)); - Ok(::opt_bytes(self, ret).unwrap()) + Ok(crate::opt_bytes(self, ret).unwrap()) } } @@ -224,7 +224,7 @@ impl Config { /// An error will be returned if the config value is not valid utf-8. pub fn get_string(&self, name: &str) -> Result { let ret = Buf::new(); - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_get_string_buf(ret.raw(), self.raw, name)); } @@ -236,17 +236,17 @@ impl Config { /// Get the value of a path config variable as an owned . pub fn get_path(&self, name: &str) -> Result { let ret = Buf::new(); - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_get_path(ret.raw(), self.raw, name)); } - Ok(::util::bytes2path(&ret).to_path_buf()) + Ok(crate::util::bytes2path(&ret).to_path_buf()) } /// Get the ConfigEntry for a config variable. pub fn get_entry(&self, name: &str) -> Result { let mut ret = ptr::null_mut(); - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_get_entry(&mut ret, self.raw, name)); Ok(Binding::from_raw(ret)) @@ -276,7 +276,7 @@ impl Config { unsafe { match glob { Some(s) => { - let s = try!(CString::new(s)); + let s = CString::new(s)?; try_call!(raw::git_config_iterator_glob_new(&mut ret, &*self.raw, s)); } None => { @@ -316,7 +316,7 @@ impl Config { /// 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> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_set_bool(self.raw, name, value)); } @@ -326,7 +326,7 @@ impl Config { /// Set the value of an integer config variable in the config file with the /// highest level (usually the local one). pub fn set_i32(&mut self, name: &str, value: i32) -> Result<(), Error> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_set_int32(self.raw, name, value)); } @@ -336,7 +336,7 @@ impl Config { /// Set the value of an integer config variable in the config file with the /// highest level (usually the local one). pub fn set_i64(&mut self, name: &str, value: i64) -> Result<(), Error> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_config_set_int64(self.raw, name, value)); } @@ -346,9 +346,9 @@ impl Config { /// Set the value of an multivar config variable in the config file with the /// highest level (usually the local one). pub fn set_multivar(&mut self, name: &str, regexp: &str, value: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); - let regexp = try!(CString::new(regexp)); - let value = try!(CString::new(value)); + let name = CString::new(name)?; + let regexp = CString::new(regexp)?; + let value = CString::new(value)?; unsafe { try_call!(raw::git_config_set_multivar(self.raw, name, regexp, value)); } @@ -358,8 +358,8 @@ impl Config { /// Set the value of a string config variable in the config file with the /// highest level (usually the local one). pub fn set_str(&mut self, name: &str, value: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); - let value = try!(CString::new(value)); + let name = CString::new(name)?; + let value = CString::new(value)?; unsafe { try_call!(raw::git_config_set_string(self.raw, name, value)); } @@ -383,9 +383,9 @@ impl Config { /// Interprets "true", "yes", "on", 1, or any non-zero number as true. /// Interprets "false", "no", "off", 0, or an empty string as false. pub fn parse_bool(s: S) -> Result { - let s = try!(s.into_c_string()); + let s = s.into_c_string()?; let mut out = 0; - ::init(); + crate::init(); unsafe { try_call!(raw::git_config_parse_bool(&mut out, s)); } @@ -395,9 +395,9 @@ impl Config { /// Parse a string as an i32; handles suffixes like k, M, or G, and /// multiplies by the appropriate power of 1024. pub fn parse_i32(s: S) -> Result { - let s = try!(s.into_c_string()); + let s = s.into_c_string()?; let mut out = 0; - ::init(); + crate::init(); unsafe { try_call!(raw::git_config_parse_int32(&mut out, s)); } @@ -407,9 +407,9 @@ impl Config { /// Parse a string as an i64; handles suffixes like k, M, or G, and /// multiplies by the appropriate power of 1024. pub fn parse_i64(s: S) -> Result { - let s = try!(s.into_c_string()); + let s = s.into_c_string()?; let mut out = 0; - ::init(); + crate::init(); unsafe { try_call!(raw::git_config_parse_int64(&mut out, s)); } @@ -443,7 +443,7 @@ impl<'cfg> ConfigEntry<'cfg> { /// Gets the name of this entry as a byte slice. pub fn name_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, (*self.raw).name).unwrap() } + unsafe { crate::opt_bytes(self, (*self.raw).name).unwrap() } } /// Gets the value of this entry. @@ -455,7 +455,7 @@ impl<'cfg> ConfigEntry<'cfg> { /// Gets the value of this entry as a byte slice. pub fn value_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, (*self.raw).value).unwrap() } + unsafe { crate::opt_bytes(self, (*self.raw).value).unwrap() } } /// Gets the configuration level of this entry. @@ -537,7 +537,7 @@ mod tests { use std::fs::File; use tempdir::TempDir; - use Config; + use crate::Config; #[test] fn smoke() { diff --git a/src/cred.rs b/src/cred.rs index 580b4c0dcc..9717f5e686 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -6,8 +6,8 @@ use std::process::{Command, Stdio}; use std::ptr; use url; -use util::Binding; -use {raw, Config, Error, IntoCString}; +use crate::util::Binding; +use crate::{raw, Config, Error, IntoCString}; /// A structure to represent git credentials in libgit2. pub struct Cred { @@ -29,7 +29,7 @@ impl Cred { /// Create a "default" credential usable for Negotiate mechanisms like NTLM /// or Kerberos authentication. pub fn default() -> Result { - ::init(); + crate::init(); let mut out = ptr::null_mut(); unsafe { try_call!(raw::git_cred_default_new(&mut out)); @@ -41,9 +41,9 @@ impl Cred { /// /// The username specified is the username to authenticate. pub fn ssh_key_from_agent(username: &str) -> Result { - ::init(); + crate::init(); let mut out = ptr::null_mut(); - let username = try!(CString::new(username)); + let username = CString::new(username)?; unsafe { try_call!(raw::git_cred_ssh_key_from_agent(&mut out, username)); Ok(Binding::from_raw(out)) @@ -57,11 +57,11 @@ impl Cred { privatekey: &Path, passphrase: Option<&str>, ) -> Result { - ::init(); - let username = try!(CString::new(username)); - let publickey = try!(::opt_cstr(publickey)); - let privatekey = try!(privatekey.into_c_string()); - let passphrase = try!(::opt_cstr(passphrase)); + crate::init(); + let username = CString::new(username)?; + let publickey = crate::opt_cstr(publickey)?; + let privatekey = privatekey.into_c_string()?; + let passphrase = crate::opt_cstr(passphrase)?; let mut out = ptr::null_mut(); unsafe { try_call!(raw::git_cred_ssh_key_new( @@ -78,11 +78,11 @@ impl Cred { privatekey: &str, passphrase: Option<&str>, ) -> Result { - ::init(); - let username = try!(CString::new(username)); - let publickey = try!(::opt_cstr(publickey)); - let privatekey = try!(CString::new(privatekey)); - let passphrase = try!(::opt_cstr(passphrase)); + crate::init(); + let username = CString::new(username)?; + let publickey = crate::opt_cstr(publickey)?; + let privatekey = CString::new(privatekey)?; + let passphrase = crate::opt_cstr(passphrase)?; let mut out = ptr::null_mut(); unsafe { try_call!(raw::git_cred_ssh_key_memory_new( @@ -94,9 +94,9 @@ impl Cred { /// Create a new plain-text username and password credential object. pub fn userpass_plaintext(username: &str, password: &str) -> Result { - ::init(); - let username = try!(CString::new(username)); - let password = try!(CString::new(password)); + crate::init(); + let username = CString::new(username)?; + let password = CString::new(password)?; let mut out = ptr::null_mut(); unsafe { try_call!(raw::git_cred_userpass_plaintext_new( @@ -139,8 +139,8 @@ impl Cred { /// THis is used with ssh authentication to query for the username if non is /// specified in the url. pub fn username(username: &str) -> Result { - ::init(); - let username = try!(CString::new(username)); + crate::init(); + let username = CString::new(username)?; let mut out = ptr::null_mut(); unsafe { try_call!(raw::git_cred_username_new(&mut out, username)); @@ -437,7 +437,7 @@ mod test { use std::path::Path; use tempdir::TempDir; - use {Config, ConfigLevel, Cred, CredentialHelper}; + use crate::{Config, ConfigLevel, Cred, CredentialHelper}; macro_rules! test_cfg( ($($k:expr => $v:expr),*) => ({ let td = TempDir::new("git2-rs").unwrap(); diff --git a/src/describe.rs b/src/describe.rs index 5e8d1e9391..efa66e826d 100644 --- a/src/describe.rs +++ b/src/describe.rs @@ -5,8 +5,8 @@ use std::ptr; use libc::{c_int, c_uint}; -use util::Binding; -use {raw, Buf, Error, Repository}; +use crate::util::Binding; +use crate::{raw, Buf, Error, Repository}; /// The result of a `describe` operation on either an `Describe` or a /// `Repository`. @@ -178,11 +178,11 @@ impl Binding for DescribeOptions { #[cfg(test)] mod tests { - use DescribeOptions; + use crate::DescribeOptions; #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let head = t!(repo.head()).target().unwrap(); let d = t!(repo.describe(DescribeOptions::new().show_commit_oid_as_fallback(true))); diff --git a/src/diff.rs b/src/diff.rs index 74f81b774d..ad8ee0d9f0 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -7,9 +7,9 @@ use std::path::Path; use std::ptr; use std::slice; -use util::{self, Binding}; -use {panic, raw, Buf, Delta, DiffFormat, Error, Oid, Repository}; -use {DiffStatsFormat, IntoCString}; +use crate::util::{self, Binding}; +use crate::{panic, raw, Buf, Delta, DiffFormat, Error, Oid, Repository}; +use crate::{DiffStatsFormat, IntoCString}; /// The diff object that contains all individual file deltas. /// @@ -457,7 +457,7 @@ impl<'a> DiffFile<'a> { /// directory of the repository. pub fn path_bytes(&self) -> Option<&'a [u8]> { static FOO: () = (); - unsafe { ::opt_bytes(&FOO, (*self.raw).path) } + unsafe { crate::opt_bytes(&FOO, (*self.raw).path) } } /// Returns the path of the entry relative to the working directory of the @@ -1213,15 +1213,15 @@ impl DiffFindOptions { #[cfg(test)] mod tests { + use crate::DiffOptions; use std::borrow::Borrow; use std::fs::File; use std::io::Write; use std::path::Path; - use DiffOptions; #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let diff = repo.diff_tree_to_workdir(None, None).unwrap(); assert_eq!(diff.deltas().len(), 0); let stats = diff.stats().unwrap(); @@ -1232,7 +1232,7 @@ mod tests { #[test] fn foreach_smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let diff = t!(repo.diff_tree_to_workdir(None, None)); let mut count = 0; t!(diff.foreach( @@ -1250,7 +1250,7 @@ mod tests { #[test] fn foreach_file_only() { let path = Path::new("foo"); - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); t!(t!(File::create(&td.path().join(path))).write_all(b"bar")); let mut opts = DiffOptions::new(); opts.include_untracked(true); @@ -1274,7 +1274,7 @@ mod tests { #[test] fn foreach_file_and_hunk() { let path = Path::new("foo"); - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); t!(t!(File::create(&td.path().join(path))).write_all(b"bar")); let mut index = t!(repo.index()); t!(index.add_path(path)); @@ -1302,7 +1302,7 @@ mod tests { let deflated_fib = vec![120, 156, 99, 96, 100, 100, 98, 102, 229, 0, 0, 0, 53, 0, 21]; let foo_path = Path::new("foo"); let bin_path = Path::new("bin"); - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); t!(t!(File::create(&td.path().join(foo_path))).write_all(b"bar\n")); t!(t!(File::create(&td.path().join(bin_path))).write_all(&fib)); let mut index = t!(repo.index()); diff --git a/src/error.rs b/src/error.rs index 23b601377e..cb55e8aa7c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,7 +5,7 @@ use std::ffi::{CStr, NulError}; use std::fmt; use std::str; -use {raw, ErrorClass, ErrorCode}; +use crate::{raw, ErrorClass, ErrorCode}; /// A structure to represent errors coming out of libgit2. #[derive(Debug, PartialEq)] @@ -26,7 +26,7 @@ impl Error { /// safe to unwrap the return value. This API will change in the next major /// version. pub fn last_error(code: c_int) -> Option { - ::init(); + crate::init(); unsafe { // Note that whenever libgit2 returns an error any negative value // indicates that an error happened. Auxiliary information is @@ -280,11 +280,11 @@ impl From for Error { #[cfg(test)] mod tests { - use {ErrorClass, ErrorCode}; + use crate::{ErrorClass, ErrorCode}; #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let err = repo.find_submodule("does_not_exist").err().unwrap(); assert_eq!(err.code(), ErrorCode::NotFound); diff --git a/src/index.rs b/src/index.rs index 9d5f14054b..9ff379e0f7 100644 --- a/src/index.rs +++ b/src/index.rs @@ -7,9 +7,9 @@ use std::slice; use libc::{c_char, c_int, c_uint, c_void, size_t}; -use util::{self, Binding}; -use IntoCString; -use {panic, raw, Error, IndexAddOption, IndexTime, Oid, Repository, Tree}; +use crate::util::{self, Binding}; +use crate::IntoCString; +use crate::{panic, raw, Error, IndexAddOption, IndexTime, Oid, Repository, Tree}; /// A structure to represent a git [index][1] /// @@ -75,7 +75,7 @@ impl Index { /// This index object cannot be read/written to the filesystem, but may be /// used to perform in-memory index operations. pub fn new() -> Result { - ::init(); + crate::init(); let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_index_new(&mut raw)); @@ -92,9 +92,9 @@ impl Index { /// If you need an index attached to a repository, use the `index()` method /// on `Repository`. pub fn open(index_path: &Path) -> Result { - ::init(); + crate::init(); let mut raw = ptr::null_mut(); - let index_path = try!(index_path.into_c_string()); + let index_path = index_path.into_c_string()?; unsafe { try_call!(raw::git_index_open(&mut raw, index_path)); Ok(Binding::from_raw(raw)) @@ -107,7 +107,7 @@ impl Index { /// given 'source_entry', it will be replaced. Otherwise, the 'source_entry' /// will be added. pub fn add(&mut self, entry: &IndexEntry) -> Result<(), Error> { - let path = try!(CString::new(&entry.path[..])); + let path = CString::new(&entry.path[..])?; // libgit2 encodes the length of the path in the lower bits of the // `flags` entry, so mask those out and recalculate here to ensure we @@ -164,7 +164,7 @@ impl Index { /// no longer be marked as conflicting. The data about the conflict will be /// moved to the "resolve undo" (REUC) section. pub fn add_frombuffer(&mut self, entry: &IndexEntry, data: &[u8]) -> Result<(), Error> { - let path = try!(CString::new(&entry.path[..])); + let path = CString::new(&entry.path[..])?; // libgit2 encodes the length of the path in the lower bits of the // `flags` entry, so mask those out and recalculate here to ensure we @@ -228,7 +228,7 @@ impl Index { } posix_path.push(comp.as_os_str()); } - let posix_path = try!(posix_path.into_c_string()); + let posix_path = posix_path.into_c_string()?; unsafe { try_call!(raw::git_index_add_bypath(self.raw, posix_path)); Ok(()) @@ -278,7 +278,7 @@ impl Index { T: IntoCString, I: IntoIterator, { - let (_a, _b, raw_strarray) = try!(::util::iter2cstrs(pathspecs)); + let (_a, _b, raw_strarray) = crate::util::iter2cstrs(pathspecs)?; let ptr = cb.as_mut(); let callback = ptr .as_ref() @@ -338,7 +338,7 @@ impl Index { /// Get an iterator over the index entries that have conflicts pub fn conflicts(&self) -> Result { - ::init(); + crate::init(); let mut conflict_iter = ptr::null_mut(); unsafe { try_call!(raw::git_index_conflict_iterator_new( @@ -373,7 +373,7 @@ impl Index { /// /// Returns `None` if this is an in-memory index. pub fn path(&self) -> Option<&Path> { - unsafe { ::opt_bytes(self, raw::git_index_path(&*self.raw)).map(util::bytes2path) } + unsafe { crate::opt_bytes(self, raw::git_index_path(&*self.raw)).map(util::bytes2path) } } /// Update the contents of an existing index object in memory by reading @@ -406,7 +406,7 @@ impl Index { /// Remove an entry from the index pub fn remove(&mut self, path: &Path, stage: i32) -> Result<(), Error> { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; unsafe { try_call!(raw::git_index_remove(self.raw, path, stage as c_int)); } @@ -422,7 +422,7 @@ impl Index { /// no longer be marked as conflicting. The data about the conflict will be /// moved to the "resolve undo" (REUC) section. pub fn remove_path(&mut self, path: &Path) -> Result<(), Error> { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; unsafe { try_call!(raw::git_index_remove_bypath(self.raw, path)); } @@ -431,7 +431,7 @@ impl Index { /// Remove all entries from the index under a given directory. pub fn remove_dir(&mut self, path: &Path, stage: i32) -> Result<(), Error> { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; unsafe { try_call!(raw::git_index_remove_directory( self.raw, @@ -456,7 +456,7 @@ impl Index { T: IntoCString, I: IntoIterator, { - let (_a, _b, raw_strarray) = try!(::util::iter2cstrs(pathspecs)); + let (_a, _b, raw_strarray) = crate::util::iter2cstrs(pathspecs)?; let ptr = cb.as_mut(); let callback = ptr .as_ref() @@ -494,7 +494,7 @@ impl Index { T: IntoCString, I: IntoIterator, { - let (_a, _b, raw_strarray) = try!(::util::iter2cstrs(pathspecs)); + let (_a, _b, raw_strarray) = crate::util::iter2cstrs(pathspecs)?; let ptr = cb.as_mut(); let callback = ptr .as_ref() @@ -703,7 +703,7 @@ mod tests { use std::path::Path; use tempdir::TempDir; - use {Index, IndexEntry, IndexTime, Oid, Repository, ResetType}; + use crate::{Index, IndexEntry, IndexTime, Oid, Repository, ResetType}; #[test] fn smoke() { @@ -718,7 +718,7 @@ mod tests { #[test] fn smoke_from_repo() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut index = repo.index().unwrap(); assert_eq!( index.path().map(|s| s.to_path_buf()), @@ -735,7 +735,7 @@ mod tests { #[test] fn add_all() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut index = repo.index().unwrap(); let root = repo.path().parent().unwrap(); @@ -745,7 +745,7 @@ mod tests { index .add_all( ["foo"].iter(), - ::IndexAddOption::DEFAULT, + crate::IndexAddOption::DEFAULT, Some(&mut |a: &Path, b: &[u8]| { assert!(!called); called = true; @@ -775,7 +775,7 @@ mod tests { #[test] fn smoke_add() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut index = repo.index().unwrap(); let root = repo.path().parent().unwrap(); @@ -798,7 +798,7 @@ mod tests { repo.reset(&obj, ResetType::Hard, None).unwrap(); let td2 = TempDir::new("git").unwrap(); - let url = ::test::path2url(&root); + let url = crate::test::path2url(&root); let repo = Repository::clone(&url, td2.path()).unwrap(); let obj = repo.find_object(commit, None).unwrap(); repo.reset(&obj, ResetType::Hard, None).unwrap(); @@ -819,7 +819,7 @@ mod tests { #[test] fn add_frombuffer_then_read() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut index = repo.index().unwrap(); let mut e = entry(); diff --git a/src/lib.rs b/src/lib.rs index 917c9fe14d..3476921f0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,49 +83,53 @@ use std::fmt; use std::str; use std::sync::{Once, ONCE_INIT}; -pub use blame::{Blame, BlameHunk, BlameIter, BlameOptions}; -pub use blob::{Blob, BlobWriter}; -pub use branch::{Branch, Branches}; -pub use buf::Buf; -pub use commit::{Commit, Parents}; -pub use config::{Config, ConfigEntries, ConfigEntry}; -pub use cred::{Cred, CredentialHelper}; -pub use describe::{Describe, DescribeFormatOptions, DescribeOptions}; -pub use diff::{Deltas, Diff, DiffDelta, DiffFile, DiffOptions}; -pub use diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind}; -pub use diff::{DiffFindOptions, DiffHunk, DiffLine, DiffStats}; -pub use error::Error; -pub use index::{Index, IndexConflict, IndexConflicts, IndexEntries, IndexEntry, IndexMatchedPath}; -pub use merge::{AnnotatedCommit, MergeOptions}; -pub use message::{message_prettify, DEFAULT_COMMENT_CHAR}; -pub use note::{Note, Notes}; -pub use object::Object; -pub use odb::{Odb, OdbObject, OdbReader, OdbWriter}; -pub use oid::Oid; -pub use packbuilder::{PackBuilder, PackBuilderStage}; -pub use patch::Patch; -pub use pathspec::{Pathspec, PathspecFailedEntries, PathspecMatchList}; -pub use pathspec::{PathspecDiffEntries, PathspecEntries}; -pub use proxy_options::ProxyOptions; -pub use rebase::{Rebase, RebaseOperation, RebaseOperationType, RebaseOptions}; -pub use reference::{Reference, ReferenceNames, References}; -pub use reflog::{Reflog, ReflogEntry, ReflogIter}; -pub use refspec::Refspec; -pub use remote::{FetchOptions, PushOptions, Refspecs, Remote, RemoteConnection, RemoteHead}; -pub use remote_callbacks::{Credentials, RemoteCallbacks, TransferProgress}; -pub use remote_callbacks::{Progress, TransportMessage, UpdateTips}; -pub use repo::{Repository, RepositoryInitOptions}; -pub use revspec::Revspec; -pub use revwalk::Revwalk; -pub use signature::Signature; -pub use stash::{StashApplyOptions, StashApplyProgressCb, StashCb}; -pub use status::{StatusEntry, StatusIter, StatusOptions, StatusShow, Statuses}; -pub use submodule::{Submodule, SubmoduleUpdateOptions}; -pub use tag::Tag; -pub use time::{IndexTime, Time}; -pub use tree::{Tree, TreeEntry, TreeIter, TreeWalkMode, TreeWalkResult}; -pub use treebuilder::TreeBuilder; -pub use util::IntoCString; +pub use crate::blame::{Blame, BlameHunk, BlameIter, BlameOptions}; +pub use crate::blob::{Blob, BlobWriter}; +pub use crate::branch::{Branch, Branches}; +pub use crate::buf::Buf; +pub use crate::commit::{Commit, Parents}; +pub use crate::config::{Config, ConfigEntries, ConfigEntry}; +pub use crate::cred::{Cred, CredentialHelper}; +pub use crate::describe::{Describe, DescribeFormatOptions, DescribeOptions}; +pub use crate::diff::{Deltas, Diff, DiffDelta, DiffFile, DiffOptions}; +pub use crate::diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind}; +pub use crate::diff::{DiffFindOptions, DiffHunk, DiffLine, DiffStats}; +pub use crate::error::Error; +pub use crate::index::{ + Index, IndexConflict, IndexConflicts, IndexEntries, IndexEntry, IndexMatchedPath, +}; +pub use crate::merge::{AnnotatedCommit, MergeOptions}; +pub use crate::message::{message_prettify, DEFAULT_COMMENT_CHAR}; +pub use crate::note::{Note, Notes}; +pub use crate::object::Object; +pub use crate::odb::{Odb, OdbObject, OdbReader, OdbWriter}; +pub use crate::oid::Oid; +pub use crate::packbuilder::{PackBuilder, PackBuilderStage}; +pub use crate::patch::Patch; +pub use crate::pathspec::{Pathspec, PathspecFailedEntries, PathspecMatchList}; +pub use crate::pathspec::{PathspecDiffEntries, PathspecEntries}; +pub use crate::proxy_options::ProxyOptions; +pub use crate::rebase::{Rebase, RebaseOperation, RebaseOperationType, RebaseOptions}; +pub use crate::reference::{Reference, ReferenceNames, References}; +pub use crate::reflog::{Reflog, ReflogEntry, ReflogIter}; +pub use crate::refspec::Refspec; +pub use crate::remote::{ + FetchOptions, PushOptions, Refspecs, Remote, RemoteConnection, RemoteHead, +}; +pub use crate::remote_callbacks::{Credentials, RemoteCallbacks, TransferProgress}; +pub use crate::remote_callbacks::{Progress, TransportMessage, UpdateTips}; +pub use crate::repo::{Repository, RepositoryInitOptions}; +pub use crate::revspec::Revspec; +pub use crate::revwalk::Revwalk; +pub use crate::signature::Signature; +pub use crate::stash::{StashApplyOptions, StashApplyProgressCb, StashCb}; +pub use crate::status::{StatusEntry, StatusIter, StatusOptions, StatusShow, Statuses}; +pub use crate::submodule::{Submodule, SubmoduleUpdateOptions}; +pub use crate::tag::Tag; +pub use crate::time::{IndexTime, Time}; +pub use crate::tree::{Tree, TreeEntry, TreeIter, TreeWalkMode, TreeWalkResult}; +pub use crate::treebuilder::TreeBuilder; +pub use crate::util::IntoCString; // Create a convinience method on bitflag struct which checks the given flag macro_rules! is_bit_set { diff --git a/src/merge.rs b/src/merge.rs index 27a52c90cc..edf7cee64d 100644 --- a/src/merge.rs +++ b/src/merge.rs @@ -2,9 +2,9 @@ use libc::c_uint; use std::marker; use std::mem; -use call::Convert; -use util::Binding; -use {raw, Commit, FileFavor, Oid}; +use crate::call::Convert; +use crate::util::Binding; +use crate::{raw, Commit, FileFavor, Oid}; /// A structure to represent an annotated commit, the input to merge and rebase. /// diff --git a/src/message.rs b/src/message.rs index b36419e270..7c17eeffe0 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2,8 +2,8 @@ use std::ffi::CString; use libc::{c_char, c_int}; -use util::Binding; -use {raw, Buf, Error, IntoCString}; +use crate::util::Binding; +use crate::{raw, Buf, Error, IntoCString}; /// Clean up a message, removing extraneous whitespace, and ensure that the /// message ends with a newline. If `comment_char` is `Some`, also remove comment @@ -12,7 +12,7 @@ pub fn message_prettify( message: T, comment_char: Option, ) -> Result { - _message_prettify(try!(message.into_c_string()), comment_char) + _message_prettify(message.into_c_string()?, comment_char) } fn _message_prettify(message: CString, comment_char: Option) -> Result { @@ -33,7 +33,7 @@ pub const DEFAULT_COMMENT_CHAR: Option = Some(b'#'); #[cfg(test)] mod tests { - use {message_prettify, DEFAULT_COMMENT_CHAR}; + use crate::{message_prettify, DEFAULT_COMMENT_CHAR}; #[test] fn prettify() { diff --git a/src/note.rs b/src/note.rs index 8bf8a7f8b4..25dc3bef0d 100644 --- a/src/note.rs +++ b/src/note.rs @@ -1,8 +1,8 @@ use std::marker; use std::str; -use util::Binding; -use {raw, signature, Error, Oid, Repository, Signature}; +use crate::util::Binding; +use crate::{raw, signature, Error, Oid, Repository, Signature}; /// A structure representing a [note][note] in git. /// @@ -35,7 +35,7 @@ impl<'repo> Note<'repo> { /// Get the note message, in bytes. pub fn message_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_note_message(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_note_message(&*self.raw)).unwrap() } } /// Get the note message as a string, returning `None` if it is not UTF-8. @@ -62,8 +62,8 @@ impl<'repo> Binding for Note<'repo> { } } -impl<'repo> ::std::fmt::Debug for Note<'repo> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { +impl<'repo> std::fmt::Debug for Note<'repo> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { f.debug_struct("Note").field("id", &self.id()).finish() } } @@ -122,7 +122,7 @@ impl<'repo> Drop for Notes<'repo> { mod tests { #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); assert!(repo.notes(None).is_err()); let sig = repo.signature().unwrap(); diff --git a/src/object.rs b/src/object.rs index 023a4aed96..18c7b03c44 100644 --- a/src/object.rs +++ b/src/object.rs @@ -2,9 +2,9 @@ use std::marker; use std::mem; use std::ptr; -use util::Binding; -use {raw, Blob, Buf, Commit, Error, ObjectType, Oid, Repository, Tag, Tree}; -use {Describe, DescribeOptions}; +use crate::util::Binding; +use crate::{raw, Blob, Buf, Commit, Error, ObjectType, Oid, Repository, Tag, Tree}; +use crate::{Describe, DescribeOptions}; /// A structure to represent a git [object][1] /// @@ -212,8 +212,8 @@ impl<'repo> Clone for Object<'repo> { } } -impl<'repo> ::std::fmt::Debug for Object<'repo> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { +impl<'repo> std::fmt::Debug for Object<'repo> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { let mut ds = f.debug_struct("Object"); match self.kind() { Some(kind) => ds.field("kind", &kind), diff --git a/src/odb.rs b/src/odb.rs index 353a0778d5..6d3635a887 100644 --- a/src/odb.rs +++ b/src/odb.rs @@ -7,9 +7,9 @@ use std::ffi::CString; use libc::{c_char, c_int, c_void, size_t}; -use panic; -use util::Binding; -use {raw, Error, Object, ObjectType, Oid}; +use crate::panic; +use crate::util::Binding; +use crate::{raw, Error, Object, ObjectType, Oid}; /// A structure to represent a git object database pub struct Odb<'repo> { @@ -187,7 +187,7 @@ impl<'repo> Odb<'repo> { /// Adds an alternate disk backend to the object database. pub fn add_disk_alternate(&self, path: &str) -> Result<(), Error> { unsafe { - let path = try!(CString::new(path)); + let path = CString::new(path)?; try_call!(raw::git_odb_add_disk_alternate(self.raw, path)); Ok(()) } @@ -376,9 +376,9 @@ extern "C" fn foreach_cb(id: *const raw::git_oid, payload: *mut c_void) -> c_int #[cfg(test)] mod tests { + use crate::{ObjectType, Oid, Repository}; use std::io::prelude::*; use tempdir::TempDir; - use {ObjectType, Oid, Repository}; #[test] fn read() { diff --git a/src/oid.rs b/src/oid.rs index 6af1296613..7de941bfc7 100644 --- a/src/oid.rs +++ b/src/oid.rs @@ -5,9 +5,9 @@ use std::hash::{Hash, Hasher}; use std::path::Path; use std::str; -use {raw, Error, IntoCString, ObjectType}; +use crate::{raw, Error, IntoCString, ObjectType}; -use util::{c_cmp_to_ordering, Binding}; +use crate::util::{c_cmp_to_ordering, Binding}; /// Unique identity of any object (commit, tree, blob, tag). #[derive(Copy, Clone)] @@ -23,7 +23,7 @@ impl Oid { /// Returns an error if the string is empty, is longer than 40 hex /// characters, or contains any non-hex characters. pub fn from_str(s: &str) -> Result { - ::init(); + crate::init(); let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -41,7 +41,7 @@ impl Oid { /// /// If the array given is not 20 bytes in length, an error is returned. pub fn from_bytes(bytes: &[u8]) -> Result { - ::init(); + crate::init(); let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -65,7 +65,7 @@ impl Oid { /// an Oid corresponding to the result. This does not store the object /// inside any object database or repository. pub fn hash_object(kind: ObjectType, bytes: &[u8]) -> Result { - ::init(); + crate::init(); let mut out = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], @@ -86,9 +86,9 @@ impl Oid { /// and returns an Oid corresponding to the result. This does not store the object /// inside any object database or repository. pub fn hash_file>(kind: ObjectType, path: P) -> Result { - ::init(); + crate::init(); - let rpath = try!(path.as_ref().into_c_string()); + let rpath = path.as_ref().into_c_string()?; let mut out = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], @@ -196,8 +196,8 @@ mod tests { use super::Error; use super::Oid; + use crate::ObjectType; use tempdir::TempDir; - use ObjectType; #[test] fn conversions() { diff --git a/src/oid_array.rs b/src/oid_array.rs index 1a369abd07..b2caf0e061 100644 --- a/src/oid_array.rs +++ b/src/oid_array.rs @@ -2,11 +2,11 @@ use std::ops::Deref; -use oid::Oid; -use raw; +use crate::oid::Oid; +use crate::raw; +use crate::util::Binding; use std::mem; use std::slice; -use util::Binding; /// An oid array structure used by libgit2 /// @@ -39,8 +39,8 @@ impl Binding for OidArray { } } -impl<'repo> ::std::fmt::Debug for OidArray { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { +impl<'repo> std::fmt::Debug for OidArray { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { f.debug_tuple("OidArray").field(&self.deref()).finish() } } diff --git a/src/packbuilder.rs b/src/packbuilder.rs index 1890cf9c54..2d65c6e9d6 100644 --- a/src/packbuilder.rs +++ b/src/packbuilder.rs @@ -3,8 +3,8 @@ use std::marker; use std::ptr; use std::slice; -use util::Binding; -use {panic, raw, Buf, Error, Oid, Repository, Revwalk}; +use crate::util::Binding; +use crate::{panic, raw, Buf, Error, Oid, Repository, Revwalk}; /// Stages that are reported by the `PackBuilder` progress callback. pub enum PackBuilderStage { @@ -28,7 +28,7 @@ impl<'repo> PackBuilder<'repo> { /// Insert a single object. For an optimal pack it's mandatory to insert /// objects in recency order, commits followed by trees and blobs. pub fn insert_object(&mut self, id: Oid, name: Option<&str>) -> Result<(), Error> { - let name = try!(::opt_cstr(name)); + let name = crate::opt_cstr(name)?; unsafe { try_call!(raw::git_packbuilder_insert(self.raw, id.raw(), name)); } @@ -65,7 +65,7 @@ impl<'repo> PackBuilder<'repo> { /// Recursively insert an object and its referenced objects. Insert the /// object as well as any object it references. pub fn insert_recursive(&mut self, id: Oid, name: Option<&str>) -> Result<(), Error> { - let name = try!(::opt_cstr(name)); + let name = crate::opt_cstr(name)?; unsafe { try_call!(raw::git_packbuilder_insert_recur(self.raw, id.raw(), name)); } @@ -239,9 +239,9 @@ extern "C" fn progress_c( #[cfg(test)] mod tests { + use crate::{Buf, Oid, Repository}; use std::fs::File; use std::path::Path; - use {Buf, Oid, Repository}; fn commit(repo: &Repository) -> (Oid, Oid) { let mut index = t!(repo.index()); @@ -282,13 +282,13 @@ mod tests { #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let _builder = t!(repo.packbuilder()); } #[test] fn smoke_write_buf() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = t!(repo.packbuilder()); let mut buf = Buf::new(); t!(builder.write_buf(&mut buf)); @@ -298,7 +298,7 @@ mod tests { #[test] fn smoke_foreach() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = t!(repo.packbuilder()); let mut buf = Vec::::new(); t!(builder.foreach(|bytes| { @@ -310,7 +310,7 @@ mod tests { #[test] fn insert_write_buf() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = t!(repo.packbuilder()); let mut buf = Buf::new(); let (commit, _tree) = commit(&repo); @@ -323,7 +323,7 @@ mod tests { #[test] fn insert_tree_write_buf() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = t!(repo.packbuilder()); let mut buf = Buf::new(); let (_commit, tree) = commit(&repo); @@ -337,7 +337,7 @@ mod tests { #[test] fn insert_commit_write_buf() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = t!(repo.packbuilder()); let mut buf = Buf::new(); let (commit, _tree) = commit(&repo); @@ -353,7 +353,7 @@ mod tests { fn progress_callback() { let mut progress_called = false; { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = t!(repo.packbuilder()); let (commit, _tree) = commit(&repo); t!(builder.set_progress_callback(|_, _, _| { @@ -370,7 +370,7 @@ mod tests { fn clear_progress_callback() { let mut progress_called = false; { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = t!(repo.packbuilder()); let (commit, _tree) = commit(&repo); t!(builder.set_progress_callback(|_, _, _| { diff --git a/src/panic.rs b/src/panic.rs index 3d7c235029..70038d910c 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -5,7 +5,7 @@ thread_local!(static LAST_ERROR: RefCell>> = { RefCell::new(None) }); -pub fn wrap T + ::std::panic::UnwindSafe>(f: F) -> Option { +pub fn wrap T + std::panic::UnwindSafe>(f: F) -> Option { use std::panic; if LAST_ERROR.with(|slot| slot.borrow().is_some()) { return None; diff --git a/src/patch.rs b/src/patch.rs index c0ac9af528..62c30017b1 100644 --- a/src/patch.rs +++ b/src/patch.rs @@ -2,9 +2,9 @@ use libc::{c_int, c_void}; use std::path::Path; use std::ptr; -use diff::{print_cb, LineCb}; -use util::{into_opt_c_string, Binding}; -use {raw, Blob, Buf, Diff, DiffDelta, DiffHunk, DiffLine, DiffOptions, Error}; +use crate::diff::{print_cb, LineCb}; +use crate::util::{into_opt_c_string, Binding}; +use crate::{raw, Blob, Buf, Diff, DiffDelta, DiffHunk, DiffLine, DiffOptions, Error}; /// A structure representing the text changes in a single diff delta. /// @@ -52,8 +52,8 @@ impl Patch { opts: Option<&mut DiffOptions>, ) -> Result { let mut ret = ptr::null_mut(); - let old_path = try!(into_opt_c_string(old_path)); - let new_path = try!(into_opt_c_string(new_path)); + let old_path = into_opt_c_string(old_path)?; + let new_path = into_opt_c_string(new_path)?; unsafe { try_call!(raw::git_patch_from_blobs( &mut ret, @@ -76,8 +76,8 @@ impl Patch { opts: Option<&mut DiffOptions>, ) -> Result { let mut ret = ptr::null_mut(); - let old_path = try!(into_opt_c_string(old_path)); - let new_path = try!(into_opt_c_string(new_path)); + let old_path = into_opt_c_string(old_path)?; + let new_path = into_opt_c_string(new_path)?; unsafe { try_call!(raw::git_patch_from_blob_and_buffer( &mut ret, @@ -101,8 +101,8 @@ impl Patch { opts: Option<&mut DiffOptions>, ) -> Result { let mut ret = ptr::null_mut(); - let old_path = try!(into_opt_c_string(old_path)); - let new_path = try!(into_opt_c_string(new_path)); + let old_path = into_opt_c_string(old_path)?; + let new_path = into_opt_c_string(new_path)?; unsafe { try_call!(raw::git_patch_from_buffers( &mut ret, diff --git a/src/pathspec.rs b/src/pathspec.rs index 26a68afb2e..d609649fd2 100644 --- a/src/pathspec.rs +++ b/src/pathspec.rs @@ -5,8 +5,8 @@ use std::ops::Range; use std::path::Path; use std::ptr; -use util::Binding; -use {raw, Diff, DiffDelta, Error, Index, IntoCString, PathspecFlags, Repository, Tree}; +use crate::util::Binding; +use crate::{raw, Diff, DiffDelta, Error, Index, IntoCString, PathspecFlags, Repository, Tree}; /// Structure representing a compiled pathspec used for matching against various /// structures. @@ -45,7 +45,7 @@ impl Pathspec { T: IntoCString, I: IntoIterator, { - let (_a, _b, arr) = try!(::util::iter2cstrs(specs)); + let (_a, _b, arr) = crate::util::iter2cstrs(specs)?; unsafe { let mut ret = ptr::null_mut(); try_call!(raw::git_pathspec_new(&mut ret, &arr)); @@ -210,7 +210,7 @@ impl<'ps> PathspecMatchList<'ps> { pub fn entry(&self, i: usize) -> Option<&[u8]> { unsafe { let ptr = raw::git_pathspec_match_list_entry(&*self.raw, i as size_t); - ::opt_bytes(self, ptr) + crate::opt_bytes(self, ptr) } } @@ -257,7 +257,7 @@ impl<'ps> PathspecMatchList<'ps> { pub fn failed_entry(&self, i: usize) -> Option<&[u8]> { unsafe { let ptr = raw::git_pathspec_match_list_failed_entry(&*self.raw, i as size_t); - ::opt_bytes(self, ptr) + crate::opt_bytes(self, ptr) } } } @@ -335,9 +335,9 @@ impl<'list> ExactSizeIterator for PathspecFailedEntries<'list> {} #[cfg(test)] mod tests { use super::Pathspec; + use crate::PathspecFlags; use std::fs::File; use std::path::Path; - use PathspecFlags; #[test] fn smoke() { @@ -347,7 +347,7 @@ mod tests { assert!(!ps.matches_path(Path::new("b"), PathspecFlags::DEFAULT)); assert!(!ps.matches_path(Path::new("ab/c"), PathspecFlags::DEFAULT)); - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); let list = ps.match_workdir(&repo, PathspecFlags::DEFAULT).unwrap(); assert_eq!(list.entries().len(), 0); assert_eq!(list.diff_entries().len(), 0); @@ -356,7 +356,7 @@ mod tests { File::create(&td.path().join("a")).unwrap(); let list = ps - .match_workdir(&repo, ::PathspecFlags::FIND_FAILURES) + .match_workdir(&repo, crate::PathspecFlags::FIND_FAILURES) .unwrap(); assert_eq!(list.entries().len(), 1); assert_eq!(list.entries().next(), Some("a".as_bytes())); diff --git a/src/proxy_options.rs b/src/proxy_options.rs index e1601749be..b19ba3a527 100644 --- a/src/proxy_options.rs +++ b/src/proxy_options.rs @@ -2,8 +2,8 @@ use std::ffi::CString; use std::marker; use std::ptr; -use raw; -use util::Binding; +use crate::raw; +use crate::util::Binding; /// Options which can be specified to various fetch operations. #[derive(Default)] diff --git a/src/rebase.rs b/src/rebase.rs index 3d9b574905..578247a7e5 100644 --- a/src/rebase.rs +++ b/src/rebase.rs @@ -1,9 +1,9 @@ use std::ffi::CString; use std::{marker, mem, ptr, str}; -use build::CheckoutBuilder; -use util::Binding; -use {raw, Error, Index, MergeOptions, Oid, Signature}; +use crate::build::CheckoutBuilder; +use crate::util::Binding; +use crate::{raw, Error, Index, MergeOptions, Oid, Signature}; /// Rebase options /// @@ -157,7 +157,7 @@ impl<'repo> Rebase<'repo> { message: Option<&str>, ) -> Result { let mut id: raw::git_oid = unsafe { mem::zeroed() }; - let message = try!(::opt_cstr(message)); + let message = crate::opt_cstr(message)?; unsafe { try_call!(raw::git_rebase_commit( &mut id, @@ -299,7 +299,7 @@ impl<'rebase> RebaseOperation<'rebase> { ///The executable the user has requested be run. This will only /// be populated for operations of type RebaseOperationType::Exec pub fn exec(&self) -> Option<&str> { - unsafe { str::from_utf8(::opt_bytes(self, (*self.raw).exec).unwrap()).ok() } + unsafe { str::from_utf8(crate::opt_bytes(self, (*self.raw).exec).unwrap()).ok() } } } @@ -318,12 +318,12 @@ impl<'rebase> Binding for RebaseOperation<'rebase> { #[cfg(test)] mod tests { + use crate::{RebaseOperationType, RebaseOptions, Signature}; use std::{fs, path}; - use {RebaseOperationType, RebaseOptions, Signature}; #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let head_target = repo.head().unwrap().target().unwrap(); let tip = repo.find_commit(head_target).unwrap(); let sig = tip.author(); @@ -366,7 +366,7 @@ mod tests { #[test] fn keeping_original_author_msg() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); let head_target = repo.head().unwrap().target().unwrap(); let tip = repo.find_commit(head_target).unwrap(); let sig = Signature::now("testname", "testemail").unwrap(); diff --git a/src/reference.rs b/src/reference.rs index 11e5b30aad..eeaa5bd180 100644 --- a/src/reference.rs +++ b/src/reference.rs @@ -5,9 +5,11 @@ use std::mem; use std::ptr; use std::str; -use object::CastOrPanic; -use util::{c_cmp_to_ordering, Binding}; -use {raw, Blob, Commit, Error, Object, ObjectType, Oid, ReferenceType, Repository, Tag, Tree}; +use crate::object::CastOrPanic; +use crate::util::{c_cmp_to_ordering, Binding}; +use crate::{ + raw, Blob, Commit, Error, Object, ObjectType, Oid, ReferenceType, Repository, Tag, Tree, +}; struct Refdb<'repo>(&'repo Repository); @@ -33,7 +35,7 @@ pub struct ReferenceNames<'repo: 'references, 'references> { impl<'repo> Reference<'repo> { /// Ensure the reference name is well-formed. pub fn is_valid_name(refname: &str) -> bool { - ::init(); + crate::init(); let refname = CString::new(refname).unwrap(); unsafe { raw::git_reference_is_valid_name(refname.as_ptr()) == 1 } } @@ -93,7 +95,7 @@ impl<'repo> Reference<'repo> { /// Get the full name of a reference. pub fn name_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_reference_name(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_reference_name(&*self.raw)).unwrap() } } /// Get the full shorthand of a reference. @@ -108,7 +110,7 @@ impl<'repo> Reference<'repo> { /// Get the full shorthand of a reference. pub fn shorthand_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_reference_shorthand(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_reference_shorthand(&*self.raw)).unwrap() } } /// Get the OID pointed to by a direct reference. @@ -140,7 +142,7 @@ impl<'repo> Reference<'repo> { /// /// Only available if the reference is symbolic. pub fn symbolic_target_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_reference_symbolic_target(&*self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_reference_symbolic_target(&*self.raw)) } } /// Resolve a symbolic reference to a direct reference. @@ -175,7 +177,7 @@ impl<'repo> Reference<'repo> { /// This method recursively peels the reference until it reaches /// a blob. pub fn peel_to_blob(&self) -> Result, Error> { - Ok(try!(self.peel(ObjectType::Blob)).cast_or_panic(ObjectType::Blob)) + Ok(self.peel(ObjectType::Blob)?.cast_or_panic(ObjectType::Blob)) } /// Peel a reference to a commit @@ -183,7 +185,9 @@ impl<'repo> Reference<'repo> { /// This method recursively peels the reference until it reaches /// a commit. pub fn peel_to_commit(&self) -> Result, Error> { - Ok(try!(self.peel(ObjectType::Commit)).cast_or_panic(ObjectType::Commit)) + Ok(self + .peel(ObjectType::Commit)? + .cast_or_panic(ObjectType::Commit)) } /// Peel a reference to a tree @@ -191,7 +195,7 @@ impl<'repo> Reference<'repo> { /// This method recursively peels the reference until it reaches /// a tree. pub fn peel_to_tree(&self) -> Result, Error> { - Ok(try!(self.peel(ObjectType::Tree)).cast_or_panic(ObjectType::Tree)) + Ok(self.peel(ObjectType::Tree)?.cast_or_panic(ObjectType::Tree)) } /// Peel a reference to a tag @@ -199,7 +203,7 @@ impl<'repo> Reference<'repo> { /// This method recursively peels the reference until it reaches /// a tag. pub fn peel_to_tag(&self) -> Result, Error> { - Ok(try!(self.peel(ObjectType::Tag)).cast_or_panic(ObjectType::Tag)) + Ok(self.peel(ObjectType::Tag)?.cast_or_panic(ObjectType::Tag)) } /// Rename an existing reference. @@ -215,8 +219,8 @@ impl<'repo> Reference<'repo> { msg: &str, ) -> Result, Error> { let mut raw = ptr::null_mut(); - let new_name = try!(CString::new(new_name)); - let msg = try!(CString::new(msg)); + let new_name = CString::new(new_name)?; + let msg = CString::new(msg)?; unsafe { try_call!(raw::git_reference_rename( &mut raw, self.raw, new_name, force, msg @@ -233,7 +237,7 @@ impl<'repo> Reference<'repo> { /// reference. pub fn set_target(&mut self, id: Oid, reflog_msg: &str) -> Result, Error> { let mut raw = ptr::null_mut(); - let msg = try!(CString::new(reflog_msg)); + let msg = CString::new(reflog_msg)?; unsafe { try_call!(raw::git_reference_set_target( &mut raw, @@ -334,7 +338,7 @@ impl<'repo, 'references> Iterator for ReferenceNames<'repo, 'references> { let mut out = ptr::null(); unsafe { try_call_iter!(raw::git_reference_next_name(&mut out, self.inner.raw)); - let bytes = ::opt_bytes(self, out).unwrap(); + let bytes = crate::opt_bytes(self, out).unwrap(); let s = str::from_utf8(bytes).unwrap(); Some(Ok(mem::transmute::<&str, &'references str>(s))) } @@ -343,7 +347,7 @@ impl<'repo, 'references> Iterator for ReferenceNames<'repo, 'references> { #[cfg(test)] mod tests { - use {ObjectType, Reference, ReferenceType}; + use crate::{ObjectType, Reference, ReferenceType}; #[test] fn smoke() { @@ -353,7 +357,7 @@ mod tests { #[test] fn smoke2() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut head = repo.head().unwrap(); assert!(head.is_branch()); assert!(!head.is_remote()); diff --git a/src/reflog.rs b/src/reflog.rs index 4e0acfba5d..0aed4e56bd 100644 --- a/src/reflog.rs +++ b/src/reflog.rs @@ -3,8 +3,8 @@ use std::marker; use std::ops::Range; use std::str; -use util::Binding; -use {raw, signature, Error, Oid, Signature}; +use crate::util::Binding; +use crate::{raw, signature, Error, Oid, Signature}; /// A reference log of a git repository. pub struct Reflog { @@ -31,7 +31,7 @@ impl Reflog { committer: &Signature, msg: Option<&str>, ) -> Result<(), Error> { - let msg = try!(::opt_cstr(msg)); + let msg = crate::opt_cstr(msg)?; unsafe { try_call!(raw::git_reflog_append( self.raw, @@ -142,7 +142,7 @@ impl<'reflog> ReflogEntry<'reflog> { /// Get the log message as a byte array. pub fn message_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_reflog_entry_message(self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_reflog_entry_message(self.raw)) } } } @@ -180,7 +180,7 @@ impl<'reflog> ExactSizeIterator for ReflogIter<'reflog> {} mod tests { #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut reflog = repo.reflog("HEAD").unwrap(); assert_eq!(reflog.iter().len(), 1); reflog.write().unwrap(); diff --git a/src/refspec.rs b/src/refspec.rs index 61654a6762..79e529d6c8 100644 --- a/src/refspec.rs +++ b/src/refspec.rs @@ -2,8 +2,8 @@ use std::ffi::CString; use std::marker; use std::str; -use util::Binding; -use {raw, Direction}; +use crate::util::Binding; +use crate::{raw, Direction}; /// A structure to represent a git [refspec][1]. /// @@ -34,7 +34,7 @@ impl<'remote> Refspec<'remote> { /// Get the destination specifier, in bytes. pub fn dst_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_refspec_dst(self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_refspec_dst(self.raw)).unwrap() } } /// Check if a refspec's destination descriptor matches a reference @@ -52,7 +52,7 @@ impl<'remote> Refspec<'remote> { /// Get the source specifier, in bytes. pub fn src_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_refspec_src(self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_refspec_src(self.raw)).unwrap() } } /// Check if a refspec's source descriptor matches a reference @@ -75,7 +75,7 @@ impl<'remote> Refspec<'remote> { /// Get the refspec's string as a byte array pub fn bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_refspec_string(self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_refspec_string(self.raw)).unwrap() } } } diff --git a/src/remote.rs b/src/remote.rs index e723155c42..9b919c9cbd 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -7,10 +7,10 @@ use std::ptr; use std::slice; use std::str; -use string_array::StringArray; -use util::Binding; -use {raw, Direction, Error, FetchPrune, Oid, ProxyOptions, Refspec}; -use {AutotagOption, Progress, RemoteCallbacks, Repository}; +use crate::string_array::StringArray; +use crate::util::Binding; +use crate::{raw, Direction, Error, FetchPrune, Oid, ProxyOptions, Refspec}; +use crate::{AutotagOption, Progress, RemoteCallbacks, Repository}; /// A structure representing a [remote][1] of a git repository. /// @@ -71,7 +71,7 @@ pub fn remote_into_raw(remote: Remote) -> *mut raw::git_remote { impl<'repo> Remote<'repo> { /// Ensure the remote name is well-formed. pub fn is_valid_name(remote_name: &str) -> bool { - ::init(); + crate::init(); let remote_name = CString::new(remote_name).unwrap(); unsafe { raw::git_remote_is_valid_name(remote_name.as_ptr()) == 1 } } @@ -88,7 +88,7 @@ impl<'repo> Remote<'repo> { /// /// Returns `None` if this remote has not yet been named pub fn name_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_remote_name(&*self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_remote_name(&*self.raw)) } } /// Get the remote's url. @@ -100,7 +100,7 @@ impl<'repo> Remote<'repo> { /// Get the remote's url as a byte array. pub fn url_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_remote_url(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_remote_url(&*self.raw)).unwrap() } } /// Get the remote's pushurl. @@ -112,7 +112,7 @@ impl<'repo> Remote<'repo> { /// Get the remote's pushurl as a byte array. pub fn pushurl_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_remote_pushurl(&*self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_remote_pushurl(&*self.raw)) } } /// Open a connection to a remote. @@ -183,7 +183,7 @@ impl<'repo> Remote<'repo> { specs: &[&str], opts: Option<&mut FetchOptions>, ) -> Result<(), Error> { - let (_a, _b, arr) = try!(::util::iter2cstrs(specs.iter())); + let (_a, _b, arr) = crate::util::iter2cstrs(specs.iter())?; let raw = opts.map(|o| o.raw()); unsafe { try_call!(raw::git_remote_download(self.raw, &arr, raw.as_ref())); @@ -233,8 +233,8 @@ impl<'repo> Remote<'repo> { opts: Option<&mut FetchOptions>, reflog_msg: Option<&str>, ) -> Result<(), Error> { - let (_a, _b, arr) = try!(::util::iter2cstrs(refspecs.iter())); - let msg = try!(::opt_cstr(reflog_msg)); + let (_a, _b, arr) = crate::util::iter2cstrs(refspecs.iter())?; + let msg = crate::opt_cstr(reflog_msg)?; let raw = opts.map(|o| o.raw()); unsafe { try_call!(raw::git_remote_fetch(self.raw, &arr, raw.as_ref(), msg)); @@ -250,7 +250,7 @@ impl<'repo> Remote<'repo> { download_tags: AutotagOption, msg: Option<&str>, ) -> Result<(), Error> { - let msg = try!(::opt_cstr(msg)); + let msg = crate::opt_cstr(msg)?; let cbs = callbacks.map(|cb| cb.raw()); unsafe { try_call!(raw::git_remote_update_tips( @@ -273,7 +273,7 @@ impl<'repo> Remote<'repo> { /// `push_update_reference` to test whether all the references were pushed /// successfully. pub fn push(&mut self, refspecs: &[&str], opts: Option<&mut PushOptions>) -> Result<(), Error> { - let (_a, _b, arr) = try!(::util::iter2cstrs(refspecs.iter())); + let (_a, _b, arr) = crate::util::iter2cstrs(refspecs.iter())?; let raw = opts.map(|o| o.raw()); unsafe { try_call!(raw::git_remote_push(self.raw, &arr, raw.as_ref())); @@ -395,12 +395,12 @@ impl<'remote> RemoteHead<'remote> { } pub fn name(&self) -> &str { - let b = unsafe { ::opt_bytes(self, (*self.raw).name).unwrap() }; + let b = unsafe { crate::opt_bytes(self, (*self.raw).name).unwrap() }; str::from_utf8(b).unwrap() } pub fn symref_target(&self) -> Option<&str> { - let b = unsafe { ::opt_bytes(self, (*self.raw).symref_target) }; + let b = unsafe { crate::opt_bytes(self, (*self.raw).symref_target) }; b.map(|b| str::from_utf8(b).unwrap()) } } @@ -478,9 +478,9 @@ impl<'cb> Binding for FetchOptions<'cb> { .as_ref() .map(|m| m.raw()) .unwrap_or_else(|| ProxyOptions::new().raw()), - prune: ::call::convert(&self.prune), - update_fetchhead: ::call::convert(&self.update_fetchhead), - download_tags: ::call::convert(&self.download_tags), + prune: crate::call::convert(&self.prune), + update_fetchhead: crate::call::convert(&self.update_fetchhead), + download_tags: crate::call::convert(&self.download_tags), // TODO: expose this as a builder option custom_headers: raw::git_strarray { count: 0, @@ -582,14 +582,14 @@ impl<'repo, 'connection, 'cb> Drop for RemoteConnection<'repo, 'connection, 'cb> #[cfg(test)] mod tests { + use crate::{AutotagOption, PushOptions}; + use crate::{Direction, FetchOptions, Remote, RemoteCallbacks, Repository}; use std::cell::Cell; use tempdir::TempDir; - use {AutotagOption, PushOptions}; - use {Direction, FetchOptions, Remote, RemoteCallbacks, Repository}; #[test] fn smoke() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); t!(repo.remote("origin", "/path/to/nowhere")); drop(repo); @@ -612,7 +612,7 @@ mod tests { let remote = td.path().join("remote"); Repository::init_bare(&remote).unwrap(); - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let url = if cfg!(unix) { format!("file://{}", remote.display()) } else { @@ -681,7 +681,7 @@ mod tests { #[test] fn rename_remote() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); repo.remote("origin", "foo").unwrap(); drop(repo.remote_rename("origin", "foo")); drop(repo.remote_delete("foo")); @@ -705,9 +705,9 @@ mod tests { #[test] fn transfer_cb() { - let (td, _repo) = ::test::repo_init(); + let (td, _repo) = crate::test::repo_init(); let td2 = TempDir::new("git").unwrap(); - let url = ::test::path2url(&td.path()); + let url = crate::test::path2url(&td.path()); let repo = Repository::init(td2.path()).unwrap(); let progress_hit = Cell::new(false); @@ -741,9 +741,9 @@ mod tests { /// segfaults #[test] fn connect_list() { - let (td, _repo) = ::test::repo_init(); + let (td, _repo) = crate::test::repo_init(); let td2 = TempDir::new("git").unwrap(); - let url = ::test::path2url(&td.path()); + let url = crate::test::path2url(&td.path()); let repo = Repository::init(td2.path()).unwrap(); let mut callbacks = RemoteCallbacks::new(); @@ -772,10 +772,10 @@ mod tests { #[test] fn push() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let td2 = TempDir::new("git1").unwrap(); let td3 = TempDir::new("git2").unwrap(); - let url = ::test::path2url(&td2.path()); + let url = crate::test::path2url(&td2.path()); Repository::init_bare(td2.path()).unwrap(); // git push diff --git a/src/remote_callbacks.rs b/src/remote_callbacks.rs index fdadd77a18..b4521213a9 100644 --- a/src/remote_callbacks.rs +++ b/src/remote_callbacks.rs @@ -6,9 +6,9 @@ use std::ptr; use std::slice; use std::str; -use cert::Cert; -use util::Binding; -use {panic, raw, Cred, CredentialType, Error, Oid}; +use crate::cert::Cert; +use crate::util::Binding; +use crate::{panic, raw, Cred, CredentialType, Error, Oid}; /// A structure to contain the callbacks which are invoked when a repository is /// being updated or downloaded. @@ -276,17 +276,17 @@ extern "C" fn credentials_cb( unsafe { let ok = panic::wrap(|| { let payload = &mut *(payload as *mut RemoteCallbacks); - let callback = try!(payload + let callback = payload .credentials .as_mut() - .ok_or(raw::GIT_PASSTHROUGH as c_int)); + .ok_or(raw::GIT_PASSTHROUGH as c_int)?; *ret = ptr::null_mut(); - let url = try!(str::from_utf8(CStr::from_ptr(url).to_bytes()) - .map_err(|_| raw::GIT_PASSTHROUGH as c_int)); - let username_from_url = match ::opt_bytes(&url, username_from_url) { - Some(username) => Some(try!( - str::from_utf8(username).map_err(|_| raw::GIT_PASSTHROUGH as c_int) - )), + let url = str::from_utf8(CStr::from_ptr(url).to_bytes()) + .map_err(|_| raw::GIT_PASSTHROUGH as c_int)?; + let username_from_url = match crate::opt_bytes(&url, username_from_url) { + Some(username) => { + Some(str::from_utf8(username).map_err(|_| raw::GIT_PASSTHROUGH as c_int)?) + } None => None, }; diff --git a/src/repo.rs b/src/repo.rs index 2135354f22..59cdf4f8a5 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -7,24 +7,24 @@ use std::path::Path; use std::ptr; use std::str; -use build::{CheckoutBuilder, RepoBuilder}; -use oid_array::OidArray; -use stash::{stash_cb, StashApplyOptions, StashCbData}; -use string_array::StringArray; -use util::{self, Binding}; -use { +use crate::build::{CheckoutBuilder, RepoBuilder}; +use crate::oid_array::OidArray; +use crate::stash::{stash_cb, StashApplyOptions, StashCbData}; +use crate::string_array::StringArray; +use crate::util::{self, Binding}; +use crate::{ init, raw, Buf, Error, Object, Remote, RepositoryOpenFlags, RepositoryState, Revspec, StashFlags, }; -use { +use crate::{ AnnotatedCommit, MergeAnalysis, MergeOptions, MergePreference, SubmoduleIgnore, SubmoduleStatus, }; -use {Blame, BlameOptions, Reference, References, ResetType, Signature, Submodule}; -use {Blob, BlobWriter, Branch, BranchType, Branches, Commit, Config, Index, Oid, Tree}; -use {Describe, IntoCString, Reflog, RepositoryInitMode, RevparseMode}; -use {DescribeOptions, Diff, DiffOptions, Odb, PackBuilder, TreeBuilder}; -use {Note, Notes, ObjectType, Revwalk, Status, StatusOptions, Statuses, Tag}; -use {Rebase, RebaseOptions}; +use crate::{Blame, BlameOptions, Reference, References, ResetType, Signature, Submodule}; +use crate::{Blob, BlobWriter, Branch, BranchType, Branches, Commit, Config, Index, Oid, Tree}; +use crate::{Describe, IntoCString, Reflog, RepositoryInitMode, RevparseMode}; +use crate::{DescribeOptions, Diff, DiffOptions, Odb, PackBuilder, TreeBuilder}; +use crate::{Note, Notes, ObjectType, Revwalk, Status, StatusOptions, Statuses, Tag}; +use crate::{Rebase, RebaseOptions}; /// An owned git repository, representing all state associated with the /// underlying filesystem. @@ -60,7 +60,7 @@ impl Repository { /// The path can point to either a normal or bare repository. pub fn open>(path: P) -> Result { init(); - let path = try!(path.as_ref().into_c_string()); + let path = path.as_ref().into_c_string()?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_repository_open(&mut ret, path)); @@ -73,7 +73,7 @@ impl Repository { /// The path can point to only a bare repository. pub fn open_bare>(path: P) -> Result { init(); - let path = try!(path.as_ref().into_c_string()); + let path = path.as_ref().into_c_string()?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_repository_open_bare(&mut ret, path)); @@ -138,9 +138,9 @@ impl Repository { I: IntoIterator, { init(); - let path = try!(path.as_ref().into_c_string()); - let ceiling_dirs_os = try!(env::join_paths(ceiling_dirs)); - let ceiling_dirs = try!(ceiling_dirs_os.into_c_string()); + let path = path.as_ref().into_c_string()?; + let ceiling_dirs_os = env::join_paths(ceiling_dirs)?; + let ceiling_dirs = ceiling_dirs_os.into_c_string()?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_repository_open_ext( @@ -161,7 +161,7 @@ impl Repository { // TODO: this diverges significantly from the libgit2 API init(); let buf = Buf::new(); - let path = try!(path.as_ref().into_c_string()); + let path = path.as_ref().into_c_string()?; unsafe { try_call!(raw::git_repository_discover( buf.raw(), @@ -197,7 +197,7 @@ impl Repository { opts: &RepositoryInitOptions, ) -> Result { init(); - let path = try!(path.as_ref().into_c_string()); + let path = path.as_ref().into_c_string()?; let mut ret = ptr::null_mut(); unsafe { let mut opts = opts.raw(); @@ -211,7 +211,7 @@ impl Repository { /// See the `RepoBuilder` struct for more information. This function will /// delegate to a fresh `RepoBuilder` pub fn clone>(url: &str, into: P) -> Result { - ::init(); + crate::init(); RepoBuilder::new().clone(url, into.as_ref()) } @@ -265,7 +265,7 @@ impl Repository { to: ptr::null_mut(), flags: 0, }; - let spec = try!(CString::new(spec)); + let spec = CString::new(spec)?; unsafe { try_call!(raw::git_revparse(&mut raw, self.raw, spec)); let to = Binding::from_raw_opt(raw.to); @@ -277,7 +277,7 @@ impl Repository { /// Find a single object, as specified by a revision string. pub fn revparse_single(&self, spec: &str) -> Result { - let spec = try!(CString::new(spec)); + let spec = CString::new(spec)?; let mut obj = ptr::null_mut(); unsafe { try_call!(raw::git_revparse_single(&mut obj, self.raw, spec)); @@ -296,7 +296,7 @@ impl Repository { /// may point to an intermediate reference. When such expressions are being /// passed in, this intermediate reference is returned. pub fn revparse_ext(&self, spec: &str) -> Result<(Object, Option), Error> { - let spec = try!(CString::new(spec)); + let spec = CString::new(spec)?; let mut git_obj = ptr::null_mut(); let mut git_ref = ptr::null_mut(); unsafe { @@ -337,7 +337,7 @@ impl Repository { pub fn path(&self) -> &Path { unsafe { let ptr = raw::git_repository_path(self.raw); - util::bytes2path(::opt_bytes(self, ptr).unwrap()) + util::bytes2path(crate::opt_bytes(self, ptr).unwrap()) } } @@ -389,7 +389,7 @@ impl Repository { /// and set config "core.worktree" (if workdir is not the parent of the .git /// directory). pub fn set_workdir(&self, path: &Path, update_gitlink: bool) -> Result<(), Error> { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; unsafe { try_call!(raw::git_repository_set_workdir( self.raw(), @@ -412,7 +412,7 @@ impl Repository { /// /// If there is no namespace, `None` is returned. pub fn namespace_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_repository_get_namespace(self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_repository_get_namespace(self.raw)) } } /// Set the active namespace for this repository. @@ -423,7 +423,7 @@ impl Repository { /// Set the active namespace for this repository as a byte array. pub fn set_namespace_bytes(&self, namespace: &[u8]) -> Result<(), Error> { unsafe { - let namespace = try!(CString::new(namespace)); + let namespace = CString::new(namespace)?; try_call!(raw::git_repository_set_namespace(self.raw, namespace)); Ok(()) } @@ -470,7 +470,7 @@ impl Repository { /// Get the information for a particular remote pub fn find_remote(&self, name: &str) -> Result { let mut ret = ptr::null_mut(); - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_remote_lookup(&mut ret, self.raw, name)); Ok(Binding::from_raw(ret)) @@ -481,8 +481,8 @@ impl Repository { /// configuration. pub fn remote(&self, name: &str, url: &str) -> Result { let mut ret = ptr::null_mut(); - let name = try!(CString::new(name)); - let url = try!(CString::new(url)); + let name = CString::new(name)?; + let url = CString::new(url)?; unsafe { try_call!(raw::git_remote_create(&mut ret, self.raw, name, url)); Ok(Binding::from_raw(ret)) @@ -496,7 +496,7 @@ impl Repository { /// remotes cannot be converted to persisted remotes. pub fn remote_anonymous(&self, url: &str) -> Result { let mut ret = ptr::null_mut(); - let url = try!(CString::new(url)); + let url = CString::new(url)?; unsafe { try_call!(raw::git_remote_create_anonymous(&mut ret, self.raw, url)); Ok(Binding::from_raw(ret)) @@ -517,8 +517,8 @@ impl Repository { /// which cannot be renamed and are returned for further processing by the /// caller. pub fn remote_rename(&self, name: &str, new_name: &str) -> Result { - let name = try!(CString::new(name)); - let new_name = try!(CString::new(new_name)); + let name = CString::new(name)?; + let new_name = CString::new(new_name)?; let mut problems = raw::git_strarray { count: 0, strings: 0 as *mut *mut c_char, @@ -539,7 +539,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> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_remote_delete(self.raw, name)); } @@ -551,8 +551,8 @@ impl Repository { /// Add the given refspec to the fetch list in the configuration. No loaded /// remote instances will be affected. pub fn remote_add_fetch(&self, name: &str, spec: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); - let spec = try!(CString::new(spec)); + let name = CString::new(name)?; + let spec = CString::new(spec)?; unsafe { try_call!(raw::git_remote_add_fetch(self.raw, name, spec)); } @@ -564,8 +564,8 @@ impl Repository { /// Add the given refspec to the push list in the configuration. No /// loaded remote instances will be affected. pub fn remote_add_push(&self, name: &str, spec: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); - let spec = try!(CString::new(spec)); + let name = CString::new(name)?; + let spec = CString::new(spec)?; unsafe { try_call!(raw::git_remote_add_push(self.raw, name, spec)); } @@ -578,8 +578,8 @@ impl Repository { /// the common case of a single-url remote and will otherwise return an /// error. pub fn remote_set_url(&self, name: &str, url: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); - let url = try!(CString::new(url)); + let name = CString::new(name)?; + let url = CString::new(url)?; unsafe { try_call!(raw::git_remote_set_url(self.raw, name, url)); } @@ -594,8 +594,8 @@ impl Repository { /// /// `None` indicates that it should be cleared. pub fn remote_set_pushurl(&self, name: &str, pushurl: Option<&str>) -> Result<(), Error> { - let name = try!(CString::new(name)); - let pushurl = try!(::opt_cstr(pushurl)); + let name = CString::new(name)?; + let pushurl = crate::opt_cstr(pushurl)?; unsafe { try_call!(raw::git_remote_set_pushurl(self.raw, name, pushurl)); } @@ -652,7 +652,7 @@ impl Repository { T: IntoCString, I: IntoIterator, { - let (_a, _b, mut arr) = try!(::util::iter2cstrs(paths)); + let (_a, _b, mut arr) = crate::util::iter2cstrs(paths)?; let target = target.map(|t| t.raw()); unsafe { try_call!(raw::git_reset_default(self.raw, target, &mut arr)); @@ -682,7 +682,7 @@ impl Repository { /// Otherwise, the HEAD will be detached and will directly point to the /// commit. pub fn set_head(&self, refname: &str) -> Result<(), Error> { - let refname = try!(CString::new(refname)); + let refname = CString::new(refname)?; unsafe { try_call!(raw::git_repository_set_head(self.raw, refname)); } @@ -734,7 +734,7 @@ impl Repository { /// glob pub fn references_glob(&self, glob: &str) -> Result { let mut ret = ptr::null_mut(); - let glob = try!(CString::new(glob)); + let glob = CString::new(glob)?; unsafe { try_call!(raw::git_reference_iterator_glob_new( &mut ret, self.raw, glob @@ -810,7 +810,7 @@ impl Repository { /// directory containing the file, would it be added or not? pub fn status_should_ignore(&self, path: &Path) -> Result { let mut ret = 0 as c_int; - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; unsafe { try_call!(raw::git_status_should_ignore(&mut ret, self.raw, path)); } @@ -838,11 +838,9 @@ impl Repository { let path = if cfg!(windows) { // `git_status_file` dose not work with windows path separator // so we convert \ to / - try!(::std::ffi::CString::new( - path.to_string_lossy().replace('\\', "/") - )) + std::ffi::CString::new(path.to_string_lossy().replace('\\', "/"))? } else { - try!(path.into_c_string()) + path.into_c_string()? }; unsafe { try_call!(raw::git_status_file(&mut ret, self.raw, path)); @@ -918,7 +916,7 @@ impl Repository { /// The Oid returned can in turn be passed to `find_blob` to get a handle to /// the blob. pub fn blob_path(&self, path: &Path) -> Result { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -941,7 +939,7 @@ impl Repository { /// to the object database. pub fn blob_writer(&self, hintpath: Option<&Path>) -> Result { let path_str = match hintpath { - Some(path) => Some(try!(path.into_c_string())), + Some(path) => Some(path.into_c_string()?), None => None, }; let path = match path_str { @@ -979,7 +977,7 @@ impl Repository { /// If `force` is true and a reference already exists with the given name, /// it'll be replaced. pub fn branch(&self, branch_name: &str, target: &Commit, force: bool) -> Result { - let branch_name = try!(CString::new(branch_name)); + let branch_name = CString::new(branch_name)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_branch_create( @@ -995,7 +993,7 @@ impl Repository { /// Lookup a branch by its name in a repository. pub fn find_branch(&self, name: &str, branch_type: BranchType) -> Result { - let name = try!(CString::new(name)); + let name = CString::new(name)?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_branch_lookup( @@ -1025,12 +1023,12 @@ impl Repository { tree: &Tree, parents: &[&Commit], ) -> Result { - let update_ref = try!(::opt_cstr(update_ref)); + let update_ref = crate::opt_cstr(update_ref)?; let mut parent_ptrs = parents .iter() .map(|p| p.raw() as *const raw::git_commit) .collect::>(); - let message = try!(CString::new(message)); + let message = CString::new(message)?; let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -1067,9 +1065,9 @@ impl Repository { signature: &str, signature_field: Option<&str>, ) -> Result { - let commit_content = try!(CString::new(commit_content)); - let signature = try!(CString::new(signature)); - let signature_field = try!(::opt_cstr(signature_field)); + let commit_content = CString::new(commit_content)?; + let signature = CString::new(signature)?; + let signature_field = crate::opt_cstr(signature_field)?; let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -1094,7 +1092,7 @@ impl Repository { commit_id: &Oid, signature_field: Option<&str>, ) -> Result<(Buf, Buf), Error> { - let signature_field = try!(::opt_cstr(signature_field)); + let signature_field = crate::opt_cstr(signature_field)?; let signature = Buf::new(); let content = Buf::new(); unsafe { @@ -1157,8 +1155,8 @@ impl Repository { force: bool, log_message: &str, ) -> Result { - let name = try!(CString::new(name)); - let log_message = try!(CString::new(log_message)); + let name = CString::new(name)?; + let log_message = CString::new(log_message)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_reference_create( @@ -1211,8 +1209,8 @@ impl Repository { current_id: Oid, log_message: &str, ) -> Result { - let name = try!(CString::new(name)); - let log_message = try!(CString::new(log_message)); + let name = CString::new(name)?; + let log_message = CString::new(log_message)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_reference_create_matching( @@ -1240,9 +1238,9 @@ impl Repository { force: bool, log_message: &str, ) -> Result { - let name = try!(CString::new(name)); - let target = try!(CString::new(target)); - let log_message = try!(CString::new(log_message)); + let name = CString::new(name)?; + let target = CString::new(target)?; + let log_message = CString::new(log_message)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_reference_symbolic_create( @@ -1274,10 +1272,10 @@ impl Repository { current_value: &str, log_message: &str, ) -> Result { - let name = try!(CString::new(name)); - let target = try!(CString::new(target)); - let current_value = try!(CString::new(current_value)); - let log_message = try!(CString::new(log_message)); + let name = CString::new(name)?; + let target = CString::new(target)?; + let current_value = CString::new(current_value)?; + let log_message = CString::new(log_message)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_reference_symbolic_create_matching( @@ -1295,7 +1293,7 @@ impl Repository { /// Lookup a reference to one of the objects in a repository. pub fn find_reference(&self, name: &str) -> Result { - let name = try!(CString::new(name)); + let name = CString::new(name)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_reference_lookup(&mut raw, self.raw(), name)); @@ -1308,7 +1306,7 @@ impl Repository { /// human-readable format e.g. 'master' instead of 'refs/heads/master', and it /// will do-what-you-mean, returning the `Reference`. pub fn resolve_reference_from_short_name(&self, refname: &str) -> Result { - let refname = try!(CString::new(refname)); + let refname = CString::new(refname)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_reference_dwim(&mut raw, self.raw(), refname)); @@ -1322,7 +1320,7 @@ impl Repository { /// through to the object id that it refers to. This avoids having to /// allocate or free any `Reference` objects for simple situations. pub fn refname_to_id(&self, name: &str) -> Result { - let name = try!(CString::new(name)); + let name = CString::new(name)?; let mut ret = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -1375,8 +1373,8 @@ impl Repository { /// `add_finalize()` to wrap up adding the new submodule and `.gitmodules` /// to the index to be ready to commit. pub fn submodule(&self, url: &str, path: &Path, use_gitlink: bool) -> Result { - let url = try!(CString::new(url)); - let path = try!(path.into_c_string()); + let url = CString::new(url)?; + let path = path.into_c_string()?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_submodule_add_setup( @@ -1395,7 +1393,7 @@ impl Repository { /// Given either the submodule name or path (they are usually the same), /// this returns a structure describing the submodule. pub fn find_submodule(&self, name: &str) -> Result { - let name = try!(CString::new(name)); + let name = CString::new(name)?; let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_submodule_lookup(&mut raw, self.raw(), name)); @@ -1413,7 +1411,7 @@ impl Repository { ignore: SubmoduleIgnore, ) -> Result { let mut ret = 0; - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_submodule_status(&mut ret, self.raw, name, ignore)); } @@ -1465,8 +1463,8 @@ impl Repository { message: &str, force: bool, ) -> Result { - let name = try!(CString::new(name)); - let message = try!(CString::new(message)); + let name = CString::new(name)?; + let message = CString::new(message)?; let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -1490,7 +1488,7 @@ impl Repository { /// If force is true and a reference already exists with the given name, /// it'll be replaced. pub fn tag_lightweight(&self, name: &str, target: &Object, force: bool) -> Result { - let name = try!(CString::new(name)); + let name = CString::new(name)?; let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -1520,7 +1518,7 @@ impl Repository { /// The tag name will be checked for validity, see `tag` for some rules /// about valid names. pub fn tag_delete(&self, name: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_tag_delete(self.raw, name)); Ok(()) @@ -1538,7 +1536,7 @@ impl Repository { unsafe { match pattern { Some(s) => { - let s = try!(CString::new(s)); + let s = CString::new(s)?; try_call!(raw::git_tag_list_match(&mut arr, s, self.raw)); } None => { @@ -1793,8 +1791,8 @@ impl Repository { note: &str, force: bool, ) -> Result { - let notes_ref = try!(::opt_cstr(notes_ref)); - let note = try!(CString::new(note)); + let notes_ref = crate::opt_cstr(notes_ref)?; + let note = CString::new(note)?; let mut ret = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; @@ -1831,7 +1829,7 @@ impl Repository { /// is the id of the note and the second id is the id the note is /// annotating. pub fn notes(&self, notes_ref: Option<&str>) -> Result { - let notes_ref = try!(::opt_cstr(notes_ref)); + let notes_ref = crate::opt_cstr(notes_ref)?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_note_iterator_new(&mut ret, self.raw, notes_ref)); @@ -1846,7 +1844,7 @@ impl Repository { /// /// The id specified is the Oid of the git object to read the note from. pub fn find_note(&self, notes_ref: Option<&str>, id: Oid) -> Result { - let notes_ref = try!(::opt_cstr(notes_ref)); + let notes_ref = crate::opt_cstr(notes_ref)?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_note_read(&mut ret, self.raw, notes_ref, id.raw())); @@ -1867,7 +1865,7 @@ impl Repository { author: &Signature, committer: &Signature, ) -> Result<(), Error> { - let notes_ref = try!(::opt_cstr(notes_ref)); + let notes_ref = crate::opt_cstr(notes_ref)?; unsafe { try_call!(raw::git_note_remove( self.raw, @@ -1891,7 +1889,7 @@ impl Repository { /// Get the blame for a single file. pub fn blame_file(&self, path: &Path, opts: Option<&mut BlameOptions>) -> Result { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; let mut raw = ptr::null_mut(); unsafe { @@ -1976,7 +1974,7 @@ impl Repository { /// If there is no reflog file for the given reference yet, an empty reflog /// object will be returned. pub fn reflog(&self, name: &str) -> Result { - let name = try!(CString::new(name)); + let name = CString::new(name)?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_reflog_read(&mut ret, self.raw, name)); @@ -1986,7 +1984,7 @@ impl Repository { /// Delete the reflog for the given reference pub fn reflog_delete(&self, name: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_reflog_delete(self.raw, name)); } @@ -1997,8 +1995,8 @@ impl Repository { /// /// The reflog to be renamed is expected to already exist. pub fn reflog_rename(&self, old_name: &str, new_name: &str) -> Result<(), Error> { - let old_name = try!(CString::new(old_name)); - let new_name = try!(CString::new(new_name)); + let old_name = CString::new(old_name)?; + let new_name = CString::new(new_name)?; unsafe { try_call!(raw::git_reflog_rename(self.raw, old_name, new_name)); } @@ -2007,14 +2005,14 @@ impl Repository { /// Check if the given reference has a reflog. pub fn reference_has_log(&self, name: &str) -> Result { - let name = try!(CString::new(name)); + let name = CString::new(name)?; let ret = unsafe { try_call!(raw::git_reference_has_log(self.raw, name)) }; Ok(ret != 0) } /// Ensure that the given reference has a reflog. pub fn reference_ensure_log(&self, name: &str) -> Result<(), Error> { - let name = try!(CString::new(name)); + let name = CString::new(name)?; unsafe { try_call!(raw::git_reference_ensure_log(self.raw, name)); } @@ -2224,7 +2222,7 @@ impl Repository { let mut raw_oid = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; - let message = try!(CString::new(message)); + let message = CString::new(message)?; let flags = flags.unwrap_or_else(StashFlags::empty); try_call!(raw::git_stash_save( &mut raw_oid, @@ -2315,11 +2313,9 @@ impl Repository { let path = if cfg!(windows) { // `git_ignore_path_is_ignored` dose not work with windows path separator // so we convert \ to / - try!(::std::ffi::CString::new( - path.as_ref().to_string_lossy().replace('\\', "/") - )) + std::ffi::CString::new(path.as_ref().to_string_lossy().replace('\\', "/"))? } else { - try!(path.as_ref().into_c_string()) + path.as_ref().into_c_string()? }; let mut ignored: c_int = 0; unsafe { @@ -2498,23 +2494,23 @@ impl RepositoryInitOptions { ); opts.flags = self.flags; opts.mode = self.mode; - opts.workdir_path = ::call::convert(&self.workdir_path); - opts.description = ::call::convert(&self.description); - opts.template_path = ::call::convert(&self.template_path); - opts.initial_head = ::call::convert(&self.initial_head); - opts.origin_url = ::call::convert(&self.origin_url); + opts.workdir_path = crate::call::convert(&self.workdir_path); + opts.description = crate::call::convert(&self.description); + opts.template_path = crate::call::convert(&self.template_path); + opts.initial_head = crate::call::convert(&self.initial_head); + opts.origin_url = crate::call::convert(&self.origin_url); opts } } #[cfg(test)] mod tests { - use build::CheckoutBuilder; + use crate::build::CheckoutBuilder; + use crate::{ObjectType, Oid, Repository, ResetType}; use std::ffi::OsStr; use std::fs; use std::path::Path; use tempdir::TempDir; - use {ObjectType, Oid, Repository, ResetType}; #[test] fn smoke_init() { @@ -2545,10 +2541,10 @@ mod tests { assert!(!repo.is_shallow()); assert!(repo.is_empty().unwrap()); assert_eq!( - ::test::realpath(&repo.path()).unwrap(), - ::test::realpath(&td.path().join(".git/")).unwrap() + crate::test::realpath(&repo.path()).unwrap(), + crate::test::realpath(&td.path().join(".git/")).unwrap() ); - assert_eq!(repo.state(), ::RepositoryState::Clean); + assert_eq!(repo.state(), crate::RepositoryState::Clean); } #[test] @@ -2560,20 +2556,20 @@ mod tests { let repo = Repository::open(path).unwrap(); assert!(repo.is_bare()); assert_eq!( - ::test::realpath(&repo.path()).unwrap(), - ::test::realpath(&td.path().join("")).unwrap() + crate::test::realpath(&repo.path()).unwrap(), + crate::test::realpath(&td.path().join("")).unwrap() ); } #[test] fn smoke_checkout() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); repo.checkout_head(None).unwrap(); } #[test] fn smoke_revparse() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let rev = repo.revparse("HEAD").unwrap(); assert!(rev.to().is_none()); let from = rev.from().unwrap(); @@ -2602,8 +2598,8 @@ mod tests { Repository::init_bare(td.path()).unwrap(); let repo = Repository::discover(&subdir).unwrap(); assert_eq!( - ::test::realpath(&repo.path()).unwrap(), - ::test::realpath(&td.path().join("")).unwrap() + crate::test::realpath(&repo.path()).unwrap(), + crate::test::realpath(&td.path().join("")).unwrap() ); } @@ -2614,32 +2610,43 @@ mod tests { fs::create_dir(&subdir).unwrap(); Repository::init(td.path()).unwrap(); - let repo = Repository::open_ext(&subdir, ::RepositoryOpenFlags::empty(), &[] as &[&OsStr]) - .unwrap(); + let repo = Repository::open_ext( + &subdir, + crate::RepositoryOpenFlags::empty(), + &[] as &[&OsStr], + ) + .unwrap(); assert!(!repo.is_bare()); assert_eq!( - ::test::realpath(&repo.path()).unwrap(), - ::test::realpath(&td.path().join(".git")).unwrap() + crate::test::realpath(&repo.path()).unwrap(), + crate::test::realpath(&td.path().join(".git")).unwrap() ); let repo = - Repository::open_ext(&subdir, ::RepositoryOpenFlags::BARE, &[] as &[&OsStr]).unwrap(); + Repository::open_ext(&subdir, crate::RepositoryOpenFlags::BARE, &[] as &[&OsStr]) + .unwrap(); assert!(repo.is_bare()); assert_eq!( - ::test::realpath(&repo.path()).unwrap(), - ::test::realpath(&td.path().join(".git")).unwrap() + crate::test::realpath(&repo.path()).unwrap(), + crate::test::realpath(&td.path().join(".git")).unwrap() ); - let err = Repository::open_ext(&subdir, ::RepositoryOpenFlags::NO_SEARCH, &[] as &[&OsStr]) - .err() - .unwrap(); - assert_eq!(err.code(), ::ErrorCode::NotFound); + let err = Repository::open_ext( + &subdir, + crate::RepositoryOpenFlags::NO_SEARCH, + &[] as &[&OsStr], + ) + .err() + .unwrap(); + assert_eq!(err.code(), crate::ErrorCode::NotFound); - assert!(Repository::open_ext(&subdir, ::RepositoryOpenFlags::empty(), &[&subdir]).is_ok()); + assert!( + Repository::open_ext(&subdir, crate::RepositoryOpenFlags::empty(), &[&subdir]).is_ok() + ); } fn graph_repo_init() -> (TempDir, Repository) { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); { let head = repo.head().unwrap().target().unwrap(); let head = repo.find_commit(head).unwrap(); @@ -2683,7 +2690,7 @@ mod tests { #[test] fn smoke_reference_has_log_ensure_log() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); assert_eq!(repo.reference_has_log("HEAD").unwrap(), true); assert_eq!(repo.reference_has_log("refs/heads/master").unwrap(), true); @@ -2699,7 +2706,7 @@ mod tests { #[test] fn smoke_set_head() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); assert!(repo.set_head("refs/heads/does-not-exist").is_ok()); assert!(repo.head().is_err()); @@ -2712,7 +2719,7 @@ mod tests { #[test] fn smoke_set_head_detached() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let void_oid = Oid::from_bytes(b"00000000000000000000").unwrap(); assert!(repo.set_head_detached(void_oid).is_err()); diff --git a/src/revspec.rs b/src/revspec.rs index de6cf01076..120f83a359 100644 --- a/src/revspec.rs +++ b/src/revspec.rs @@ -1,4 +1,4 @@ -use {Object, RevparseMode}; +use crate::{Object, RevparseMode}; /// A revspec represents a range of revisions within a repository. pub struct Revspec<'repo> { diff --git a/src/revwalk.rs b/src/revwalk.rs index fe33fddab8..4afd36ed9f 100644 --- a/src/revwalk.rs +++ b/src/revwalk.rs @@ -2,8 +2,8 @@ use libc::c_uint; use std::ffi::CString; use std::marker; -use util::Binding; -use {raw, Error, Oid, Repository, Sort}; +use crate::util::Binding; +use crate::{raw, Error, Oid, Repository, Sort}; /// A revwalk allows traversal of the commit graph defined by including one or /// more leaves and excluding one or more roots. @@ -68,7 +68,7 @@ impl<'repo> Revwalk<'repo> { /// Any references matching this glob which do not point to a committish /// will be ignored. pub fn push_glob(&mut self, glob: &str) -> Result<(), Error> { - let glob = try!(CString::new(glob)); + let glob = CString::new(glob)?; unsafe { try_call!(raw::git_revwalk_push_glob(self.raw, glob)); } @@ -81,7 +81,7 @@ impl<'repo> Revwalk<'repo> { /// `` is in the form accepted by `revparse_single`. The left-hand /// commit will be hidden and the right-hand commit pushed. pub fn push_range(&mut self, range: &str) -> Result<(), Error> { - let range = try!(CString::new(range)); + let range = CString::new(range)?; unsafe { try_call!(raw::git_revwalk_push_range(self.raw, range)); } @@ -92,7 +92,7 @@ impl<'repo> Revwalk<'repo> { /// /// The reference must point to a committish. pub fn push_ref(&mut self, reference: &str) -> Result<(), Error> { - let reference = try!(CString::new(reference)); + let reference = CString::new(reference)?; unsafe { try_call!(raw::git_revwalk_push_ref(self.raw, reference)); } @@ -128,7 +128,7 @@ impl<'repo> Revwalk<'repo> { /// Any references matching this glob which do not point to a committish /// will be ignored. pub fn hide_glob(&mut self, glob: &str) -> Result<(), Error> { - let glob = try!(CString::new(glob)); + let glob = CString::new(glob)?; unsafe { try_call!(raw::git_revwalk_hide_glob(self.raw, glob)); } @@ -139,7 +139,7 @@ impl<'repo> Revwalk<'repo> { /// /// The reference must point to a committish. pub fn hide_ref(&mut self, reference: &str) -> Result<(), Error> { - let reference = try!(CString::new(reference)); + let reference = CString::new(reference)?; unsafe { try_call!(raw::git_revwalk_hide_ref(self.raw, reference)); } @@ -183,14 +183,14 @@ impl<'repo> Iterator for Revwalk<'repo> { mod tests { #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let head = repo.head().unwrap(); let target = head.target().unwrap(); let mut walk = repo.revwalk().unwrap(); walk.push(target).unwrap(); - let oids: Vec<::Oid> = walk.by_ref().collect::, _>>().unwrap(); + let oids: Vec = walk.by_ref().collect::, _>>().unwrap(); assert_eq!(oids.len(), 1); assert_eq!(oids[0], target); diff --git a/src/signature.rs b/src/signature.rs index a915b2dcb4..e0beaa60af 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -6,8 +6,8 @@ use std::mem; use std::ptr; use std::str; -use util::Binding; -use {raw, Error, Time}; +use crate::util::Binding; +use crate::{raw, Error, Time}; /// A Signature is used to indicate authorship of various actions throughout the /// library. @@ -29,10 +29,10 @@ impl<'a> Signature<'a> { /// /// See `new` for more information pub fn now(name: &str, email: &str) -> Result, Error> { - ::init(); + crate::init(); let mut ret = ptr::null_mut(); - let name = try!(CString::new(name)); - let email = try!(CString::new(email)); + let name = CString::new(name)?; + let email = CString::new(email)?; unsafe { try_call!(raw::git_signature_now(&mut ret, name, email)); Ok(Binding::from_raw(ret)) @@ -46,10 +46,10 @@ impl<'a> Signature<'a> { /// /// Returns error if either `name` or `email` contain angle brackets. pub fn new(name: &str, email: &str, time: &Time) -> Result, Error> { - ::init(); + crate::init(); let mut ret = ptr::null_mut(); - let name = try!(CString::new(name)); - let email = try!(CString::new(email)); + let name = CString::new(name)?; + let email = CString::new(email)?; unsafe { try_call!(raw::git_signature_new( &mut ret, @@ -71,7 +71,7 @@ impl<'a> Signature<'a> { /// Gets the name on the signature as a byte slice. pub fn name_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, (*self.raw).name).unwrap() } + unsafe { crate::opt_bytes(self, (*self.raw).name).unwrap() } } /// Gets the email on the signature. @@ -83,7 +83,7 @@ impl<'a> Signature<'a> { /// Gets the email on the signature as a byte slice. pub fn email_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, (*self.raw).email).unwrap() } + unsafe { crate::opt_bytes(self, (*self.raw).email).unwrap() } } /// Get the `when` of this signature. @@ -160,7 +160,7 @@ impl<'a> fmt::Display for Signature<'a> { #[cfg(test)] mod tests { - use {Signature, Time}; + use crate::{Signature, Time}; #[test] fn smoke() { diff --git a/src/stash.rs b/src/stash.rs index 6881f2d246..280d164132 100644 --- a/src/stash.rs +++ b/src/stash.rs @@ -1,9 +1,9 @@ -use build::CheckoutBuilder; +use crate::build::CheckoutBuilder; +use crate::util::Binding; +use crate::{panic, raw, Oid, StashApplyProgress}; use libc::{c_char, c_int, c_void, size_t}; use std::ffi::CStr; use std::mem; -use util::Binding; -use {panic, raw, Oid, StashApplyProgress}; /// Stash application progress notification function. /// @@ -151,12 +151,12 @@ extern "C" fn stash_apply_progress_cb( #[cfg(test)] mod tests { - use stash::StashApplyOptions; + use crate::stash::StashApplyOptions; + use crate::test::repo_init; + use crate::{Repository, StashFlags, Status}; use std::fs; use std::io::Write; use std::path::Path; - use test::repo_init; - use {Repository, StashFlags, Status}; fn make_stash(next: C) where diff --git a/src/status.rs b/src/status.rs index baef097eb5..4ea28be575 100644 --- a/src/status.rs +++ b/src/status.rs @@ -5,8 +5,8 @@ use std::mem; use std::ops::Range; use std::str; -use util::Binding; -use {raw, DiffDelta, IntoCString, Repository, Status}; +use crate::util::Binding; +use crate::{raw, DiffDelta, IntoCString, Repository, Status}; /// Options that can be provided to `repo.statuses()` to control how the status /// information is gathered. @@ -302,9 +302,9 @@ impl<'statuses> StatusEntry<'statuses> { pub fn path_bytes(&self) -> &[u8] { unsafe { if (*self.raw).head_to_index.is_null() { - ::opt_bytes(self, (*(*self.raw).index_to_workdir).old_file.path) + crate::opt_bytes(self, (*(*self.raw).index_to_workdir).old_file.path) } else { - ::opt_bytes(self, (*(*self.raw).head_to_index).old_file.path) + crate::opt_bytes(self, (*(*self.raw).head_to_index).old_file.path) } .unwrap() } @@ -358,15 +358,15 @@ mod tests { #[test] fn smoke() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); assert_eq!(repo.statuses(None).unwrap().len(), 0); File::create(&td.path().join("foo")).unwrap(); let statuses = repo.statuses(None).unwrap(); assert_eq!(statuses.iter().count(), 1); let status = statuses.iter().next().unwrap(); assert_eq!(status.path(), Some("foo")); - assert!(status.status().contains(::Status::WT_NEW)); - assert!(!status.status().contains(::Status::INDEX_NEW)); + assert!(status.status().contains(crate::Status::WT_NEW)); + assert!(!status.status().contains(crate::Status::INDEX_NEW)); assert!(status.head_to_index().is_none()); let diff = status.index_to_workdir().unwrap(); assert_eq!(diff.old_file().path_bytes().unwrap(), b"foo"); @@ -375,7 +375,7 @@ mod tests { #[test] fn filter() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); t!(File::create(&td.path().join("foo"))); t!(File::create(&td.path().join("bar"))); let mut opts = StatusOptions::new(); @@ -389,7 +389,7 @@ mod tests { #[test] fn gitignore() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); t!(t!(File::create(td.path().join(".gitignore"))).write_all(b"foo\n")); assert!(!t!(repo.status_should_ignore(Path::new("bar")))); assert!(t!(repo.status_should_ignore(Path::new("foo")))); @@ -397,7 +397,7 @@ mod tests { #[test] fn status_file() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); assert!(repo.status_file(Path::new("foo")).is_err()); if cfg!(windows) { assert!(repo.status_file(Path::new("bar\\foo.txt")).is_err()); @@ -408,10 +408,10 @@ mod tests { t!(File::create(td.path().join("bar").join("foo.txt"))); } let status = t!(repo.status_file(Path::new("foo"))); - assert!(status.contains(::Status::WT_NEW)); + assert!(status.contains(crate::Status::WT_NEW)); if cfg!(windows) { let status = t!(repo.status_file(Path::new("bar\\foo.txt"))); - assert!(status.contains(::Status::WT_NEW)); + assert!(status.contains(crate::Status::WT_NEW)); } } } diff --git a/src/string_array.rs b/src/string_array.rs index 8c23b0cb32..1bb40c24ea 100644 --- a/src/string_array.rs +++ b/src/string_array.rs @@ -3,8 +3,8 @@ use std::ops::Range; use std::str; -use raw; -use util::Binding; +use crate::raw; +use crate::util::Binding; /// A string array structure used by libgit2 /// @@ -38,7 +38,7 @@ impl StringArray { if i < self.raw.count as usize { unsafe { let ptr = *self.raw.strings.offset(i as isize) as *const _; - Some(::opt_bytes(self, ptr).unwrap()) + Some(crate::opt_bytes(self, ptr).unwrap()) } } else { None diff --git a/src/submodule.rs b/src/submodule.rs index 26e6224ea2..4112210405 100644 --- a/src/submodule.rs +++ b/src/submodule.rs @@ -5,9 +5,9 @@ use std::path::Path; use std::ptr; use std::str; -use build::CheckoutBuilder; -use util::{self, Binding}; -use {raw, Error, FetchOptions, Oid, Repository}; +use crate::build::CheckoutBuilder; +use crate::util::{self, Binding}; +use crate::{raw, Error, FetchOptions, Oid, Repository}; /// A structure to represent a git [submodule][1] /// @@ -30,7 +30,7 @@ impl<'repo> Submodule<'repo> { /// /// Returns `None` if the branch is not yet available. pub fn branch_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_submodule_branch(self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_submodule_branch(self.raw)) } } /// Get the submodule's url. @@ -53,7 +53,7 @@ impl<'repo> Submodule<'repo> { // TODO: delete this method and fix the signature of `url_bytes` on next // major version bump pub fn opt_url_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_submodule_url(self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_submodule_url(self.raw)) } } /// Get the submodule's name. @@ -65,12 +65,14 @@ impl<'repo> Submodule<'repo> { /// Get the name for the submodule. pub fn name_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_submodule_name(self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_submodule_name(self.raw)).unwrap() } } /// Get the path for the submodule. pub fn path(&self) -> &Path { - util::bytes2path(unsafe { ::opt_bytes(self, raw::git_submodule_path(self.raw)).unwrap() }) + util::bytes2path(unsafe { + crate::opt_bytes(self, raw::git_submodule_path(self.raw)).unwrap() + }) } /// Get the OID for the submodule in the current HEAD tree. @@ -282,8 +284,8 @@ mod tests { use tempdir::TempDir; use url::Url; - use Repository; - use SubmoduleUpdateOptions; + use crate::Repository; + use crate::SubmoduleUpdateOptions; #[test] fn smoke() { @@ -318,8 +320,8 @@ mod tests { #[test] fn add_a_submodule() { - let (_td, repo1) = ::test::repo_init(); - let (td, repo2) = ::test::repo_init(); + let (_td, repo1) = crate::test::repo_init(); + let (td, repo2) = crate::test::repo_init(); let url = Url::from_file_path(&repo1.workdir().unwrap()).unwrap(); let mut s = repo2 @@ -335,8 +337,8 @@ mod tests { fn update_submodule() { // ----------------------------------- // Same as `add_a_submodule()` - let (_td, repo1) = ::test::repo_init(); - let (td, repo2) = ::test::repo_init(); + let (_td, repo1) = crate::test::repo_init(); + let (td, repo2) = crate::test::repo_init(); let url = Url::from_file_path(&repo1.workdir().unwrap()).unwrap(); let mut s = repo2 diff --git a/src/tag.rs b/src/tag.rs index 2442a8b30a..5a02b43b26 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -3,8 +3,8 @@ use std::mem; use std::ptr; use std::str; -use util::Binding; -use {raw, signature, Error, Object, ObjectType, Oid, Signature}; +use crate::util::Binding; +use crate::{raw, signature, Error, Object, ObjectType, Oid, Signature}; /// A structure to represent a git [tag][1] /// @@ -31,7 +31,7 @@ impl<'repo> Tag<'repo> { /// /// Returns None if there is no message pub fn message_bytes(&self) -> Option<&[u8]> { - unsafe { ::opt_bytes(self, raw::git_tag_message(&*self.raw)) } + unsafe { crate::opt_bytes(self, raw::git_tag_message(&*self.raw)) } } /// Get the name of a tag @@ -43,7 +43,7 @@ impl<'repo> Tag<'repo> { /// Get the name of a tag pub fn name_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_tag_name(&*self.raw)).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_tag_name(&*self.raw)).unwrap() } } /// Recursively peel a tag until a non tag git_object is found @@ -103,8 +103,8 @@ impl<'repo> Tag<'repo> { } } -impl<'repo> ::std::fmt::Debug for Tag<'repo> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { +impl<'repo> std::fmt::Debug for Tag<'repo> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { let mut ds = f.debug_struct("Tag"); if let Some(name) = self.name() { ds.field("name", &name); @@ -143,7 +143,7 @@ impl<'repo> Drop for Tag<'repo> { mod tests { #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let head = repo.head().unwrap(); let id = head.target().unwrap(); assert!(repo.find_tag(id).is_err()); @@ -162,7 +162,7 @@ mod tests { assert_eq!(tag.message(), Some("msg")); assert_eq!(tag.peel().unwrap().id(), obj.id()); assert_eq!(tag.target_id(), obj.id()); - assert_eq!(tag.target_type(), Some(::ObjectType::Commit)); + assert_eq!(tag.target_type(), Some(crate::ObjectType::Commit)); assert_eq!(tag.tagger().unwrap().name(), sig.name()); tag.target().unwrap(); @@ -180,7 +180,7 @@ mod tests { #[test] fn lite() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let head = t!(repo.head()); let id = head.target().unwrap(); let obj = t!(repo.find_object(id, None)); diff --git a/src/test.rs b/src/test.rs index 5fed0a7882..6f885bd6f3 100644 --- a/src/test.rs +++ b/src/test.rs @@ -5,7 +5,7 @@ use std::ptr; use tempdir::TempDir; use url::Url; -use Repository; +use crate::Repository; macro_rules! t { ($e:expr) => { @@ -51,7 +51,7 @@ pub fn realpath(original: &Path) -> io::Result { fn realpath(name: *const c_char, resolved: *mut c_char) -> *mut c_char; } unsafe { - let cstr = try!(CString::new(original.as_os_str().as_bytes())); + let cstr = CString::new(original.as_os_str().as_bytes())?; let ptr = realpath(cstr.as_ptr(), ptr::null_mut()); if ptr.is_null() { return Err(io::Error::last_os_error()); diff --git a/src/time.rs b/src/time.rs index 69508e37e0..92dc0b36ff 100644 --- a/src/time.rs +++ b/src/time.rs @@ -2,8 +2,8 @@ use std::cmp::Ordering; use libc::{c_char, c_int}; -use raw; -use util::Binding; +use crate::raw; +use crate::util::Binding; /// Time in a signature #[derive(Copy, Clone, Eq, PartialEq)] diff --git a/src/transport.rs b/src/transport.rs index 53e2e13208..b19d764e9d 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -9,8 +9,8 @@ use std::ptr; use std::slice; use std::str; -use util::Binding; -use {panic, raw, Error, Remote}; +use crate::util::Binding; +use crate::{panic, raw, Error, Remote}; /// A transport is a structure which knows how to transfer data to and from a /// remote. @@ -107,11 +107,11 @@ pub unsafe fn register(prefix: &str, factory: F) -> Result<(), Error> where F: Fn(&Remote) -> Result + Send + Sync + 'static, { - ::init(); + crate::init(); let mut data = Box::new(TransportData { factory: Box::new(factory), }); - let prefix = try!(CString::new(prefix)); + let prefix = CString::new(prefix)?; let datap = (&mut *data) as *mut TransportData as *mut c_void; try_call!(raw::git_transport_register( prefix, diff --git a/src/tree.rs b/src/tree.rs index 02c46829fc..6035f63310 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -8,8 +8,8 @@ use std::path::Path; use std::ptr; use std::str; -use util::{c_cmp_to_ordering, Binding, IntoCString}; -use {panic, raw, Error, Object, ObjectType, Oid, Repository}; +use crate::util::{c_cmp_to_ordering, Binding, IntoCString}; +use crate::{panic, raw, Error, Object, ObjectType, Oid, Repository}; /// A structure to represent a git [tree][1] /// @@ -179,7 +179,7 @@ impl<'repo> Tree<'repo> { /// Retrieve a tree entry contained in a tree or in any of its subtrees, /// given its relative path. pub fn get_path(&self, path: &Path) -> Result, Error> { - let path = try!(path.into_c_string()); + let path = path.into_c_string()?; let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_tree_entry_bypath(&mut ret, &*self.raw(), path)); @@ -234,8 +234,8 @@ impl<'repo> Binding for Tree<'repo> { } } -impl<'repo> ::std::fmt::Debug for Tree<'repo> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { +impl<'repo> std::fmt::Debug for Tree<'repo> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { f.debug_struct("Tree").field("id", &self.id()).finish() } } @@ -287,7 +287,7 @@ impl<'tree> TreeEntry<'tree> { /// Get the filename of a tree entry pub fn name_bytes(&self) -> &[u8] { - unsafe { ::opt_bytes(self, raw::git_tree_entry_name(&*self.raw())).unwrap() } + unsafe { crate::opt_bytes(self, raw::git_tree_entry_name(&*self.raw())).unwrap() } } /// Convert a tree entry to the object it points to. @@ -399,11 +399,11 @@ impl<'tree> ExactSizeIterator for TreeIter<'tree> {} #[cfg(test)] mod tests { use super::{TreeWalkMode, TreeWalkResult}; + use crate::{Object, ObjectType, Repository, Tree, TreeEntry}; use std::fs::File; use std::io::prelude::*; use std::path::Path; use tempdir::TempDir; - use {Object, ObjectType, Repository, Tree, TreeEntry}; pub struct TestTreeIter<'a> { entries: Vec>, @@ -452,7 +452,7 @@ mod tests { #[test] fn smoke_tree_iter() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); setup_repo(&td, &repo); @@ -495,7 +495,7 @@ mod tests { #[test] fn smoke() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); setup_repo(&td, &repo); @@ -529,7 +529,7 @@ mod tests { #[test] fn tree_walk() { - let (td, repo) = ::test::repo_init(); + let (td, repo) = crate::test::repo_init(); setup_repo(&td, &repo); diff --git a/src/treebuilder.rs b/src/treebuilder.rs index 6eabf17f25..16f60123ce 100644 --- a/src/treebuilder.rs +++ b/src/treebuilder.rs @@ -3,8 +3,8 @@ use std::ptr; use libc::{c_int, c_void}; -use util::{Binding, IntoCString}; -use {panic, raw, tree, Error, Oid, Repository, TreeEntry}; +use crate::util::{Binding, IntoCString}; +use crate::{panic, raw, tree, Error, Oid, Repository, TreeEntry}; /// Constructor for in-memory trees pub struct TreeBuilder<'repo> { @@ -33,7 +33,7 @@ impl<'repo> TreeBuilder<'repo> { where P: IntoCString, { - let filename = try!(filename.into_c_string()); + let filename = filename.into_c_string()?; unsafe { let ret = raw::git_treebuilder_get(self.raw, filename.as_ptr()); if ret.is_null() { @@ -57,7 +57,7 @@ impl<'repo> TreeBuilder<'repo> { oid: Oid, filemode: i32, ) -> Result { - let filename = try!(filename.into_c_string()); + let filename = filename.into_c_string()?; let filemode = filemode as raw::git_filemode_t; let mut ret = ptr::null(); @@ -75,7 +75,7 @@ impl<'repo> TreeBuilder<'repo> { /// Remove an entry from the builder by its filename pub fn remove(&mut self, filename: P) -> Result<(), Error> { - let filename = try!(filename.into_c_string()); + let filename = filename.into_c_string()?; unsafe { try_call!(raw::git_treebuilder_remove(self.raw, filename)); } @@ -153,11 +153,11 @@ impl<'repo> Drop for TreeBuilder<'repo> { #[cfg(test)] mod tests { - use ObjectType; + use crate::ObjectType; #[test] fn smoke() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = repo.treebuilder(None).unwrap(); assert_eq!(builder.len(), 0); @@ -177,7 +177,7 @@ mod tests { #[test] fn write() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = repo.treebuilder(None).unwrap(); let data = repo.blob(b"data").unwrap(); @@ -196,7 +196,7 @@ mod tests { #[test] fn filter() { - let (_td, repo) = ::test::repo_init(); + let (_td, repo) = crate::test::repo_init(); let mut builder = repo.treebuilder(None).unwrap(); let blob = repo.blob(b"data").unwrap(); diff --git a/src/util.rs b/src/util.rs index cf135d9292..d2402fcc71 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,7 +4,7 @@ use std::ffi::{CString, OsStr, OsString}; use std::iter::IntoIterator; use std::path::{Path, PathBuf}; -use {raw, Error}; +use crate::{raw, Error}; #[doc(hidden)] pub trait IsNull { @@ -48,7 +48,10 @@ where T: IntoCString, I: IntoIterator, { - let cstrs: Vec<_> = try!(iter.into_iter().map(|i| i.into_c_string()).collect()); + let cstrs = iter + .into_iter() + .map(|i| i.into_c_string()) + .collect::, _>>()?; let ptrs = cstrs.iter().map(|i| i.as_ptr()).collect::>(); let raw = raw::git_strarray { strings: ptrs.as_ptr() as *mut _, @@ -85,13 +88,13 @@ impl<'a, T: IntoCString + Clone> IntoCString for &'a T { impl<'a> IntoCString for &'a str { fn into_c_string(self) -> Result { - Ok(try!(CString::new(self))) + Ok(CString::new(self)?) } } impl IntoCString for String { fn into_c_string(self) -> Result { - Ok(try!(CString::new(self.into_bytes()))) + Ok(CString::new(self.into_bytes())?) } } @@ -126,7 +129,7 @@ impl IntoCString for OsString { fn into_c_string(self) -> Result { use std::os::unix::prelude::*; let s: &OsStr = self.as_ref(); - Ok(try!(CString::new(s.as_bytes()))) + Ok(CString::new(s.as_bytes())?) } #[cfg(windows)] fn into_c_string(self) -> Result { @@ -142,13 +145,13 @@ impl IntoCString for OsString { impl<'a> IntoCString for &'a [u8] { fn into_c_string(self) -> Result { - Ok(try!(CString::new(self))) + Ok(CString::new(self)?) } } impl IntoCString for Vec { fn into_c_string(self) -> Result { - Ok(try!(CString::new(self))) + Ok(CString::new(self)?) } } @@ -158,7 +161,7 @@ where { match opt_s { None => Ok(None), - Some(s) => Ok(Some(try!(s.into_c_string()))), + Some(s) => Ok(Some(s.into_c_string()?)), } } diff --git a/systest/Cargo.toml b/systest/Cargo.toml index 3507d85e6d..a95c28fb85 100644 --- a/systest/Cargo.toml +++ b/systest/Cargo.toml @@ -3,6 +3,7 @@ name = "systest" version = "0.1.0" authors = ["Alex Crichton "] build = "build.rs" +edition = "2018" [dependencies] libgit2-sys = { path = "../libgit2-sys", features = ['https', 'ssh'] }