Skip to content

Commit e39a0ac

Browse files
committed
Update to 2018 edition.
1 parent 9f1f9d8 commit e39a0ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+699
-676
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ both threadsafe and memory safe and allows both reading and writing git
1414
repositories.
1515
"""
1616
categories = ["api-bindings"]
17+
edition = "2018"
1718

1819
[badges]
1920
travis-ci = { repository = "rust-lang/git2-rs" }

examples/add.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ struct Args {
3333
}
3434

3535
fn run(args: &Args) -> Result<(), git2::Error> {
36-
let repo = try!(Repository::open(&Path::new(".")));
37-
let mut index = try!(repo.index());
36+
let repo = Repository::open(&Path::new("."))?;
37+
let mut index = repo.index()?;
3838

3939
let cb = &mut |path: &Path, _matched_spec: &[u8]| -> i32 {
4040
let status = repo.status_file(path).unwrap();
@@ -61,12 +61,12 @@ fn run(args: &Args) -> Result<(), git2::Error> {
6161
};
6262

6363
if args.flag_update {
64-
try!(index.update_all(args.arg_spec.iter(), cb));
64+
index.update_all(args.arg_spec.iter(), cb)?;
6565
} else {
66-
try!(index.add_all(args.arg_spec.iter(), git2::IndexAddOption::DEFAULT, cb));
66+
index.add_all(args.arg_spec.iter(), git2::IndexAddOption::DEFAULT, cb)?;
6767
}
6868

69-
try!(index.write());
69+
index.write()?;
7070
Ok(())
7171
}
7272

examples/blame.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct Args {
3333
}
3434

3535
fn run(args: &Args) -> Result<(), git2::Error> {
36-
let repo = try!(Repository::open("."));
36+
let repo = Repository::open(".")?;
3737
let path = Path::new(&args.arg_path[..]);
3838

3939
// Prepare our blame options
@@ -46,7 +46,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
4646

4747
// Parse spec
4848
if let Some(spec) = args.arg_spec.as_ref() {
49-
let revspec = try!(repo.revparse(spec));
49+
let revspec = repo.revparse(spec)?;
5050

5151
let (oldest, newest) = if revspec.mode().contains(git2::RevparseMode::SINGLE) {
5252
(None, revspec.from())
@@ -69,9 +69,9 @@ fn run(args: &Args) -> Result<(), git2::Error> {
6969
}
7070

7171
let spec = format!("{}:{}", commit_id, path.display());
72-
let blame = try!(repo.blame_file(path, Some(&mut opts)));
73-
let object = try!(repo.revparse_single(&spec[..]));
74-
let blob = try!(repo.find_blob(object.id()));
72+
let blame = repo.blame_file(path, Some(&mut opts))?;
73+
let object = repo.revparse_single(&spec[..])?;
74+
let blob = repo.find_blob(object.id())?;
7575
let reader = BufReader::new(blob.content());
7676

7777
for (i, line) in reader.lines().enumerate() {

examples/cat-file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ struct Args {
3838

3939
fn run(args: &Args) -> Result<(), git2::Error> {
4040
let path = args.flag_git_dir.as_ref().map(|s| &s[..]).unwrap_or(".");
41-
let repo = try!(Repository::open(path));
41+
let repo = Repository::open(path)?;
4242

43-
let obj = try!(repo.revparse_single(&args.arg_object));
43+
let obj = repo.revparse_single(&args.arg_object)?;
4444
if args.flag_v && !args.flag_q {
4545
println!("{} {}\n--", obj.kind().unwrap().str(), obj.id());
4646
}

examples/clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ fn run(args: &Args) -> Result<(), git2::Error> {
111111

112112
let mut fo = FetchOptions::new();
113113
fo.remote_callbacks(cb);
114-
try!(RepoBuilder::new()
114+
RepoBuilder::new()
115115
.fetch_options(fo)
116116
.with_checkout(co)
117-
.clone(&args.arg_url, Path::new(&args.arg_path)));
117+
.clone(&args.arg_url, Path::new(&args.arg_path))?;
118118
println!("");
119119

120120
Ok(())

examples/diff.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ enum Cache {
7979

8080
fn run(args: &Args) -> Result<(), Error> {
8181
let path = args.flag_git_dir.as_ref().map(|s| &s[..]).unwrap_or(".");
82-
let repo = try!(Repository::open(path));
82+
let repo = Repository::open(path)?;
8383

8484
// Prepare our diff options based on the arguments given
8585
let mut opts = DiffOptions::new();
@@ -112,25 +112,25 @@ fn run(args: &Args) -> Result<(), Error> {
112112
}
113113

114114
// Prepare the diff to inspect
115-
let t1 = try!(tree_to_treeish(&repo, args.arg_from_oid.as_ref()));
116-
let t2 = try!(tree_to_treeish(&repo, args.arg_to_oid.as_ref()));
117-
let head = try!(tree_to_treeish(&repo, Some(&"HEAD".to_string()))).unwrap();
115+
let t1 = tree_to_treeish(&repo, args.arg_from_oid.as_ref())?;
116+
let t2 = tree_to_treeish(&repo, args.arg_to_oid.as_ref())?;
117+
let head = tree_to_treeish(&repo, Some(&"HEAD".to_string()))?.unwrap();
118118
let mut diff = match (t1, t2, args.cache()) {
119119
(Some(t1), Some(t2), _) => {
120-
try!(repo.diff_tree_to_tree(t1.as_tree(), t2.as_tree(), Some(&mut opts)))
120+
repo.diff_tree_to_tree(t1.as_tree(), t2.as_tree(), Some(&mut opts))?
121121
}
122122
(t1, None, Cache::None) => {
123123
let t1 = t1.unwrap_or(head);
124-
try!(repo.diff_tree_to_workdir(t1.as_tree(), Some(&mut opts)))
124+
repo.diff_tree_to_workdir(t1.as_tree(), Some(&mut opts))?
125125
}
126126
(t1, None, Cache::Only) => {
127127
let t1 = t1.unwrap_or(head);
128-
try!(repo.diff_tree_to_index(t1.as_tree(), None, Some(&mut opts)))
128+
repo.diff_tree_to_index(t1.as_tree(), None, Some(&mut opts))?
129129
}
130130
(Some(t1), None, _) => {
131-
try!(repo.diff_tree_to_workdir_with_index(t1.as_tree(), Some(&mut opts)))
131+
repo.diff_tree_to_workdir_with_index(t1.as_tree(), Some(&mut opts))?
132132
}
133-
(None, None, _) => try!(repo.diff_index_to_workdir(None, Some(&mut opts))),
133+
(None, None, _) => repo.diff_index_to_workdir(None, Some(&mut opts))?,
134134
(None, Some(_), _) => unreachable!(),
135135
};
136136

@@ -151,20 +151,20 @@ fn run(args: &Args) -> Result<(), Error> {
151151
}
152152
opts.copies_from_unmodified(args.flag_find_copies_harder)
153153
.rewrites(args.flag_break_rewrites);
154-
try!(diff.find_similar(Some(&mut opts)));
154+
diff.find_similar(Some(&mut opts))?;
155155
}
156156

157157
// Generate simple output
158158
let stats = args.flag_stat | args.flag_numstat | args.flag_shortstat | args.flag_summary;
159159
if stats {
160-
try!(print_stats(&diff, args));
160+
print_stats(&diff, args)?;
161161
}
162162
if args.flag_patch || !stats {
163163
if args.color() {
164164
print!("{}", RESET);
165165
}
166166
let mut last_color = None;
167-
try!(diff.print(args.diff_format(), |_delta, _hunk, line| {
167+
diff.print(args.diff_format(), |_delta, _hunk, line| {
168168
if args.color() {
169169
let next = match line.origin() {
170170
'+' => Some(GREEN),
@@ -190,7 +190,7 @@ fn run(args: &Args) -> Result<(), Error> {
190190
}
191191
print!("{}", str::from_utf8(line.content()).unwrap());
192192
true
193-
}));
193+
})?;
194194
if args.color() {
195195
print!("{}", RESET);
196196
}
@@ -200,7 +200,7 @@ fn run(args: &Args) -> Result<(), Error> {
200200
}
201201

202202
fn print_stats(diff: &Diff, args: &Args) -> Result<(), Error> {
203-
let stats = try!(diff.stats());
203+
let stats = diff.stats()?;
204204
let mut format = git2::DiffStatsFormat::NONE;
205205
if args.flag_stat {
206206
format |= git2::DiffStatsFormat::FULL;
@@ -214,7 +214,7 @@ fn print_stats(diff: &Diff, args: &Args) -> Result<(), Error> {
214214
if args.flag_summary {
215215
format |= git2::DiffStatsFormat::INCLUDE_SUMMARY;
216216
}
217-
let buf = try!(stats.to_buf(format, 80));
217+
let buf = stats.to_buf(format, 80)?;
218218
print!("{}", str::from_utf8(&*buf).unwrap());
219219
Ok(())
220220
}
@@ -227,8 +227,8 @@ fn tree_to_treeish<'a>(
227227
Some(s) => s,
228228
None => return Ok(None),
229229
};
230-
let obj = try!(repo.revparse_single(arg));
231-
let tree = try!(obj.peel(ObjectType::Tree));
230+
let obj = repo.revparse_single(arg)?;
231+
let tree = obj.peel(ObjectType::Tree)?;
232232
Ok(Some(tree))
233233
}
234234

examples/fetch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ struct Args {
3030
}
3131

3232
fn run(args: &Args) -> Result<(), git2::Error> {
33-
let repo = try!(Repository::open("."));
33+
let repo = Repository::open(".")?;
3434
let remote = args.arg_remote.as_ref().map(|s| &s[..]).unwrap_or("origin");
3535

3636
// Figure out whether it's a named remote or a URL
3737
println!("Fetching {} for repo", remote);
3838
let mut cb = RemoteCallbacks::new();
39-
let mut remote = try!(repo
39+
let mut remote = repo
4040
.find_remote(remote)
41-
.or_else(|_| { repo.remote_anonymous(remote) }));
41+
.or_else(|_| repo.remote_anonymous(remote))?;
4242
cb.sideband_progress(|data| {
4343
print!("remote: {}", str::from_utf8(data).unwrap());
4444
io::stdout().flush().unwrap();
@@ -85,7 +85,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
8585
// progress.
8686
let mut fo = FetchOptions::new();
8787
fo.remote_callbacks(cb);
88-
try!(remote.download(&[], Some(&mut fo)));
88+
remote.download(&[], Some(&mut fo))?;
8989

9090
{
9191
// 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> {
117117
// commits. This may be needed even if there was no packfile to download,
118118
// which can happen e.g. when the branches have been changed but all the
119119
// needed objects are available locally.
120-
try!(remote.update_tips(None, true, AutotagOption::Unspecified, None));
120+
remote.update_tips(None, true, AutotagOption::Unspecified, None)?;
121121

122122
Ok(())
123123
}

examples/init.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn run(args: &Args) -> Result<(), Error> {
4141
&& args.flag_shared.is_none()
4242
&& args.flag_separate_git_dir.is_none()
4343
{
44-
try!(Repository::init(&path))
44+
Repository::init(&path)?
4545
} else {
4646
let mut opts = RepositoryInitOptions::new();
4747
opts.bare(args.flag_bare);
@@ -58,9 +58,9 @@ fn run(args: &Args) -> Result<(), Error> {
5858
}
5959

6060
if let Some(ref s) = args.flag_shared {
61-
opts.mode(try!(parse_shared(s)));
61+
opts.mode(parse_shared(s)?);
6262
}
63-
try!(Repository::init_opts(&path, &opts))
63+
Repository::init_opts(&path, &opts)?
6464
};
6565

6666
// Print a message to stdout like "git init" does
@@ -74,7 +74,7 @@ fn run(args: &Args) -> Result<(), Error> {
7474
}
7575

7676
if args.flag_initial_commit {
77-
try!(create_initial_commit(&repo));
77+
create_initial_commit(&repo)?;
7878
println!("Created empty initial commit");
7979
}
8080

@@ -85,27 +85,27 @@ fn run(args: &Args) -> Result<(), Error> {
8585
/// commit in the repository. This is the helper function that does that.
8686
fn create_initial_commit(repo: &Repository) -> Result<(), Error> {
8787
// First use the config to initialize a commit signature for the user.
88-
let sig = try!(repo.signature());
88+
let sig = repo.signature()?;
8989

9090
// Now let's create an empty tree for this commit
9191
let tree_id = {
92-
let mut index = try!(repo.index());
92+
let mut index = repo.index()?;
9393

9494
// Outside of this example, you could call index.add_path()
9595
// here to put actual files into the index. For our purposes, we'll
9696
// leave it empty for now.
9797

98-
try!(index.write_tree())
98+
index.write_tree()?
9999
};
100100

101-
let tree = try!(repo.find_tree(tree_id));
101+
let tree = repo.find_tree(tree_id)?;
102102

103103
// Ready to create the initial commit.
104104
//
105105
// Normally creating a commit would involve looking up the current HEAD
106106
// commit and making that be the parent of the initial commit, but here this
107107
// is the first commit so there will be no parent.
108-
try!(repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[]));
108+
repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[])?;
109109

110110
Ok(())
111111
}

examples/ls-remote.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ struct Args {
2828
}
2929

3030
fn run(args: &Args) -> Result<(), git2::Error> {
31-
let repo = try!(Repository::open("."));
31+
let repo = Repository::open(".")?;
3232
let remote = &args.arg_remote;
33-
let mut remote = try!(repo
33+
let mut remote = repo
3434
.find_remote(remote)
35-
.or_else(|_| { repo.remote_anonymous(remote) }));
35+
.or_else(|_| repo.remote_anonymous(remote))?;
3636

3737
// Connect to the remote and call the printing function for each of the
3838
// remote references.
39-
let connection = try!(remote.connect_auth(Direction::Fetch, None, None));
39+
let connection = remote.connect_auth(Direction::Fetch, None, None)?;
4040

4141
// Get the list of references on the remote and print out their name next to
4242
// what they point to.
43-
for head in try!(connection.list()).iter() {
43+
for head in connection.list()?.iter() {
4444
println!("{}\t{}", head.oid(), head.name());
4545
}
4646
Ok(())

examples/rev-list.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ struct Args {
3333
}
3434

3535
fn run(args: &Args) -> Result<(), git2::Error> {
36-
let repo = try!(Repository::open("."));
37-
let mut revwalk = try!(repo.revwalk());
36+
let repo = Repository::open(".")?;
37+
let mut revwalk = repo.revwalk()?;
3838

3939
let base = if args.flag_reverse {
4040
git2::Sort::REVERSE
@@ -65,20 +65,20 @@ fn run(args: &Args) -> Result<(), git2::Error> {
6565
});
6666
for (spec, hide) in specs {
6767
let id = if spec.contains("..") {
68-
let revspec = try!(repo.revparse(spec));
68+
let revspec = repo.revparse(spec)?;
6969
if revspec.mode().contains(git2::RevparseMode::MERGE_BASE) {
7070
return Err(Error::from_str("merge bases not implemented"));
7171
}
72-
try!(push(&mut revwalk, revspec.from().unwrap().id(), !hide));
72+
push(&mut revwalk, revspec.from().unwrap().id(), !hide)?;
7373
revspec.to().unwrap().id()
7474
} else {
75-
try!(repo.revparse_single(spec)).id()
75+
repo.revparse_single(spec)?.id()
7676
};
77-
try!(push(&mut revwalk, id, hide));
77+
push(&mut revwalk, id, hide)?;
7878
}
7979

8080
for id in revwalk {
81-
let id = try!(id);
81+
let id = id?;
8282
println!("{}", id);
8383
}
8484
Ok(())

examples/rev-parse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ struct Args {
3030

3131
fn run(args: &Args) -> Result<(), git2::Error> {
3232
let path = args.flag_git_dir.as_ref().map(|s| &s[..]).unwrap_or(".");
33-
let repo = try!(Repository::open(path));
33+
let repo = Repository::open(path)?;
3434

35-
let revspec = try!(repo.revparse(&args.arg_spec));
35+
let revspec = repo.revparse(&args.arg_spec)?;
3636

3737
if revspec.mode().contains(git2::RevparseMode::SINGLE) {
3838
println!("{}", revspec.from().unwrap().id());
@@ -42,7 +42,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
4242
println!("{}", to.id());
4343

4444
if revspec.mode().contains(git2::RevparseMode::MERGE_BASE) {
45-
let base = try!(repo.merge_base(from.id(), to.id()));
45+
let base = repo.merge_base(from.id(), to.id())?;
4646
println!("{}", base);
4747
}
4848

0 commit comments

Comments
 (0)