-
Notifications
You must be signed in to change notification settings - Fork 32
feat(log): add --grep parameter for commit message filtering #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(log): add --grep parameter for commit message filtering #60
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a --grep parameter to the log command for filtering commits based on message content, implementing issue #47. The feature uses simple substring matching to filter the commit history before display.
- Adds
--grepoption toLogArgsstruct for pattern-based commit message filtering - Implements filtering logic in the execute function after sorting commits by timestamp
- Adds unit tests for argument parsing and parameter combinations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
| reachable_commits = reachable_commits | ||
| .into_iter() | ||
| .filter(|commit| commit.message.contains(pattern)) | ||
| .collect(); |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider handling the edge case where the grep pattern is an empty string. Currently, an empty string will match all commits (since contains("") returns true for any string). While this might be acceptable, it could be clearer to either:
- Skip filtering when the pattern is empty
- Document this behavior in the help text
Example improvement:
// Apply grep filtering
if let Some(pattern) = &args.grep {
if !pattern.is_empty() {
reachable_commits = reachable_commits
.into_iter()
.filter(|commit| commit.message.contains(pattern))
.collect();
}
}| reachable_commits = reachable_commits | |
| .into_iter() | |
| .filter(|commit| commit.message.contains(pattern)) | |
| .collect(); | |
| if !pattern.is_empty() { | |
| reachable_commits = reachable_commits | |
| .into_iter() | |
| .filter(|commit| commit.message.contains(pattern)) | |
| .collect(); | |
| } |
| #[clap(value_name = "PATHS", num_args = 0..)] | ||
| pathspec: Vec<String>, | ||
|
|
||
| /// Filter commits by message content |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider clarifying that the grep filter performs case-sensitive substring matching. This helps set user expectations about the behavior. For example:
/// Filter commits by message content (case-sensitive substring match)
or
/// Filter commits by message content. Performs case-sensitive substring matching.
| /// Filter commits by message content | |
| /// Filter commits by message content (case-sensitive substring match) |
|
请参考copilot意见修改代码,并修复fmt和clippy |
feat(log): add --grep parameter for commit message filtering
Fixes #47
功能描述
为 log 命令添加
--grep参数,允许用户根据提交信息中的内容来过滤提交历史,只显示包含指定模式的提交。实现功能
--oneline,-n,--stat等)组合使用实现方案
LogArgs结构体中添加Option<String>类型的grep字段表示--grep参数测试验证
使用示例