diff --git a/examples/cat-file.rs b/examples/cat-file.rs
index 6196b9bb9f..7c6da33a0e 100644
--- a/examples/cat-file.rs
+++ b/examples/cat-file.rs
@@ -89,7 +89,7 @@ fn show_commit(commit: &Commit) {
}
show_sig("author", Some(commit.author()));
show_sig("committer", Some(commit.committer()));
- if let Some(msg) = commit.message() {
+ if let Ok(msg) = commit.message() {
println!("\n{}", msg);
}
}
@@ -100,7 +100,7 @@ fn show_tag(tag: &Tag) {
println!("tag {}", tag.name().unwrap());
show_sig("tagger", tag.tagger());
- if let Some(msg) = tag.message() {
+ if let Ok(Some(msg)) = tag.message() {
println!("\n{}", msg);
}
}
diff --git a/examples/log.rs b/examples/log.rs
index 5f6fe0f210..22c7a5d785 100644
--- a/examples/log.rs
+++ b/examples/log.rs
@@ -176,7 +176,7 @@ fn run(args: &Args) -> Result<(), Error> {
if !sig_matches(&commit.committer(), &args.flag_committer) {
return None;
}
- if !log_message_matches(commit.message(), &args.flag_grep) {
+ if !log_message_matches(commit.message().ok(), &args.flag_grep) {
return None;
}
Some(Ok(commit))
diff --git a/examples/pull.rs b/examples/pull.rs
index 27f461e546..ac1b4b7e0e 100644
--- a/examples/pull.rs
+++ b/examples/pull.rs
@@ -56,7 +56,7 @@ fn do_fetch<'a>(
// Always fetch all tags.
// Perform a download and also update tips
fo.download_tags(git2::AutotagOption::All);
- println!("Fetching {} for repo", remote.name().unwrap());
+ println!("Fetching {} for repo", remote.name().unwrap().unwrap());
remote.fetch(refs, Some(&mut fo), None)?;
// If there are local objects (we got a thin pack), then tell the user
@@ -90,8 +90,8 @@ fn fast_forward(
rc: &git2::AnnotatedCommit,
) -> Result<(), git2::Error> {
let name = match lb.name() {
- Some(s) => s.to_string(),
- None => String::from_utf8_lossy(lb.name_bytes()).to_string(),
+ Ok(s) => s.to_string(),
+ Err(_) => String::from_utf8_lossy(lb.name_bytes()).to_string(),
};
let msg = format!("Fast-Forward: Setting {} to id: {}", name, rc.id());
println!("{}", msg);
diff --git a/examples/status.rs b/examples/status.rs
index 0ed61711c8..f64f0b38bd 100644
--- a/examples/status.rs
+++ b/examples/status.rs
@@ -134,7 +134,7 @@ fn show_branch(repo: &Repository, format: &Format) -> Result<(), Error> {
}
Err(e) => return Err(e),
};
- let head = head.as_ref().and_then(|h| h.shorthand());
+ let head = head.as_ref().and_then(|h| h.shorthand().ok());
if format == &Format::Long {
println!(
diff --git a/examples/tag.rs b/examples/tag.rs
index 5d2af02063..921863bee3 100644
--- a/examples/tag.rs
+++ b/examples/tag.rs
@@ -65,7 +65,7 @@ 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 repo.tag_names(Some(pattern))?.iter() {
- let name = name.unwrap();
+ let name = name.expect("Not invalid utf8").expect("Not None");
let obj = repo.revparse_single(name)?;
if let Some(tag) = obj.as_tag() {
@@ -83,7 +83,7 @@ fn run(args: &Args) -> Result<(), Error> {
fn print_tag(tag: &Tag, args: &Args) {
print!("{:<16}", tag.name().unwrap());
if args.flag_n.is_some() {
- print_list_lines(tag.message(), args);
+ print_list_lines(tag.message().unwrap(), args);
} else {
println!();
}
@@ -92,7 +92,7 @@ fn print_tag(tag: &Tag, args: &Args) {
fn print_commit(commit: &Commit, name: &str, args: &Args) {
print!("{:<16}", name);
if args.flag_n.is_some() {
- print_list_lines(commit.message(), args);
+ print_list_lines(commit.message().ok(), args);
} else {
println!();
}
diff --git a/src/blame.rs b/src/blame.rs
index 13f3294191..0034127495 100644
--- a/src/blame.rs
+++ b/src/blame.rs
@@ -186,10 +186,12 @@ impl<'blame> BlameHunk<'blame> {
/// The returned message is the summary of the commit, comprising the first
/// paragraph of the message with whitespace trimmed and squashed.
///
- /// `None` may be returned if an error occurs or if the summary is not valid
- /// utf-8.
- pub fn summary(&self) -> Option<&str> {
- self.summary_bytes().and_then(|s| str::from_utf8(s).ok())
+ /// `Ok(None)` may be returned if there is no summary.
+ pub fn summary(&self) -> Result