-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revset: add &FilesetAliasesMap to RevsetParseContext
This propogates `[fileset-aliases]` to everywhere they're used. Chiefly, they need to be accessible inside of expressions like: jj log -T 'self.diff("...").summary()' jj log -r 'diff_contains("words", "...")'
- Loading branch information
1 parent
d4537ab
commit c293f52
Showing
7 changed files
with
82 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -896,7 +896,12 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, RevsetFunction>> = Lazy: | |
} | ||
let file_expressions = itertools::chain([arg], args) | ||
.map(|arg| { | ||
expect_fileset_expression(diagnostics, arg, ctx.path_converter, &Default::default()) | ||
expect_fileset_expression( | ||
diagnostics, | ||
arg, | ||
ctx.path_converter, | ||
context.fileset_aliases_map, | ||
) | ||
}) | ||
.try_collect()?; | ||
let expr = FilesetExpression::union_all(file_expressions); | ||
|
@@ -918,7 +923,7 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, RevsetFunction>> = Lazy: | |
diagnostics, | ||
files_arg, | ||
ctx.path_converter, | ||
&Default::default(), | ||
context.fileset_aliases_map, | ||
)? | ||
} else { | ||
// TODO: defaults to CLI path arguments? | ||
|
@@ -2647,6 +2652,7 @@ pub struct RevsetParseContext<'a> { | |
date_pattern_context: DatePatternContext, | ||
extensions: &'a RevsetExtensions, | ||
workspace: Option<RevsetWorkspaceContext<'a>>, | ||
fileset_aliases_map: &'a FilesetAliasesMap, | ||
} | ||
|
||
impl<'a> RevsetParseContext<'a> { | ||
|
@@ -2656,20 +2662,26 @@ impl<'a> RevsetParseContext<'a> { | |
date_pattern_context: DatePatternContext, | ||
extensions: &'a RevsetExtensions, | ||
workspace: Option<RevsetWorkspaceContext<'a>>, | ||
fileset_aliases_map: &'a FilesetAliasesMap, | ||
) -> Self { | ||
Self { | ||
aliases_map, | ||
user_email, | ||
date_pattern_context, | ||
extensions, | ||
workspace, | ||
fileset_aliases_map, | ||
} | ||
} | ||
|
||
pub fn aliases_map(&self) -> &'a RevsetAliasesMap { | ||
self.aliases_map | ||
} | ||
|
||
pub fn fileset_aliases_map(&self) -> &'a FilesetAliasesMap { | ||
self.fileset_aliases_map | ||
} | ||
|
||
pub fn user_email(&self) -> &str { | ||
&self.user_email | ||
} | ||
|
@@ -2695,35 +2707,51 @@ mod tests { | |
use std::path::PathBuf; | ||
|
||
use assert_matches::assert_matches; | ||
use dsl_util::AliasesMap; | ||
|
||
use super::*; | ||
|
||
const EMPTY: [(&str, &str); 0] = []; | ||
|
||
fn get_alias_map<T>( | ||
aliases: impl IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>, | ||
) -> AliasesMap<T, String> | ||
where | ||
T: dsl_util::AliasDeclarationParser + Default, | ||
T::Error: std::fmt::Debug, | ||
{ | ||
let mut aliases_map = AliasesMap::new(); | ||
for (decl, defn) in aliases { | ||
aliases_map.insert(decl, defn).unwrap(); | ||
} | ||
aliases_map | ||
} | ||
|
||
fn parse(revset_str: &str) -> Result<Rc<UserRevsetExpression>, RevsetParseError> { | ||
parse_with_aliases(revset_str, [] as [(&str, &str); 0]) | ||
parse_with_aliases(revset_str, EMPTY) | ||
} | ||
|
||
fn parse_with_workspace( | ||
revset_str: &str, | ||
workspace_id: &WorkspaceId, | ||
) -> Result<Rc<UserRevsetExpression>, RevsetParseError> { | ||
parse_with_aliases_and_workspace(revset_str, [] as [(&str, &str); 0], workspace_id) | ||
parse_with_aliases_and_workspace(revset_str, EMPTY, workspace_id) | ||
} | ||
|
||
fn parse_with_aliases( | ||
revset_str: &str, | ||
aliases: impl IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>, | ||
) -> Result<Rc<UserRevsetExpression>, RevsetParseError> { | ||
let mut aliases_map = RevsetAliasesMap::new(); | ||
for (decl, defn) in aliases { | ||
aliases_map.insert(decl, defn).unwrap(); | ||
} | ||
let aliases_map = get_alias_map(aliases); | ||
let fileset_aliases_map = get_alias_map(EMPTY); | ||
let extensions = RevsetExtensions::default(); | ||
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().fixed_offset().into(), | ||
&extensions, | ||
None, | ||
&fileset_aliases_map, | ||
); | ||
super::parse(&mut RevsetDiagnostics::new(), revset_str, &context) | ||
} | ||
|
@@ -2742,42 +2770,40 @@ mod tests { | |
path_converter: &path_converter, | ||
workspace_id, | ||
}; | ||
let mut aliases_map = RevsetAliasesMap::new(); | ||
for (decl, defn) in aliases { | ||
aliases_map.insert(decl, defn).unwrap(); | ||
} | ||
let aliases_map = get_alias_map(aliases); | ||
let fileset_aliases_map = get_alias_map(EMPTY); | ||
let extensions = RevsetExtensions::default(); | ||
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().fixed_offset().into(), | ||
&extensions, | ||
Some(workspace_ctx), | ||
&fileset_aliases_map, | ||
); | ||
super::parse(&mut RevsetDiagnostics::new(), revset_str, &context) | ||
} | ||
|
||
fn parse_with_modifier( | ||
revset_str: &str, | ||
) -> Result<(Rc<UserRevsetExpression>, Option<RevsetModifier>), RevsetParseError> { | ||
parse_with_aliases_and_modifier(revset_str, [] as [(&str, &str); 0]) | ||
parse_with_aliases_and_modifier(revset_str, EMPTY) | ||
} | ||
|
||
fn parse_with_aliases_and_modifier( | ||
revset_str: &str, | ||
aliases: impl IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>, | ||
) -> Result<(Rc<UserRevsetExpression>, Option<RevsetModifier>), RevsetParseError> { | ||
let mut aliases_map = RevsetAliasesMap::new(); | ||
for (decl, defn) in aliases { | ||
aliases_map.insert(decl, defn).unwrap(); | ||
} | ||
let aliases_map = get_alias_map(aliases); | ||
let fileset_aliases_map = get_alias_map(EMPTY); | ||
let extensions = RevsetExtensions::default(); | ||
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().fixed_offset().into(), | ||
&extensions, | ||
None, | ||
&fileset_aliases_map, | ||
); | ||
super::parse_with_modifier(&mut RevsetDiagnostics::new(), revset_str, &context) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters