-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,6 +57,10 @@ pub struct LogArgs { | |||||||||||||||||||||
| /// Files to limit diff output (used with -p, --name-only, or --stat) | ||||||||||||||||||||||
| #[clap(value_name = "PATHS", num_args = 0..)] | ||||||||||||||||||||||
| pathspec: Vec<String>, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Filter commits by message content | ||||||||||||||||||||||
| #[clap(long)] | ||||||||||||||||||||||
| pub grep: Option<String>, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #[derive(PartialEq, Debug)] | ||||||||||||||||||||||
|
|
@@ -200,6 +204,14 @@ pub async fn execute(args: LogArgs) { | |||||||||||||||||||||
| // default sort with signature time | ||||||||||||||||||||||
| reachable_commits.sort_by(|a, b| b.committer.timestamp.cmp(&a.committer.timestamp)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Apply grep filtering | ||||||||||||||||||||||
| if let Some(pattern) = &args.grep { | ||||||||||||||||||||||
| reachable_commits = reachable_commits | ||||||||||||||||||||||
| .into_iter() | ||||||||||||||||||||||
| .filter(|commit| commit.message.contains(pattern)) | ||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||
|
Comment on lines
+209
to
+212
|
||||||||||||||||||||||
| 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(); | |
| } |
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 👍 / 👎.
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.