forked from mirrors/jj
templater: inline capture variables in each method body of Commit type
Each method body will be turned into a closure.
This commit is contained in:
parent
e9243a7638
commit
0d77ce5ba9
1 changed files with 12 additions and 7 deletions
|
@ -243,8 +243,6 @@ fn build_commit_method<'repo>(
|
||||||
self_property: impl TemplateProperty<Commit, Output = Commit> + 'repo,
|
self_property: impl TemplateProperty<Commit, Output = Commit> + 'repo,
|
||||||
function: &FunctionCallNode,
|
function: &FunctionCallNode,
|
||||||
) -> TemplateParseResult<CommitTemplatePropertyKind<'repo>> {
|
) -> TemplateParseResult<CommitTemplatePropertyKind<'repo>> {
|
||||||
let repo = language.repo;
|
|
||||||
let cache = &language.keyword_cache;
|
|
||||||
let property = match function.name {
|
let property = match function.name {
|
||||||
"description" => {
|
"description" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
@ -284,12 +282,14 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"working_copies" => {
|
"working_copies" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
let repo = language.repo;
|
||||||
language.wrap_string(TemplateFunction::new(self_property, |commit| {
|
language.wrap_string(TemplateFunction::new(self_property, |commit| {
|
||||||
extract_working_copies(repo, &commit)
|
extract_working_copies(repo, &commit)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
"current_working_copy" => {
|
"current_working_copy" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
let repo = language.repo;
|
||||||
let workspace_id = language.workspace_id.clone();
|
let workspace_id = language.workspace_id.clone();
|
||||||
language.wrap_boolean(TemplateFunction::new(self_property, move |commit| {
|
language.wrap_boolean(TemplateFunction::new(self_property, move |commit| {
|
||||||
Some(commit.id()) == repo.view().get_wc_commit_id(&workspace_id)
|
Some(commit.id()) == repo.view().get_wc_commit_id(&workspace_id)
|
||||||
|
@ -297,7 +297,7 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"branches" => {
|
"branches" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
let index = cache.branches_index(repo).clone();
|
let index = language.keyword_cache.branches_index(language.repo).clone();
|
||||||
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
||||||
index
|
index
|
||||||
.get(commit.id())
|
.get(commit.id())
|
||||||
|
@ -309,7 +309,7 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"local_branches" => {
|
"local_branches" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
let index = cache.branches_index(repo).clone();
|
let index = language.keyword_cache.branches_index(language.repo).clone();
|
||||||
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
||||||
index
|
index
|
||||||
.get(commit.id())
|
.get(commit.id())
|
||||||
|
@ -321,7 +321,7 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"remote_branches" => {
|
"remote_branches" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
let index = cache.branches_index(repo).clone();
|
let index = language.keyword_cache.branches_index(language.repo).clone();
|
||||||
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
||||||
index
|
index
|
||||||
.get(commit.id())
|
.get(commit.id())
|
||||||
|
@ -333,26 +333,28 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"tags" => {
|
"tags" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
let index = cache.tags_index(repo).clone();
|
let index = language.keyword_cache.tags_index(language.repo).clone();
|
||||||
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
||||||
index.get(commit.id()).to_vec()
|
index.get(commit.id()).to_vec()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
"git_refs" => {
|
"git_refs" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
let index = cache.git_refs_index(repo).clone();
|
let index = language.keyword_cache.git_refs_index(language.repo).clone();
|
||||||
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
language.wrap_ref_name_list(TemplateFunction::new(self_property, move |commit| {
|
||||||
index.get(commit.id()).to_vec()
|
index.get(commit.id()).to_vec()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
"git_head" => {
|
"git_head" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
let repo = language.repo;
|
||||||
language.wrap_ref_name_list(TemplateFunction::new(self_property, |commit| {
|
language.wrap_ref_name_list(TemplateFunction::new(self_property, |commit| {
|
||||||
extract_git_head(repo, &commit)
|
extract_git_head(repo, &commit)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
"divergent" => {
|
"divergent" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
let repo = language.repo;
|
||||||
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
||||||
// The given commit could be hidden in e.g. obslog.
|
// The given commit could be hidden in e.g. obslog.
|
||||||
let maybe_entries = repo.resolve_change_id(commit.change_id());
|
let maybe_entries = repo.resolve_change_id(commit.change_id());
|
||||||
|
@ -361,6 +363,7 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"hidden" => {
|
"hidden" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
let repo = language.repo;
|
||||||
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
||||||
let maybe_entries = repo.resolve_change_id(commit.change_id());
|
let maybe_entries = repo.resolve_change_id(commit.change_id());
|
||||||
maybe_entries.map_or(true, |entries| !entries.contains(commit.id()))
|
maybe_entries.map_or(true, |entries| !entries.contains(commit.id()))
|
||||||
|
@ -374,6 +377,7 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"empty" => {
|
"empty" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
let repo = language.repo;
|
||||||
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
||||||
if let [parent] = &commit.parents()[..] {
|
if let [parent] = &commit.parents()[..] {
|
||||||
return parent.tree_id() == commit.tree_id();
|
return parent.tree_id() == commit.tree_id();
|
||||||
|
@ -384,6 +388,7 @@ fn build_commit_method<'repo>(
|
||||||
}
|
}
|
||||||
"root" => {
|
"root" => {
|
||||||
template_parser::expect_no_arguments(function)?;
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
let repo = language.repo;
|
||||||
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
language.wrap_boolean(TemplateFunction::new(self_property, |commit| {
|
||||||
commit.id() == repo.store().root_commit_id()
|
commit.id() == repo.store().root_commit_id()
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Reference in a new issue