pretty: colorize pattern matches in commit messages
PATCH v3 1/1 pretty: colorize pattern matches in commit messages
The "git log" command limits its output to the commits that contain strings matched by a pattern when the "--grep=<pattern>" option is used, but unlike output from "git grep -e <pattern>", the matches are not highlighted, making them harder to spot.
Teach the pretty-printer code to highlight matches from the "--grep=<pattern>", "--author=<pattern>" and "--committer=<pattern>" options (to view the last one, you may have to ask for --pretty=fuller).
---
v2: make the commit message whole (add the missing ingredients), rename
append_matched_line() to append_line_with_color(), use colors[GREP_COLOR_MATCH_SELECTED] instead of colors[GREP_COLOR_MATCH_CONTEXT], allow the background color to be customized, don't copy strings to a buffer when not coloring in append_line_with_color(), rename next_match() to grep_next_match(), repurpose grep_next_match()/match_one_pattern() for use in append_line_with_color() (allowing us to remove duplicated matching code in append_line_with_color()), document how to customize the feature and modify some of the tests to fit the feature better.
v3: fix a formatting issue with the added documentation.
--- Documentation/git-log.txt | 8 +++ grep.c | 41 +++++++++------ grep.h | 3 ++ pretty.c | 107 +++++++++++++++++++++++++++++++++----- t/t4202-log.sh | 42 +++++++++++++++ 5 files changed, 174 insertions(+), 27 deletions(-)
Documentation/git-log.txt +8 -0
@@ -241,6 +241,14 @@ This setting can be disabled by the `--no-notes` option, overridden by the `GIT_NOTES_DISPLAY_REF` environment variable, and overridden by the `--notes=<ref>` option. +color.grep.selected:: + Determines the non matching text (background) color of selected lines, + when `--grep`, `--author` or `--committer` are used. + +color.grep.matchSelected:: + Determines the matching text (foreground) color of selected lines, when + `--grep`, `--author` or `--committer` are used. + GIT --- Part of the linkgit:git[1] suite
grep.c +26 -15
72 lines not on this page · raw message
grep.h +3 -0
@@ -177,6 +177,9 @@ void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, constvoid compile_grep_patterns (struct grep_opt *opt);void free_grep_patterns (struct grep_opt *opt);int grep_buffer (struct grep_opt *opt,char *buf,unsigned long size); +int grep_next_match (struct grep_opt *opt,char *bol,char *eol, +enum grep_context ctx,regmatch_t *pmatch, +enum grep_header_field field,int eflags);struct grep_source {char *name;
pretty.c +95 -12
173 lines not on this page · raw message
t/t4202-log.sh +42 -0
48 lines not on this page · raw message
Signature · 1 line
2.33.0