Templater: Give short id function a total_len argument

This will be tested in the next commit.
This commit is contained in:
Ilya Grigoriev 2023-02-02 22:48:39 -08:00
parent 58828803d4
commit b87facff7a
2 changed files with 7 additions and 5 deletions

View file

@ -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<i64>)| {
id.short(len.and_then(|l| l.try_into().ok()).unwrap_or(12))
}),
))
}
"shortest_prefix_and_brackets" => {

View file

@ -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
}