Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit_templater: make various attributes accessible to extensions #3213

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

torquestomp
Copy link
Contributor

Ideally I also want to make the caching functionality extensible here, but I'm not sure of a good way to go about that yet. I really want some sort of thread-safe HashMap<TypeId, Box<dyn Any (of TypeId)>> that can hold arbitrary cache objects in it but I don't know if that exists.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@yuja
Copy link
Contributor

yuja commented Mar 5, 2024

Ideally I also want to make the caching functionality extensible here, but I'm not sure of a good way to go about that yet.

If the cache doesn't have to be shared between methods, it could be baked into a property closure. (e.g. format in "format" of builtin_timestamp_methods() is a cache.) The TemplateBuildMethodFn could also be changed to Box<dyn Fn to allow capturing, but that might get uglier.

@torquestomp torquestomp merged commit 4847fed into main Mar 5, 2024
16 checks passed
@torquestomp torquestomp deleted the dploch/commit-tmpl-pub branch March 5, 2024 00:59
@torquestomp
Copy link
Contributor Author

Ideally I also want to make the caching functionality extensible here, but I'm not sure of a good way to go about that yet.

If the cache doesn't have to be shared between methods, it could be baked into a property closure. (e.g. format in "format" of builtin_timestamp_methods() is a cache.) The TemplateBuildMethodFn could also be changed to Box<dyn Fn to allow capturing, but that might get uglier.

In our case it would need to be shared between methods so capturing wouldn't be sufficient. I'll try rolling something simple to handle this then, it might be useful for revamping the revset extensions PR too.

@@ -121,6 +121,18 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> {
// If we need to add multiple languages that support Commit types, this can be
// turned into a trait which extends TemplateLanguage.
impl<'repo> CommitTemplateLanguage<'repo> {
pub fn repo(&self) -> &dyn Repo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 'repo lifetime is missing here. (didn't notice before, sorry.)

@yuja
Copy link
Contributor

yuja commented Mar 5, 2024

The TemplateBuildMethodFn could also be changed to Box<dyn Fn to allow capturing, but that might get uglier.

Fyi, the generic templater uses this approach (because it seemed useful for ad-hoc templating.)
f345d99#diff-4e078e210000c4918cb327fe441cf124ab9f8b76a3ab9b825209575792a482e4R143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants