From 665f7c5917bf014ff34a31592f5f4e70160999b1 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 14 Jan 2023 11:32:01 +0100 Subject: [PATCH] style: description template extractor This also prevents the creating of an extra empty String when the description is empty. --- src/templater.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/templater.rs b/src/templater.rs index eb07491c8..10fdd7dc3 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -15,7 +15,7 @@ use std::borrow::BorrowMut; use std::collections::{HashMap, HashSet}; use std::io; -use std::ops::{Add, AddAssign}; +use std::ops::AddAssign; use itertools::Itertools; use jujutsu_lib::backend::{ChangeId, CommitId, ObjectId, Signature, Timestamp}; @@ -166,13 +166,10 @@ pub struct DescriptionProperty; impl TemplateProperty for DescriptionProperty { fn extract(&self, context: &Commit) -> String { - let description = context.description().to_owned(); - if description.ends_with('\n') { - description - } else if description.is_empty() { - "(no description set)\n".to_string() - } else { - description.add("\n") + match context.description() { + s if s.is_empty() => "(no description set)\n".to_owned(), + s if s.ends_with('\n') => s.to_owned(), + s => format!("{s}\n"), } } }