Skip to content

Commit aff88f8

Browse files
committed
fix clippy
1 parent d33f2eb commit aff88f8

File tree

3 files changed

+71
-63
lines changed

3 files changed

+71
-63
lines changed

src/popups/branch_sort.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ impl BranchSortPopup {
4040
pub fn open(&mut self, sort_by: BranchListSortBy) -> Result<()> {
4141
self.show()?;
4242
self.update_sort_key(sort_by);
43-
44-
Ok(())
45-
}
46-
47-
fn is_visible(&self) -> bool {
48-
self.visible
49-
}
50-
51-
fn hide(&mut self) {
52-
self.visible = false;
53-
}
54-
55-
fn show(&mut self) -> Result<()> {
56-
self.visible = true;
5743
Ok(())
5844
}
5945

src/popups/branchlist.rs

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Component for BranchListPopup {
219219
strings::commands::sort_branch(&self.key_config),
220220
true,
221221
true,
222-
))
222+
));
223223
}
224224
visibility_blocking(self)
225225
}
@@ -315,7 +315,7 @@ impl Component for BranchListPopup {
315315
));
316316
} else if key_match(e, self.key_config.keys.branch_sort) {
317317
self.queue.push(InternalEvent::OpenBranchSortPopup(
318-
self.sort_by.clone(),
318+
self.sort_by,
319319
));
320320
}
321321
}
@@ -480,10 +480,10 @@ impl BranchListPopup {
480480
});
481481
}
482482
BranchListSortBy::BranchNameAsc => {
483-
self.branches.sort_by(|a, b| a.name.cmp(&b.name))
483+
self.branches.sort_by(|a, b| a.name.cmp(&b.name));
484484
}
485485
BranchListSortBy::BranchNameDesc => {
486-
self.branches.sort_by(|a, b| b.name.cmp(&a.name))
486+
self.branches.sort_by(|a, b| b.name.cmp(&a.name));
487487
}
488488
}
489489
//remove remote branch called `HEAD`
@@ -635,6 +635,46 @@ impl BranchListPopup {
635635
Ok(())
636636
}
637637

