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

templater: inline "current_working_copy" keyword

Maybe I didn't make this change before because the closure needs to capture
WorkspaceId by value. Since the inlined version looks pretty simple, let's
go forward to do that.
This commit is contained in:
Yuya Nishihara 2023-02-03 12:39:48 +09:00
parent edfa03f017
commit e2eda9f72f
2 changed files with 9 additions and 21 deletions

View file

@ -27,9 +27,9 @@ use thiserror::Error;
use crate::templater::{
BranchProperty, CommitOrChangeId, ConditionalTemplate, FormattablePropertyTemplate,
GitHeadProperty, GitRefsProperty, IdWithHighlightedPrefix, IsWorkingCopyProperty,
LabelTemplate, ListTemplate, Literal, PlainTextFormattedProperty, TagProperty, Template,
TemplateFunction, TemplateProperty, TemplatePropertyFn, WorkingCopiesProperty,
GitHeadProperty, GitRefsProperty, IdWithHighlightedPrefix, LabelTemplate, ListTemplate,
Literal, PlainTextFormattedProperty, TagProperty, Template, TemplateFunction, TemplateProperty,
TemplatePropertyFn, WorkingCopiesProperty,
};
use crate::{cli_util, time_util};
@ -419,10 +419,12 @@ fn parse_commit_keyword<'a>(
"author" => Property::Signature(wrap_fn(|commit| commit.author().clone())),
"committer" => Property::Signature(wrap_fn(|commit| commit.committer().clone())),
"working_copies" => Property::String(Box::new(WorkingCopiesProperty { repo })),
"current_working_copy" => Property::Boolean(Box::new(IsWorkingCopyProperty {
repo,
workspace_id: workspace_id.clone(),
})),
"current_working_copy" => {
let workspace_id = workspace_id.clone();
Property::Boolean(wrap_fn(move |commit| {
Some(commit.id()) == repo.view().get_wc_commit_id(&workspace_id)
}))
}
"branches" => Property::String(Box::new(BranchProperty { repo })),
"tags" => Property::String(Box::new(TagProperty { repo })),
"git_refs" => Property::String(Box::new(GitRefsProperty { repo })),

View file

@ -18,7 +18,6 @@ use std::io;
use itertools::Itertools;
use jujutsu_lib::backend::{ObjectId, Signature, Timestamp};
use jujutsu_lib::commit::Commit;
use jujutsu_lib::op_store::WorkspaceId;
use jujutsu_lib::repo::RepoRef;
use crate::formatter::{Formatter, PlainTextFormatter};
@ -220,19 +219,6 @@ impl TemplateProperty<Commit> for WorkingCopiesProperty<'_> {
}
}
pub struct IsWorkingCopyProperty<'a> {
pub repo: RepoRef<'a>,
pub workspace_id: WorkspaceId,
}
impl TemplateProperty<Commit> for IsWorkingCopyProperty<'_> {
type Output = bool;
fn extract(&self, context: &Commit) -> Self::Output {
Some(context.id()) == self.repo.view().get_wc_commit_id(&self.workspace_id)
}
}
pub struct BranchProperty<'a> {
pub repo: RepoRef<'a>,
}