Skip to content

Commit

Permalink
commit_templater: add an AnyMap for extensions to cache their own info
Browse files Browse the repository at this point in the history
  • Loading branch information
torquestomp committed Mar 6, 2024
1 parent aa67344 commit 8399647
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::any::Any;
use std::cmp::max;
use std::collections::HashMap;
use std::io;
use std::rc::Rc;

use itertools::Itertools as _;
use jj_lib::any_map::AnyMap;
use jj_lib::backend::{ChangeId, CommitId};
use jj_lib::commit::Commit;
use jj_lib::hex_util::to_reverse_hex;
Expand Down Expand Up @@ -50,6 +52,7 @@ pub struct CommitTemplateLanguage<'repo> {
id_prefix_context: &'repo IdPrefixContext,
build_fn_table: CommitTemplateBuildFnTable<'repo>,
keyword_cache: CommitKeywordCache,
cache_extensions: AnyMap,
}

impl<'repo> CommitTemplateLanguage<'repo> {
Expand All @@ -71,6 +74,7 @@ impl<'repo> CommitTemplateLanguage<'repo> {
id_prefix_context,
build_fn_table,
keyword_cache: CommitKeywordCache::default(),
cache_extensions: AnyMap::new(),
}
}
}
Expand Down Expand Up @@ -156,6 +160,10 @@ impl<'repo> CommitTemplateLanguage<'repo> {
&self.keyword_cache
}

pub fn cache_extension<T: Any>(&self, generator: impl FnOnce() -> T) -> &T {
self.cache_extensions.insert(generator)
}

pub fn wrap_commit(
&self,
property: impl TemplateProperty<Commit, Output = Commit> + 'repo,
Expand Down

0 comments on commit 8399647

Please sign in to comment.