cli_util: extract new_id_prefix_context method

This commit is contained in:
Scott Taylor 2024-06-29 20:38:48 -05:00 committed by Scott Taylor
parent 8bf10c8289
commit ddfce6d2c9

View file

@ -999,8 +999,7 @@ impl WorkspaceCommandHelper {
) )
} }
pub fn id_prefix_context(&self) -> Result<&IdPrefixContext, CommandError> { fn new_id_prefix_context(&self) -> Result<IdPrefixContext, CommandError> {
self.user_repo.id_prefix_context.get_or_try_init(|| {
let mut context: IdPrefixContext = IdPrefixContext::new(self.revset_extensions.clone()); let mut context: IdPrefixContext = IdPrefixContext::new(self.revset_extensions.clone());
let revset_string: String = self let revset_string: String = self
.settings .settings
@ -1009,15 +1008,19 @@ impl WorkspaceCommandHelper {
.unwrap_or_else(|_| self.settings.default_revset()); .unwrap_or_else(|_| self.settings.default_revset());
if !revset_string.is_empty() { if !revset_string.is_empty() {
let (expression, modifier) = let (expression, modifier) =
revset::parse_with_modifier(&revset_string, &self.revset_parse_context()) revset::parse_with_modifier(&revset_string, &self.revset_parse_context()).map_err(
.map_err(|err| { |err| config_error_with_message("Invalid `revsets.short-prefixes`", err),
config_error_with_message("Invalid `revsets.short-prefixes`", err) )?;
})?;
let (None | Some(RevsetModifier::All)) = modifier; let (None | Some(RevsetModifier::All)) = modifier;
context = context.disambiguate_within(revset::optimize(expression)); context = context.disambiguate_within(revset::optimize(expression));
} }
Ok(context) Ok(context)
}) }
pub fn id_prefix_context(&self) -> Result<&IdPrefixContext, CommandError> {
self.user_repo
.id_prefix_context
.get_or_try_init(|| self.new_id_prefix_context())
} }
pub fn template_aliases_map(&self) -> &TemplateAliasesMap { pub fn template_aliases_map(&self) -> &TemplateAliasesMap {