diff --git a/src/template_parser.rs b/src/template_parser.rs index 1f893f8a9..b25afc215 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -485,10 +485,12 @@ fn parse_commit_or_change_id_method<'a, I: 'a>( }; let property = match name.as_str() { "short" => { - expect_no_arguments(args_pair)?; + let len_property = parse_optional_integer(args_pair)?; Property::String(chain_properties( - self_property, - TemplatePropertyFn(|id: &CommitOrChangeId| id.short()), + (self_property, len_property), + TemplatePropertyFn(|(id, len): &(CommitOrChangeId, Option)| { + id.short(len.and_then(|l| l.try_into().ok()).unwrap_or(12)) + }), )) } "shortest_prefix_and_brackets" => { diff --git a/src/templater.rs b/src/templater.rs index 7c56c7b09..04dc5c3b7 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -561,9 +561,9 @@ impl<'a> CommitOrChangeId<'a> { hex::encode(&self.id_bytes) } - pub fn short(&self) -> String { + pub fn short(&self, total_len: usize) -> String { let mut hex = self.hex(); - hex.truncate(12); + hex.truncate(total_len); hex }