Skip to content

Commit

Permalink
grep: prepare for new header field filter
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Sep 29, 2012
1 parent 652398a commit ad4813b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,14 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
if (strncmp(bol, field, len))
return 0;
bol += len;
saved_ch = strip_timestamp(bol, &eol);
switch (p->field) {
case GREP_HEADER_AUTHOR:
case GREP_HEADER_COMMITTER:
saved_ch = strip_timestamp(bol, &eol);
break;
default:
break;
}
}

again:
Expand Down
6 changes: 4 additions & 2 deletions grep.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ enum grep_context {

enum grep_header_field {
GREP_HEADER_AUTHOR = 0,
GREP_HEADER_COMMITTER
GREP_HEADER_COMMITTER,

/* Must be at the end of the enum */
GREP_HEADER_FIELD_MAX
};
#define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)

struct grep_pat {
struct grep_pat *next;
Expand Down
12 changes: 12 additions & 0 deletions t/t7810-grep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,18 @@ test_expect_success 'log --all-match --grep --grep --author takes intersection'
test_cmp expect actual
'

test_expect_success 'log --author does not search in timestamp' '
: >expect &&
git log --author="$GIT_AUTHOR_DATE" >actual &&
test_cmp expect actual
'

test_expect_success 'log --committer does not search in timestamp' '
: >expect &&
git log --committer="$GIT_COMMITTER_DATE" >actual &&
test_cmp expect actual
'

test_expect_success 'grep with CE_VALID file' '
git update-index --assume-unchanged t/t &&
rm t/t &&
Expand Down

0 comments on commit ad4813b

Please sign in to comment.