mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
more idiomatic way
This commit is contained in:
parent
5966c05690
commit
7e33047232
1 changed files with 23 additions and 18 deletions
|
|
@ -51,26 +51,31 @@ pub fn get_branches_to_display(
|
|||
scope_time!("get_branches_to_display");
|
||||
|
||||
let cur_repo = utils::repo(repo_path)?;
|
||||
let mut branches_for_display = vec![];
|
||||
let branches_for_display = cur_repo
|
||||
.branches(Some(BranchType::Local))?
|
||||
.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);
|
||||
|
||||
for b in cur_repo.branches(Some(BranchType::Local))? {
|
||||
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);
|
||||
|
||||
branches_for_display.push(BranchForDisplay {
|
||||
name: String::from_utf8(Vec::from(branch.name_bytes()?))?,
|
||||
reference: String::from_utf8(Vec::from(
|
||||
branch.get().name_bytes(),
|
||||
))?,
|
||||
top_commit_message: String::from_utf8(Vec::from(
|
||||
top_commit.summary_bytes().unwrap_or_default(),
|
||||
))?,
|
||||
top_commit_reference: commit_id,
|
||||
is_head: branch.is_head(),
|
||||
Ok(BranchForDisplay {
|
||||
name: String::from_utf8(Vec::from(
|
||||
branch.name_bytes()?,
|
||||
))?,
|
||||
reference: String::from_utf8(Vec::from(
|
||||
branch.get().name_bytes(),
|
||||
))?,
|
||||
top_commit_message: String::from_utf8(Vec::from(
|
||||
top_commit.summary_bytes().unwrap_or_default(),
|
||||
))?,
|
||||
top_commit_reference: commit_id,
|
||||
is_head: branch.is_head(),
|
||||
})
|
||||
})
|
||||
}
|
||||
.filter_map(Result::ok)
|
||||
.collect();
|
||||
|
||||
Ok(branches_for_display)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue