little cleanups

This commit is contained in:
Stephan Dilly 2020-10-25 15:43:13 +01:00
parent 9439114e5f
commit a2b26c30dc
8 changed files with 22 additions and 14 deletions

View file

@ -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"

View file

@ -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<String> {
@ -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(),
})
})

View file

@ -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 {

View file

@ -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,

View file

@ -163,6 +163,6 @@ impl ResetComponent {
};
}
("".to_string(), "".to_string())
(String::new(), String::new())
}
}

View file

@ -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),
),

View file

@ -14,13 +14,11 @@ pub struct LogEntry {
impl From<CommitInfo> 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,
}
}

View file

@ -231,7 +231,7 @@ fn get_modifier_hint(modifier: KeyModifiers) -> String {
KeyModifiers::ALT => {
"\u{2325}".to_string() //⌥
}
_ => "".to_string(),
_ => String::new(),
}
}