grep: prepare for new header field filter
grep supports only author and committer headers, which have the same special treatment that later headers may or may not have. Check for field type and only strip_timestamp() when the field is either author or committer. GREP_HEADER_FIELD_MAX is put in the grep_header_field enum to be calculated automatically, correctly, as long as it's at the end of the enum. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Sep 29, 2012 at 11:41 UTC
ad4813b3c2513c5dc7e84305ab8a393b32124977
3 files changed
+24
-3
grep.c
+8
-1
@@ -720,7 +720,14 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
720
if (strncmp(bol, field, len))
721
return 0;
722
bol += len;
723
- saved_ch = strip_timestamp(bol, &eol);
723
+ switch (p->field) {
724
+ case GREP_HEADER_AUTHOR:
725
+ case GREP_HEADER_COMMITTER:
726
+ saved_ch = strip_timestamp(bol, &eol);
727
+ break;
728
+ default:
729
+ break;
730
+ }
731
}
732
733
again:
grep.h
+4
-2
@@ -29,9 +29,11 @@ enum grep_context {
29
30
enum grep_header_field {
31
GREP_HEADER_AUTHOR = 0,
32
- GREP_HEADER_COMMITTER
32
+ GREP_HEADER_COMMITTER,
33
+
34
+ /* Must be at the end of the enum */
35
+ GREP_HEADER_FIELD_MAX
36
};
34
-#define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
37
38
struct grep_pat {
39
struct grep_pat *next;
t/t7810-grep.sh
+12
@@ -628,6 +628,18 @@ test_expect_success 'log --all-match --grep --grep --author takes intersection'
628
test_cmp expect actual
629
'
630
631
+test_expect_success 'log --author does not search in timestamp' '
632
+ : >expect &&
633
+ git log --author="$GIT_AUTHOR_DATE" >actual &&
634
+ test_cmp expect actual
635
+'
636
+
637
+test_expect_success 'log --committer does not search in timestamp' '
638
+ : >expect &&
639
+ git log --committer="$GIT_COMMITTER_DATE" >actual &&
640
+ test_cmp expect actual
641
+'
642
+
643
test_expect_success 'grep with CE_VALID file' '
644
git update-index --assume-unchanged t/t &&
645
rm t/t &&