Skip to content

Commit

Permalink
commit_templater: make a bunch of types public for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
torquestomp committed Feb 29, 2024
1 parent 9031288 commit 5e8227a
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::templater::{
};
use crate::text_util;

struct CommitTemplateLanguage<'repo> {
pub struct CommitTemplateLanguage<'repo> {
repo: &'repo dyn Repo,
workspace_id: WorkspaceId,
id_prefix_context: &'repo IdPrefixContext,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<'repo> CommitTemplateLanguage<'repo> {
}
}

enum CommitTemplatePropertyKind<'repo> {
pub enum CommitTemplatePropertyKind<'repo> {
Core(CoreTemplatePropertyKind<'repo, Commit>),
Commit(Box<dyn TemplateProperty<Commit, Output = Commit> + 'repo>),
CommitList(Box<dyn TemplateProperty<Commit, Output = Vec<Commit>> + 'repo>),
Expand Down Expand Up @@ -232,15 +232,15 @@ type CommitTemplateBuildMethodFnMap<'repo, T> =
TemplateBuildMethodFnMap<'repo, CommitTemplateLanguage<'repo>, T>;

/// Symbol table of methods available in the commit template.
struct CommitTemplateBuildFnTable<'repo> {
core: CoreTemplateBuildFnTable<'repo, CommitTemplateLanguage<'repo>>,
commit_methods: CommitTemplateBuildMethodFnMap<'repo, Commit>,
ref_name_methods: CommitTemplateBuildMethodFnMap<'repo, RefName>,
commit_or_change_id_methods: CommitTemplateBuildMethodFnMap<'repo, CommitOrChangeId>,
shortest_id_prefix_methods: CommitTemplateBuildMethodFnMap<'repo, ShortestIdPrefix>,
pub struct CommitTemplateBuildFnTable<'repo> {
pub core: CoreTemplateBuildFnTable<'repo, CommitTemplateLanguage<'repo>>,
pub commit_methods: CommitTemplateBuildMethodFnMap<'repo, Commit>,
pub ref_name_methods: CommitTemplateBuildMethodFnMap<'repo, RefName>,
pub commit_or_change_id_methods: CommitTemplateBuildMethodFnMap<'repo, CommitOrChangeId>,
pub shortest_id_prefix_methods: CommitTemplateBuildMethodFnMap<'repo, ShortestIdPrefix>,
}

impl CommitTemplateBuildFnTable<'_> {
impl<'repo> CommitTemplateBuildFnTable<'repo> {
/// Creates new symbol table containing the builtin methods.
fn builtin() -> Self {
CommitTemplateBuildFnTable {
Expand All @@ -251,6 +251,22 @@ impl CommitTemplateBuildFnTable<'_> {
shortest_id_prefix_methods: builtin_shortest_id_prefix_methods(),
}
}

pub fn new() -> Self {
CommitTemplateBuildFnTable {
core: CoreTemplateBuildFnTable::new(),
commit_methods: HashMap::new(),
ref_name_methods: HashMap::new(),
commit_or_change_id_methods: HashMap::new(),
shortest_id_prefix_methods: HashMap::new(),
}
}
}

impl<'a> Default for CommitTemplateBuildFnTable<'a> {
fn default() -> Self {
Self::new()
}
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -506,7 +522,7 @@ fn extract_working_copies(repo: &dyn Repo, commit: &Commit) -> String {

/// Branch or tag name with metadata.
#[derive(Clone, Debug, Eq, PartialEq)]
struct RefName {
pub struct RefName {
/// Local name.
name: String,
/// Remote name if this is a remote or Git-tracking ref.
Expand Down Expand Up @@ -656,7 +672,7 @@ fn extract_git_head(repo: &dyn Repo, commit: &Commit) -> Vec<RefName> {
}

#[derive(Clone, Debug, Eq, PartialEq)]
enum CommitOrChangeId {
pub enum CommitOrChangeId {
Commit(CommitId),
Change(ChangeId),
}
Expand Down Expand Up @@ -736,7 +752,7 @@ fn builtin_commit_or_change_id_methods<'repo>(
map
}

struct ShortestIdPrefix {
pub struct ShortestIdPrefix {
pub prefix: String,
pub rest: String,
}
Expand Down

0 comments on commit 5e8227a

Please sign in to comment.