From a2b26c30dcc93d2701645a2f5a9875abdf8906e7 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 25 Oct 2020 15:43:13 +0100 Subject: [PATCH] little cleanups --- asyncgit/Cargo.toml | 2 +- asyncgit/src/sync/branch.rs | 8 ++++---- asyncgit/src/sync/commits_info.rs | 5 +++++ src/components/push.rs | 5 +++-- src/components/reset.rs | 2 +- src/components/select_branch.rs | 8 ++++++-- src/components/utils/logitems.rs | 4 +--- src/keys.rs | 2 +- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/asyncgit/Cargo.toml b/asyncgit/Cargo.toml index 0ed233be..0dc5192a 100644 --- a/asyncgit/Cargo.toml +++ b/asyncgit/Cargo.toml @@ -18,7 +18,7 @@ rayon-core = "1.9" crossbeam-channel = "0.5" log = "0.4" thiserror = "1.0" -url = "2.1.1" +url = "2.1" [dev-dependencies] tempfile = "3.1" diff --git a/asyncgit/src/sync/branch.rs b/asyncgit/src/sync/branch.rs index 0b340376..d60ab809 100644 --- a/asyncgit/src/sync/branch.rs +++ b/asyncgit/src/sync/branch.rs @@ -8,6 +8,8 @@ use git2::BranchType; use scopetime::scope_time; use utils::get_head_repo; +use super::CommitId; + /// returns the branch-name head is currently pointing to /// this might be expensive, see `cached::BranchName` pub(crate) fn get_branch_name(repo_path: &str) -> Result { @@ -38,7 +40,7 @@ pub struct BranchForDisplay { /// pub top_commit_message: String, /// - pub top_commit_reference: String, + pub top_commit: CommitId, /// pub is_head: bool, } @@ -56,8 +58,6 @@ pub fn get_branches_to_display( .map(|b| { let branch = b?.0; let top_commit = branch.get().peel_to_commit()?; - let mut commit_id = top_commit.id().to_string(); - commit_id.truncate(7); Ok(BranchForDisplay { name: String::from_utf8(Vec::from( @@ -69,7 +69,7 @@ pub fn get_branches_to_display( top_commit_message: String::from_utf8(Vec::from( top_commit.summary_bytes().unwrap_or_default(), ))?, - top_commit_reference: commit_id, + top_commit: top_commit.id().into(), is_head: branch.is_head(), }) }) diff --git a/asyncgit/src/sync/commits_info.rs b/asyncgit/src/sync/commits_info.rs index bb02d574..75f5066d 100644 --- a/asyncgit/src/sync/commits_info.rs +++ b/asyncgit/src/sync/commits_info.rs @@ -17,6 +17,11 @@ impl CommitId { pub(crate) fn get_oid(self) -> Oid { self.0 } + + /// + pub fn get_short_string(&self) -> String { + self.to_string().chars().take(7).collect() + } } impl ToString for CommitId { diff --git a/src/components/push.rs b/src/components/push.rs index d1431c2a..ceaf334e 100644 --- a/src/components/push.rs +++ b/src/components/push.rs @@ -54,7 +54,7 @@ impl PushComponent { queue: queue.clone(), pending: false, visible: false, - branch: "".to_string(), + branch: String::new(), git_push: AsyncPush::new(sender), progress: None, input_cred: CredComponent::new( @@ -189,9 +189,10 @@ impl DrawableComponent for PushComponent { .border_style(self.theme.block(true)), ) .gauge_style( + //TODO: use theme Style::default() .fg(Color::White) - .bg(Color::Black), // .modifier(Modifier::ITALIC), + .bg(Color::Black), ) .percent(u16::from(progress)), area, diff --git a/src/components/reset.rs b/src/components/reset.rs index 35e47609..da275c59 100644 --- a/src/components/reset.rs +++ b/src/components/reset.rs @@ -163,6 +163,6 @@ impl ResetComponent { }; } - ("".to_string(), "".to_string()) + (String::new(), String::new()) } } diff --git a/src/components/select_branch.rs b/src/components/select_branch.rs index 7779da76..1ef99017 100644 --- a/src/components/select_branch.rs +++ b/src/components/select_branch.rs @@ -337,7 +337,9 @@ impl SelectBranchComponent { Span::styled( format!( "{} ", - displaybranch.top_commit_reference + displaybranch + .top_commit + .get_short_string() ), theme.commit_hash(true), ), @@ -363,7 +365,9 @@ impl SelectBranchComponent { Span::styled( format!( "{} ", - displaybranch.top_commit_reference + displaybranch + .top_commit + .get_short_string() ), theme.commit_hash(false), ), diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index 1dc2ec47..9fa26be0 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -14,13 +14,11 @@ pub struct LogEntry { impl From for LogEntry { fn from(c: CommitInfo) -> Self { - let hash = c.id.to_string().chars().take(7).collect(); - Self { author: c.author, msg: c.message, time: time_to_string(c.time, true), - hash_short: hash, + hash_short: c.id.get_short_string(), id: c.id, } } diff --git a/src/keys.rs b/src/keys.rs index c92501b6..8c2d640e 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -231,7 +231,7 @@ fn get_modifier_hint(modifier: KeyModifiers) -> String { KeyModifiers::ALT => { "\u{2325}".to_string() //⌥ } - _ => "".to_string(), + _ => String::new(), } }