ok/jj
1
0
Fork 0
forked from mirrors/jj

Templater: Inline highlight_shortest_prefix_brackets

This commit is contained in:
Ilya Grigoriev 2023-01-28 18:54:34 -08:00
parent 3ee87aa5a7
commit bd37989b63

View file

@ -494,8 +494,18 @@ impl CommitOrChangeId<'_> {
hex hex
} }
pub fn shortest_prefix_and_brackets(&self) -> String { fn shortest_prefix_and_brackets(&self) -> String {
highlight_shortest_prefix_brackets(self, 12) let hex = self.hex();
let (prefix, rest) = extract_entire_prefix_and_trimmed_tail(
&hex,
self.repo.shortest_unique_id_prefix_len(self.as_bytes()),
12 - 2,
);
if rest.is_empty() {
prefix.to_string()
} else {
format!("{prefix}[{rest}]")
}
} }
} }
@ -551,20 +561,6 @@ mod tests {
} }
} }
fn highlight_shortest_prefix_brackets(id: &CommitOrChangeId, total_len: usize) -> String {
let hex = id.hex();
let (prefix, rest) = extract_entire_prefix_and_trimmed_tail(
&hex,
id.repo.shortest_unique_id_prefix_len(id.as_bytes()),
total_len - 2,
);
if rest.is_empty() {
prefix.to_string()
} else {
format!("{prefix}[{rest}]")
}
}
pub struct CommitOrChangeIdShort; pub struct CommitOrChangeIdShort;
impl TemplateProperty<CommitOrChangeId<'_>> for CommitOrChangeIdShort { impl TemplateProperty<CommitOrChangeId<'_>> for CommitOrChangeIdShort {