Skip to content

Commit

Permalink
Update with edition idioms.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jun 4, 2019
1 parent e39a0ac commit d327bb1
Show file tree
Hide file tree
Showing 52 changed files with 323 additions and 378 deletions.
8 changes: 2 additions & 6 deletions examples/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
#![deny(warnings)]
#![allow(trivial_casts)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::Repository;
use serde_derive::Deserialize;
use std::path::Path;

#[derive(Deserialize)]
Expand Down Expand Up @@ -71,7 +67,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: add [options] [--] [<spec>..]
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::{BlameOptions, Repository};
use serde_derive::Deserialize;
use std::io::{BufRead, BufReader};
use std::path::Path;

Expand Down Expand Up @@ -91,7 +87,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: blame [options] [<spec>] <path>
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/cat-file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use std::io::{self, Write};

use docopt::Docopt;
use git2::{Blob, Commit, ObjectType, Repository, Signature, Tag, Tree};
use serde_derive::Deserialize;

#[derive(Deserialize)]
struct Args {
Expand Down Expand Up @@ -132,7 +128,7 @@ fn show_sig(header: &str, sig: Option<Signature>) {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: cat-file (-t | -s | -e | -p) [options] <object>
Options:
Expand Down
12 changes: 4 additions & 8 deletions examples/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::build::{CheckoutBuilder, RepoBuilder};
use git2::{FetchOptions, Progress, RemoteCallbacks};
use serde_derive::Deserialize;
use std::cell::RefCell;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -52,7 +48,7 @@ fn print(state: &mut State) {
let kbytes = stats.received_bytes() / 1024;
if stats.received_objects() == stats.total_objects() {
if !state.newline {
println!("");
println!();
state.newline = true;
}
print!(
Expand Down Expand Up @@ -115,13 +111,13 @@ fn run(args: &Args) -> Result<(), git2::Error> {
.fetch_options(fo)
.with_checkout(co)
.clone(&args.arg_url, Path::new(&args.arg_path))?;
println!("");
println!();

Ok(())
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: add [options] <url> <path>
Options:
Expand Down
21 changes: 8 additions & 13 deletions examples/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use std::str;

use docopt::Docopt;
use git2::{Diff, DiffOptions, Error, Object, ObjectType, Repository};
use git2::{DiffFindOptions, DiffFormat};
use serde_derive::Deserialize;
use std::str;

#[derive(Deserialize)]
#[allow(non_snake_case)]
Expand Down Expand Up @@ -64,11 +59,11 @@ struct Args {
flag_git_dir: Option<String>,
}

const RESET: &'static str = "\u{1b}[m";
const BOLD: &'static str = "\u{1b}[1m";
const RED: &'static str = "\u{1b}[31m";
const GREEN: &'static str = "\u{1b}[32m";
const CYAN: &'static str = "\u{1b}[36m";
const RESET: &str = "\u{1b}[m";
const BOLD: &str = "\u{1b}[1m";
const RED: &str = "\u{1b}[31m";
const GREEN: &str = "\u{1b}[32m";
const CYAN: &str = "\u{1b}[36m";

#[derive(PartialEq, Eq, Copy, Clone)]
enum Cache {
Expand Down Expand Up @@ -267,7 +262,7 @@ impl Args {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: diff [options] [<from-oid> [<to-oid>]]
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::{AutotagOption, FetchOptions, RemoteCallbacks, Repository};
use serde_derive::Deserialize;
use std::io::{self, Write};
use std::str;

Expand Down Expand Up @@ -123,7 +119,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: fetch [options] [<remote>]
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::{Error, Repository, RepositoryInitMode, RepositoryInitOptions};
use serde_derive::Deserialize;
use std::path::{Path, PathBuf};

#[derive(Deserialize)]
Expand Down Expand Up @@ -129,7 +125,7 @@ fn parse_shared(shared: &str) -> Result<RepositoryInitMode, Error> {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: init [options] <directory>
Options:
Expand Down
9 changes: 2 additions & 7 deletions examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@

#![deny(warnings)]

#[macro_use]
extern crate serde_derive;
extern crate docopt;
extern crate git2;
extern crate time;

use docopt::Docopt;
use git2::{Commit, DiffOptions, ObjectType, Repository, Signature, Time};
use git2::{DiffFormat, Error, Pathspec};
use serde_derive::Deserialize;
use std::str;

#[derive(Deserialize)]
Expand Down Expand Up @@ -274,7 +269,7 @@ impl Args {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: log [options] [<commit>..] [--] [<spec>..]
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/ls-remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::{Direction, Repository};
use serde_derive::Deserialize;

#[derive(Deserialize)]
struct Args {
Expand All @@ -47,7 +43,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: ls-remote [option] <remote>
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/rev-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::{Error, Oid, Repository, Revwalk};
use serde_derive::Deserialize;

#[derive(Deserialize)]
struct Args {
Expand Down Expand Up @@ -93,7 +89,7 @@ fn push(revwalk: &mut Revwalk, id: Oid, hide: bool) -> Result<(), Error> {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: rev-list [options] [--] <spec>...
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/rev-parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::Repository;
use serde_derive::Deserialize;

#[derive(Deserialize)]
struct Args {
Expand Down Expand Up @@ -54,7 +50,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: rev-parse [options] <spec>
Options:
Expand Down
8 changes: 2 additions & 6 deletions examples/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::{Error, ErrorCode, Repository, StatusOptions, SubmoduleIgnore};
use serde_derive::Deserialize;
use std::str;
use std::time::Duration;

Expand Down Expand Up @@ -415,7 +411,7 @@ impl Args {
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage: status [options] [--] [<spec>..]
Options:
Expand Down
14 changes: 5 additions & 9 deletions examples/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

#![deny(warnings)]

extern crate docopt;
extern crate git2;
#[macro_use]
extern crate serde_derive;

use docopt::Docopt;
use git2::{Commit, Error, Repository, Tag};
use serde_derive::Deserialize;
use std::str;

#[derive(Deserialize)]
Expand Down Expand Up @@ -80,7 +76,7 @@ fn print_tag(tag: &Tag, args: &Args) {
if args.flag_n.is_some() {
print_list_lines(tag.message(), args);
} else {
println!("");
println!();
}
}

Expand All @@ -89,7 +85,7 @@ fn print_commit(commit: &Commit, name: &str, args: &Args) {
if args.flag_n.is_some() {
print_list_lines(commit.message(), args);
} else {
println!("");
println!();
}
}

Expand All @@ -106,15 +102,15 @@ fn print_list_lines(message: Option<&str>, args: &Args) {
if let Some(first) = lines.next() {
print!("{}", first);
}
println!("");
println!();

for line in lines.take(args.flag_n.unwrap_or(0) as usize) {
print!(" {}", line);
}
}

fn main() {
const USAGE: &'static str = "
const USAGE: &str = "
usage:
tag [-a] [-f] [-m <msg>] <tagname> [<object>]
tag -d <tag>
Expand Down
Loading

0 comments on commit d327bb1

Please sign in to comment.