-
Notifications
You must be signed in to change notification settings - Fork 53
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 |
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Apply grep filtering | ||
| if let Some(pattern) = &args.grep { | ||
| reachable_commits = reachable_commits | ||
| .into_iter() | ||
| .filter(|commit| commit.message.contains(pattern)) | ||
| .collect(); |
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.
Clear graph columns when commits are skipped by --grep
The new grep filter is applied before rendering the graph, but GraphState only clears a column when that commit is actually rendered (see GraphState::render in the same file). With libra log --graph --grep <pattern>, if a matching commit’s parent does not match the pattern, the parent hash is pushed into columns but never removed, so later unrelated commits are printed with stray | branches and the column list grows as more ancestors are skipped. This yields incorrect graph output whenever grep hides intermediate commits.
Useful? React with 👍 / 👎.
feat(log): add --grep parameter for commit message filtering
Fixes #47
功能描述
为 log 命令添加
--grep参数,允许用户根据提交信息中的内容来过滤提交历史,只显示包含指定模式的提交。实现功能
--oneline,-n,--stat等)组合使用实现方案
LogArgs结构体中添加Option<String>类型的grep字段表示--grep参数测试验证
使用示例