638+
const fn calculate_shared_commit_message_length(
639+
width_available: u16,
640+
three_dots_length: usize,
641+
) -> usize {
642+
const COMMIT_HASH_LENGTH: usize = 8;
643+
const COMMIT_DATE_LENGTH: usize = 11;
644+
const IS_HEAD_STAR_LENGTH: usize = 3;
645+
let branch_name_length: usize =
646+
width_available as usize * 40 / 100;
647+
648+
(width_available as usize)
649+
.saturating_sub(COMMIT_HASH_LENGTH)
650+
.saturating_sub(COMMIT_DATE_LENGTH)
651+
.saturating_sub(branch_name_length)
652+
.saturating_sub(IS_HEAD_STAR_LENGTH)
653+
.saturating_sub(three_dots_length)
654+
}
655+
656+
fn get_branch_name_text(
657+
branch_name_length: usize,
658+
displaybranch: &BranchInfo,
659+
three_dots_length: usize,
660+
three_dots: &str,
661+
) -> String {
662+
let mut branch_name = displaybranch.name.clone();
663+
if branch_name.len()
664+
> branch_name_length.saturating_sub(three_dots_length)
665+
{
666+
branch_name = branch_name
667+
.unicode_truncate(
668+
branch_name_length
669+
.saturating_sub(three_dots_length),
670+
)
671+
.0
672+
.to_string();
673+
branch_name += three_dots;
674+
}
675+
branch_name
676+
}
677+
638678
/// Get branches to display
639679
fn get_text(
640680
&self,
@@ -648,20 +688,15 @@ impl BranchListPopup {
648688
const EMPTY_SYMBOL: char = ' ';
649689
const THREE_DOTS: &str = "...";
650690
const THREE_DOTS_LENGTH: usize = THREE_DOTS.len(); // "..."
651-
const COMMIT_HASH_LENGTH: usize = 8;
652-
const COMMIT_DATE_LENGTH: usize = 11;
653-
const IS_HEAD_STAR_LENGTH: usize = 3; // "* "
654691

655692
let branch_name_length: usize =
656693
width_available as usize * 40 / 100;
657694
// commit message takes up the remaining width
658-
let mut commit_message_length: usize = (width_available
659-
as usize)
660-
.saturating_sub(COMMIT_HASH_LENGTH)
661-
.saturating_sub(COMMIT_DATE_LENGTH)
662-
.saturating_sub(branch_name_length)
663-
.saturating_sub(IS_HEAD_STAR_LENGTH)
664-
.saturating_sub(THREE_DOTS_LENGTH);
695+
let shared_commit_message_length: usize =
696+
Self::calculate_shared_commit_message_length(
697+
width_available,
698+
THREE_DOTS_LENGTH,
699+
);
665700
let mut txt = Vec::new();
666701

667702
for (i, displaybranch) in self
@@ -678,8 +713,7 @@ impl BranchListPopup {
678713
let author_text =
679714
displaybranch.top_commit_author.clone() + " ";
680715

681-
// commit_message_length contains author_text length
682-
commit_message_length = commit_message_length
716+
let commit_message_length = shared_commit_message_length
683717
.saturating_sub(author_text.len());
684718
let mut commit_message =
685719
displaybranch.top_commit_message.clone();
@@ -691,20 +725,12 @@ impl BranchListPopup {
691725
commit_message += THREE_DOTS;
692726
}
693727

694-
let mut branch_name = displaybranch.name.clone();
695-
if branch_name.len()
696-
> branch_name_length.saturating_sub(THREE_DOTS_LENGTH)
697-
{
698-
branch_name = branch_name
699-
.unicode_truncate(
700-
branch_name_length
701-
.saturating_sub(THREE_DOTS_LENGTH),
702-
)
703-
.0
704-
.to_string();
705-
branch_name += THREE_DOTS;
706-
}
707-
728+
let branch_name = Self::get_branch_name_text(
729+
branch_name_length,
730+
displaybranch,
731+
THREE_DOTS_LENGTH,
732+
THREE_DOTS,
733+
);
708734
let selected = (self.selection as usize
709735
- self.scroll.get_top())
710736
== i;
@@ -751,7 +777,6 @@ impl BranchListPopup {
751777
format!("{branch_name:branch_name_length$} "),
752778
theme.branch(selected, is_head),
753779
);
754-
755780
txt.push(Line::from(vec![
756781
span_prefix,
757782
span_name,
@@ -761,7 +786,6 @@ impl BranchListPopup {
761786
span_msg,
762787
]));
763788
}
764-
765789
Text::from(txt)
766790
}
767791

src/strings.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,56 +365,54 @@ pub fn rename_branch_popup_msg(
365365
}
366366

367367
pub fn sort_branch_by_name_msg(
368-
_key_config: &SharedKeyConfig,
368+
key_config: &SharedKeyConfig,
369369
) -> String {
370370
let hint =
371-
_key_config.get_hint(_key_config.keys.branch_sort_by_name);
371+
key_config.get_hint(key_config.keys.branch_sort_by_name);
372372
format!("{: <5}branch name (a -> z)", format!("[{}]", hint))
373-
.to_string()
374373
}
375374
pub fn sort_branch_by_name_rev_msg(
376-
_key_config: &SharedKeyConfig,
375+
key_config: &SharedKeyConfig,
377376
) -> String {
378-
let hint = _key_config
379-
.get_hint(_key_config.keys.branch_sort_by_name_rev);
377+
let hint =
378+
key_config.get_hint(key_config.keys.branch_sort_by_name_rev);
380379
format!("{: <5}branch name (z -> a)", format!("[{}]", hint))
381-
.to_string()
382380
}
383381
pub fn sort_branch_by_time_msg(
384-
_key_config: &SharedKeyConfig,
382+
key_config: &SharedKeyConfig,
385383
) -> String {
386384
let hint =
387-
_key_config.get_hint(_key_config.keys.branch_sort_by_time);
385+
key_config.get_hint(key_config.keys.branch_sort_by_time);
388386
format!(
389387
"{: <5}last commit time (new -> old)",
390388
format!("[{}]", hint)
391389
)
392390
}
393391
pub fn sort_branch_by_time_rev_msg(
394-
_key_config: &SharedKeyConfig,
392+
key_config: &SharedKeyConfig,
395393
) -> String {
396-
let hint = _key_config
397-
.get_hint(_key_config.keys.branch_sort_by_time_rev);
394+
let hint =
395+
key_config.get_hint(key_config.keys.branch_sort_by_time_rev);
398396
format!(
399397
"{: <5}last commit time (old -> new)",
400398
format!("[{}]", hint)
401399
)
402400
}
403401
pub fn sort_branch_by_author_msg(
404-
_key_config: &SharedKeyConfig,
402+
key_config: &SharedKeyConfig,
405403
) -> String {
406404
let hint =
407-
_key_config.get_hint(_key_config.keys.branch_sort_by_author);
405+
key_config.get_hint(key_config.keys.branch_sort_by_author);
408406
format!(
409407
"{: <5}last commit author (a -> z)",
410408
format!("[{}]", hint)
411409
)
412410
}
413411
pub fn sort_branch_by_author_rev_msg(
414-
_key_config: &SharedKeyConfig,
412+
key_config: &SharedKeyConfig,
415413
) -> String {
416-
let hint = _key_config
417-
.get_hint(_key_config.keys.branch_sort_by_author_rev);
414+
let hint = key_config
415+
.get_hint(key_config.keys.branch_sort_by_author_rev);
418416
format!(
419417
"{: <5}last commit author (z -> a)",
420418
format!("[{}]", hint)

0 commit comments

Comments
 (0)