Skip to content

Commit 396fd95

Browse files
committed
cli: rewrite get_git_hash_from_jj in a functional style
1 parent 28aad4e commit 396fd95

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

cli/build.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn get_git_hash_from_nix() -> Option<String> {
5757
}
5858

5959
fn get_git_hash_from_jj() -> Option<String> {
60-
if let Ok(output) = Command::new("jj")
60+
Command::new("jj")
6161
.args([
6262
"--ignore-working-copy",
6363
"--color=never",
@@ -67,17 +67,15 @@ fn get_git_hash_from_jj() -> Option<String> {
6767
"-T=commit_id ++ '-'",
6868
])
6969
.output()
70-
{
71-
if output.status.success() {
70+
.ok()
71+
.filter(|output| output.status.success())
72+
.map(|output| {
7273
let mut parent_commits = String::from_utf8(output.stdout).unwrap();
7374
// If a development version of `jj` is compiled at a merge commit, this will
7475
// result in several commit ids separated by `-`s.
7576
parent_commits.truncate(parent_commits.trim_end_matches('-').len());
76-
return Some(parent_commits);
77-
}
78-
}
79-
80-
None
77+
parent_commits
78+
})
8179
}
8280

8381
fn get_git_hash_from_git() -> Option<String> {

0 commit comments

Comments
 (0)