mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 10:07:28 +00:00
templater: replace is_git_head
keyword by git_head
keyword
I'm about to make it possible for `HEAD@git` to be conflicted. For that, we need to be able to include the trailing `?`. This patch prepares for that.
This commit is contained in:
parent
23fc849574
commit
6cf7d98465
4 changed files with 15 additions and 11 deletions
|
@ -1391,7 +1391,7 @@ fn log_template(settings: &UserSettings) -> String {
|
|||
if(branches, " " branches)
|
||||
if(tags, " " tags)
|
||||
if(working_copies, " " working_copies)
|
||||
if(is_git_head, label("git_head", " HEAD@git"))
|
||||
if(git_head, " " git_head)
|
||||
" " commit_id.{prefix_format}
|
||||
if(conflict, label("conflict", " conflict"))
|
||||
"\n"
|
||||
|
|
|
@ -26,8 +26,8 @@ use crate::templater::{
|
|||
AuthorProperty, BranchProperty, ChangeIdProperty, CommitIdProperty, CommitOrChangeId,
|
||||
CommitOrChangeIdShort, CommitOrChangeIdShortPrefixAndBrackets, CommitterProperty,
|
||||
ConditionalTemplate, ConflictProperty, DescriptionProperty, DivergentProperty,
|
||||
DynamicLabelTemplate, EmptyProperty, FormattablePropertyTemplate, GitRefsProperty,
|
||||
IsGitHeadProperty, IsWorkingCopyProperty, LabelTemplate, ListTemplate, Literal,
|
||||
DynamicLabelTemplate, EmptyProperty, FormattablePropertyTemplate, GitHeadProperty,
|
||||
GitRefsProperty, IsWorkingCopyProperty, LabelTemplate, ListTemplate, Literal,
|
||||
SignatureTimestamp, TagProperty, Template, TemplateFunction, TemplateProperty,
|
||||
WorkingCopiesProperty,
|
||||
};
|
||||
|
@ -239,7 +239,7 @@ fn parse_commit_keyword<'a>(
|
|||
"branches" => Property::String(Box::new(BranchProperty { repo })),
|
||||
"tags" => Property::String(Box::new(TagProperty { repo })),
|
||||
"git_refs" => Property::String(Box::new(GitRefsProperty { repo })),
|
||||
"is_git_head" => Property::Boolean(Box::new(IsGitHeadProperty::new(repo))),
|
||||
"git_head" => Property::String(Box::new(GitHeadProperty::new(repo))),
|
||||
"divergent" => Property::Boolean(Box::new(DivergentProperty::new(repo))),
|
||||
"conflict" => Property::Boolean(Box::new(ConflictProperty)),
|
||||
"empty" => Property::Boolean(Box::new(EmptyProperty { repo })),
|
||||
|
|
|
@ -348,21 +348,25 @@ impl TemplateProperty<Commit> for GitRefsProperty<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct IsGitHeadProperty<'a> {
|
||||
pub struct GitHeadProperty<'a> {
|
||||
repo: RepoRef<'a>,
|
||||
}
|
||||
|
||||
impl<'a> IsGitHeadProperty<'a> {
|
||||
impl<'a> GitHeadProperty<'a> {
|
||||
pub fn new(repo: RepoRef<'a>) -> Self {
|
||||
Self { repo }
|
||||
}
|
||||
}
|
||||
|
||||
impl TemplateProperty<Commit> for IsGitHeadProperty<'_> {
|
||||
type Output = bool;
|
||||
impl TemplateProperty<Commit> for GitHeadProperty<'_> {
|
||||
type Output = String;
|
||||
|
||||
fn extract(&self, context: &Commit) -> Self::Output {
|
||||
self.repo.view().git_head().as_ref() == Some(context.id())
|
||||
fn extract(&self, context: &Commit) -> String {
|
||||
if self.repo.view().git_head().as_ref() == Some(context.id()) {
|
||||
"HEAD@git".to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ fn test_log_git_head() {
|
|||
insta::assert_snapshot!(stdout, @r###"
|
||||
@ [1m[38;5;13m8[e4fac809c][39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;12m5[0aaf4754c][39m[0m
|
||||
| [1minitial[0m
|
||||
o [38;5;5m9[a45c67d3e][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:07.000 +07:00[39m [38;5;5mmaster[39m[38;5;5m HEAD@git[39m [38;5;4m23[0dd059e1][39m
|
||||
o [38;5;5m9[a45c67d3e][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:07.000 +07:00[39m [38;5;5mmaster[39m [38;5;5mHEAD@git[39m [38;5;4m23[0dd059e1][39m
|
||||
| [38;5;2m(empty) [39m(no description set)
|
||||
o [38;5;5m0[000000000][39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m0[000000000][39m
|
||||
[38;5;2m(empty) [39m(no description set)
|
||||
|
|
Loading…
Reference in a new issue