mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-02 09:28:40 +00:00
templater: host shortest_styled_prefix() by CommitOrChangeId
HighlightPrefix::extract() will be inlined by the next commit.
This commit is contained in:
parent
94b53575d8
commit
67eac2a455
1 changed files with 14 additions and 12 deletions
|
@ -507,6 +507,19 @@ impl CommitOrChangeId<'_> {
|
|||
format!("{prefix}[{rest}]")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shortest_styled_prefix(&self) -> IdWithHighlightedPrefix {
|
||||
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,
|
||||
);
|
||||
IdWithHighlightedPrefix {
|
||||
prefix: prefix.to_string(),
|
||||
rest: rest.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Template<()> for CommitOrChangeId<'_> {
|
||||
|
@ -578,18 +591,7 @@ impl TemplateProperty<CommitOrChangeId<'_>> for HighlightPrefix {
|
|||
type Output = IdWithHighlightedPrefix;
|
||||
|
||||
fn extract(&self, context: &CommitOrChangeId) -> Self::Output {
|
||||
let hex = context.hex();
|
||||
let (prefix, rest) = extract_entire_prefix_and_trimmed_tail(
|
||||
&hex,
|
||||
context
|
||||
.repo
|
||||
.shortest_unique_id_prefix_len(context.as_bytes()),
|
||||
12,
|
||||
);
|
||||
IdWithHighlightedPrefix {
|
||||
prefix: prefix.to_string(),
|
||||
rest: rest.to_string(),
|
||||
}
|
||||
context.shortest_styled_prefix()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue