@matheusbsbs / matheus-bagliano / commits / 0843acfd2c
Fork 0

Fix "git log -i --grep"

This has been broken in v1.6.0 due to the reorganization of the revision option parsing code. The "-i" is completely ignored, but works fine in "git log --grep -i". What happens is that the code for "-i" looks for revs->grep_filter; if it is NULL, we do nothing, since there are no grep filters. But that is obviously not correct, since we want it to influence the later --grep option. Doing it the other way around works, since "-i" just impacts the existing grep_filter option. Instead, we now always initialize the grep_filter member and just fill in options and patterns as we get them. This means that we can no longer check grep_filter for NULL, but instead must check the pattern list to see if we have any actual patterns. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 25, 2008 at 02:15 UTC 0843acfd2c32dd8a8594731a0090d0934ccb123b
4 files changed +38 -24
builtin-rev-list.c
+2 -1
@@ -645,7 +645,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
645 revs.diff)
646 usage(rev_list_usage);
647
648 - save_commit_buffer = revs.verbose_header || revs.grep_filter;
648 + save_commit_buffer = revs.verbose_header ||
649 + revs.grep_filter.pattern_list;
650 if (bisect_list)
651 revs.limited = 1;
652
revision.c
+12 -22
@@ -782,6 +782,10 @@ void init_revisions(struct rev_info *revs, const char *prefix)
782
783 revs->commit_format = CMIT_FMT_DEFAULT;
784
785 + revs->grep_filter.status_only = 1;
786 + revs->grep_filter.pattern_tail = &(revs->grep_filter.pattern_list);
787 + revs->grep_filter.regflags = REG_NEWLINE;
788 +
789 diff_setup(&revs->diffopt);
790 if (prefix && !revs->diffopt.prefix) {
791 revs->diffopt.prefix = prefix;
@@ -946,15 +950,7 @@ void read_revisions_from_stdin(struct rev_info *revs)
950
951 static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
952 {
949 - if (!revs->grep_filter) {
950 - struct grep_opt *opt = xcalloc(1, sizeof(*opt));
951 - opt->status_only = 1;
952 - opt->pattern_tail = &(opt->pattern_list);
953 - opt->regflags = REG_NEWLINE;
954 - revs->grep_filter = opt;
955 - }
956 - append_grep_pattern(revs->grep_filter, ptn,
957 - "command line", 0, what);
953 + append_grep_pattern(&revs->grep_filter, ptn, "command line", 0, what);
954 }
955
956 static void add_header_grep(struct rev_info *revs, const char *field, const char *pattern)
@@ -1164,17 +1160,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1160 } else if (!prefixcmp(arg, "--grep=")) {
1161 add_message_grep(revs, arg+7);
1162 } else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
1167 - if (revs->grep_filter)
1168 - revs->grep_filter->regflags |= REG_EXTENDED;
1163 + revs->grep_filter.regflags |= REG_EXTENDED;
1164 } else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
1170 - if (revs->grep_filter)
1171 - revs->grep_filter->regflags |= REG_ICASE;
1165 + revs->grep_filter.regflags |= REG_ICASE;
1166 } else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
1173 - if (revs->grep_filter)
1174 - revs->grep_filter->fixed = 1;
1167 + revs->grep_filter.fixed = 1;
1168 } else if (!strcmp(arg, "--all-match")) {
1176 - if (revs->grep_filter)
1177 - revs->grep_filter->all_match = 1;
1169 + revs->grep_filter.all_match = 1;
1170 } else if (!prefixcmp(arg, "--encoding=")) {
1171 arg += 11;
1172 if (strcmp(arg, "none"))
@@ -1349,9 +1341,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1341 if (diff_setup_done(&revs->diffopt) < 0)
1342 die("diff_setup_done failed");
1343
1352 - if (revs->grep_filter) {
1353 - compile_grep_patterns(revs->grep_filter);
1354 - }
1344 + compile_grep_patterns(&revs->grep_filter);
1345
1346 if (revs->reverse && revs->reflog_info)
1347 die("cannot combine --reverse with --walk-reflogs");
@@ -1492,9 +1482,9 @@ static int rewrite_parents(struct rev_info *revs, struct commit *commit)
1482
1483 static int commit_match(struct commit *commit, struct rev_info *opt)
1484 {
1495 - if (!opt->grep_filter)
1485 + if (!opt->grep_filter.pattern_list)
1486 return 1;
1497 - return grep_buffer(opt->grep_filter,
1487 + return grep_buffer(&opt->grep_filter,
1488 NULL, /* we say nothing, not even filename */
1489 commit->buffer, strlen(commit->buffer));
1490 }
revision.h
+2 -1
@@ -2,6 +2,7 @@
2 #define REVISION_H
3
4 #include "parse-options.h"
5 +#include "grep.h"
6
7 #define SEEN (1u<<0)
8 #define UNINTERESTING (1u<<1)
@@ -92,7 +93,7 @@ struct rev_info {
93 int show_log_size;
94
95 /* Filter by commit log message */
95 - struct grep_opt *grep_filter;
96 + struct grep_opt grep_filter;
97
98 /* Display history graph */
99 struct git_graph *graph;
t/t4202-log.sh
+22
@@ -69,7 +69,29 @@ test_expect_success 'diff-filter=D' '
69
70 '
71
72 +test_expect_success 'setup case sensitivity tests' '
73 + echo case >one &&
74 + test_tick &&
75 + git commit -a -m Second
76 +'
77 +
78 +test_expect_success 'log --grep' '
79 + echo second >expect &&
80 + git log -1 --pretty="tformat:%s" --grep=sec >actual &&
81 + test_cmp expect actual
82 +'
83
84 +test_expect_success 'log -i --grep' '
85 + echo Second >expect &&
86 + git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
87 + test_cmp expect actual
88 +'
89 +
90 +test_expect_success 'log --grep -i' '
91 + echo Second >expect &&
92 + git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
93 + test_cmp expect actual
94 +'
95
96 test_done
97