-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revset: add author_date and committer_date revset functions
Author dates and committer dates can be filtered like so: committer_date(before:"1 hour ago") # more than 1 hour ago committer_date(after:"1 hour ago") # 1 hour ago or less A date range can be created by combining revsets. For example, to see any revisions committed yesterday: committer_date(after:"yesterday") & committer_date(before:"today")
- Loading branch information
Showing
7 changed files
with
351 additions
and
3 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 |
---|---|---|
|
@@ -43,6 +43,7 @@ pub use crate::revset_parser::{ | |
}; | ||
use crate::store::Store; | ||
use crate::str_util::StringPattern; | ||
use crate::time_util::{DatePattern, DatePatternContext}; | ||
use crate::{dsl_util, revset_parser}; | ||
|
||
/// Error occurred during symbol resolution. | ||
|
@@ -131,6 +132,10 @@ pub enum RevsetFilterPredicate { | |
Author(StringPattern), | ||
/// Commits with committer name or email matching the pattern. | ||
Committer(StringPattern), | ||
/// Commits with author dates matching the given date pattern. | ||
AuthorDate(DatePattern), | ||
/// Commits with committer dates matching the given date pattern. | ||
CommitterDate(DatePattern), | ||
/// Commits modifying the paths specified by the fileset. | ||
File(FilesetExpression), | ||
/// Commits with conflicts | ||
|
@@ -685,6 +690,13 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, RevsetFunction>> = Lazy: | |
pattern, | ||
))) | ||
}); | ||
map.insert("author_date", |function, context| { | ||
let [arg] = function.expect_exact_arguments()?; | ||
let pattern = expect_date_pattern(arg, context.date_pattern_context())?; | ||
Ok(RevsetExpression::filter(RevsetFilterPredicate::AuthorDate( | ||
pattern, | ||
))) | ||
}); | ||
map.insert("mine", |function, context| { | ||
function.expect_no_arguments()?; | ||
// Email address domains are inherently case‐insensitive, and the local‐parts | ||
|
@@ -701,6 +713,13 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, RevsetFunction>> = Lazy: | |
pattern, | ||
))) | ||
}); | ||
map.insert("committer_date", |function, context| { | ||
let [arg] = function.expect_exact_arguments()?; | ||
let pattern = expect_date_pattern(arg, context.date_pattern_context())?; | ||
Ok(RevsetExpression::filter( | ||
RevsetFilterPredicate::CommitterDate(pattern), | ||
)) | ||
}); | ||
map.insert("empty", |function, _context| { | ||
function.expect_no_arguments()?; | ||
Ok(RevsetExpression::is_empty()) | ||
|
@@ -752,6 +771,20 @@ pub fn expect_string_pattern(node: &ExpressionNode) -> Result<StringPattern, Rev | |
revset_parser::expect_pattern_with("string pattern", node, parse_pattern) | ||
} | ||
|
||
fn expect_date_pattern( | ||
node: &ExpressionNode, | ||
context: &DatePatternContext, | ||
) -> Result<DatePattern, RevsetParseError> { | ||
let parse_pattern = | ||
|value: &str, kind: Option<&str>| -> Result<_, Box<dyn std::error::Error + Send + Sync>> { | ||
match kind { | ||
None => Err("Date pattern must specify 'after' or 'before'".into()), | ||
Some(kind) => Ok(context.parse_relative(value, kind)?), | ||
} | ||
}; | ||
revset_parser::expect_pattern_with("date pattern", node, parse_pattern) | ||
} | ||
|
||
/// Resolves function call by using the given function map. | ||
fn lower_function_call( | ||
function: &FunctionCallNode, | ||
|
@@ -1980,6 +2013,8 @@ impl RevsetExtensions { | |
pub struct RevsetParseContext<'a> { | ||
aliases_map: &'a RevsetAliasesMap, | ||
user_email: String, | ||
/// The current local time when the revset expression was written. | ||
date_pattern_context: DatePatternContext, | ||
extensions: &'a RevsetExtensions, | ||
workspace: Option<RevsetWorkspaceContext<'a>>, | ||
} | ||
|
@@ -1988,12 +2023,14 @@ impl<'a> RevsetParseContext<'a> { | |
pub fn new( | ||
aliases_map: &'a RevsetAliasesMap, | ||
user_email: String, | ||
date_pattern_context: DatePatternContext, | ||
extensions: &'a RevsetExtensions, | ||
workspace: Option<RevsetWorkspaceContext<'a>>, | ||
) -> Self { | ||
Self { | ||
aliases_map, | ||
user_email, | ||
date_pattern_context, | ||
extensions, | ||
workspace, | ||
} | ||
|
@@ -2007,6 +2044,10 @@ impl<'a> RevsetParseContext<'a> { | |
&self.user_email | ||
} | ||
|
||
pub fn date_pattern_context(&self) -> &DatePatternContext { | ||
&self.date_pattern_context | ||
} | ||
|
||
pub fn symbol_resolvers(&self) -> &[impl AsRef<dyn SymbolResolverExtension>] { | ||
self.extensions.symbol_resolvers() | ||
} | ||
|
@@ -2050,6 +2091,7 @@ mod tests { | |
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().into(), | ||
&extensions, | ||
None, | ||
); | ||
|
@@ -2078,6 +2120,7 @@ mod tests { | |
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().into(), | ||
&extensions, | ||
Some(workspace_ctx), | ||
); | ||
|
@@ -2102,6 +2145,7 @@ mod tests { | |
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().into(), | ||
&extensions, | ||
None, | ||
); | ||
|
Oops, something went wrong.