Skip to content

Commit 4ae3a82

Browse files
committed
Use if let on both author and commit message
Even more code taken from #1
1 parent cb090b9 commit 4ae3a82

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/main.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn main() -> Result<(), Box<Error>> {
119119
None => env::current_dir()?,
120120
};
121121
let verbose = opt.verbose;
122+
122123
let repo = Repository::open(&path)?;
123124
let commits = {
124125
let mut revwalk = repo.revwalk()?;
@@ -130,13 +131,13 @@ fn main() -> Result<(), Box<Error>> {
130131
}
131132
commits
132133
};
134+
133135
let mut repo = Repo::new(path.file_name().unwrap().to_str().unwrap());
134136
for commit in &commits {
135-
let commit_message = commit
136-
.message()
137-
.map(|msg| msg.to_lowercase())
138-
.expect("No commit message found");
139-
if let Some(author_name) = commit.author().name() {
137+
if let (Some(author_name), Some(commit_message)) = (
138+
commit.author().name(),
139+
commit.message().map(|w| w.to_lowercase()),
140+
) {
140141
let mut curses_added = 0;
141142
{
142143
let author = repo.author(author_name);
@@ -151,8 +152,14 @@ fn main() -> Result<(), Box<Error>> {
151152
}
152153
repo.total_commits += 1;
153154
repo.total_curses += curses_added;
155+
} else {
156+
eprintln!(
157+
"Skipping commit {:?} because either the commit author or message is missing",
158+
commit
159+
);
154160
}
155161
}
162+
156163
let end = Instant::now();
157164
if verbose {
158165
println!(
@@ -161,12 +168,14 @@ fn main() -> Result<(), Box<Error>> {
161168
repo.name
162169
);
163170
}
171+
164172
println!("{}", repo);
165173
for mut author in repo.authors.values() {
166174
if author.is_naughty() {
167175
println!("{}", author);
168176
}
169177
}
178+
170179
Ok(())
171180
}
172181

0 commit comments

Comments
 (0)