cli/patch: Replace manual building table from iterator

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2025-09-07 12:51:28 +02:00 committed by Lorenz Leutgeb
parent 41a742ed9b
commit fb458537b4
1 changed files with 13 additions and 11 deletions

View File

@ -306,18 +306,20 @@ pub fn get_update_message(
/// List the given commits in a table.
pub fn list_commits(commits: &[git::raw::Commit]) -> anyhow::Result<()> {
let mut table = term::Table::default();
commits
.iter()
.map(|commit| {
let message = commit
.summary_bytes()
.unwrap_or_else(|| commit.message_bytes());
for commit in commits {
let message = commit
.summary_bytes()
.unwrap_or_else(|| commit.message_bytes());
table.push([
term::format::secondary(term::format::oid(commit.id()).into()),
term::format::italic(String::from_utf8_lossy(message).to_string()),
]);
}
table.print();
[
term::format::secondary(term::format::oid(commit.id()).into()),
term::format::italic(String::from_utf8_lossy(message).to_string()),
]
})
.collect::<term::Table<2, _>>()
.print();
Ok(())
}