-
Notifications
You must be signed in to change notification settings - Fork 353
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
8 changed files
with
381 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, fileset, revset_parser}; | ||
|
||
/// Error occurred during symbol resolution. | ||
|
@@ -132,6 +133,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 containing diffs matching the `text` pattern within the `files`. | ||
|
@@ -684,6 +689,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 | ||
|
@@ -700,6 +712,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()) | ||
|
@@ -774,6 +793,20 @@ pub fn expect_string_pattern(node: &ExpressionNode) -> Result<StringPattern, Rev | |
revset_parser::expect_pattern_with("string pattern", node, parse_pattern) | ||
} | ||
|
||
pub 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) | ||
} | ||
|
||
fn parse_remote_branches_arguments( | ||
function: &FunctionCallNode, | ||
remote_ref_state: Option<RemoteRefState>, | ||
|
@@ -2035,6 +2068,7 @@ impl RevsetExtensions { | |
pub struct RevsetParseContext<'a> { | ||
aliases_map: &'a RevsetAliasesMap, | ||
user_email: String, | ||
date_pattern_context: DatePatternContext, | ||
extensions: &'a RevsetExtensions, | ||
workspace: Option<RevsetWorkspaceContext<'a>>, | ||
} | ||
|
@@ -2043,12 +2077,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, | ||
} | ||
|
@@ -2062,6 +2098,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() | ||
} | ||
|
@@ -2105,6 +2145,7 @@ mod tests { | |
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().fixed_offset().into(), | ||
&extensions, | ||
None, | ||
); | ||
|
@@ -2133,6 +2174,7 @@ mod tests { | |
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().fixed_offset().into(), | ||
&extensions, | ||
Some(workspace_ctx), | ||
); | ||
|
@@ -2157,6 +2199,7 @@ mod tests { | |
let context = RevsetParseContext::new( | ||
&aliases_map, | ||
"[email protected]".to_string(), | ||
chrono::Utc::now().fixed_offset().into(), | ||
&extensions, | ||
None, | ||
); | ||
|
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
Oops, something went wrong.