From 79bd7b093fde6c282cccffd3397d4b0bc5f64e95 Mon Sep 17 00:00:00 2001 From: messense <messense@icloud.com> Date: Tue, 10 Jul 2018 11:02:23 +0800 Subject: [PATCH] Fix two crash --- src/modules/git.rs | 13 ++++++++----- src/modules/status.rs | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/modules/git.rs b/src/modules/git.rs index b1d98e4..5b68ce1 100644 --- a/src/modules/git.rs +++ b/src/modules/git.rs @@ -31,11 +31,14 @@ pub fn segment(segment: &mut Segment, _: &[&str]) { branch = head.shorthand().unwrap().to_owned(); let local = head.target().unwrap(); - let upstream = repo.find_branch(&branch, git2::BranchType::Local).unwrap(); - let upstream = upstream.upstream().unwrap().get().target().unwrap(); - - let (ahead, behind) = repo.graph_ahead_behind(local, upstream).unwrap(); - graph = icons::get("ahead").repeat(ahead) + &icons::get("behind").repeat(behind); + let local_branch = repo.find_branch(&branch, git2::BranchType::Local).unwrap(); + let upstream = local_branch.upstream(); + if let Ok(upstream) = upstream { + if let Some(upstream) = upstream.get().target() { + let (ahead, behind) = repo.graph_ahead_behind(local, upstream).unwrap(); + graph = icons::get("ahead").repeat(ahead) + &icons::get("behind").repeat(behind); + } + } } let mut modified = String::new(); diff --git a/src/modules/status.rs b/src/modules/status.rs index 94fbca0..2bdac8d 100644 --- a/src/modules/status.rs +++ b/src/modules/status.rs @@ -30,6 +30,8 @@ pub fn segment(segment: &mut Segment, _: &[&str]) { } if let Ok(jobs) = env::var("jobs") { - segment.value += &icons::get("job").repeat(usize::from_str_radix(&jobs, 10).unwrap()); + if let Ok(jobs_count) = usize::from_str_radix(jobs.trim(), 10) { + segment.value += &icons::get("job").repeat(jobs_count); + } } }