forked from mirrors/jj
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}]")
|
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<'_> {
|
impl Template<()> for CommitOrChangeId<'_> {
|
||||||
|
@ -578,18 +591,7 @@ impl TemplateProperty<CommitOrChangeId<'_>> for HighlightPrefix {
|
||||||
type Output = IdWithHighlightedPrefix;
|
type Output = IdWithHighlightedPrefix;
|
||||||
|
|
||||||
fn extract(&self, context: &CommitOrChangeId) -> Self::Output {
|
fn extract(&self, context: &CommitOrChangeId) -> Self::Output {
|
||||||
let hex = context.hex();
|
context.shortest_styled_prefix()
|
||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue