From ad4813b3c2513c5dc7e84305ab8a393b32124977 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 29 Sep 2012 11:41:27 +0700 Subject: [PATCH] grep: prepare for new header field filter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- grep.c | 9 ++++++++- grep.h | 6 ++++-- t/t7810-grep.sh | 12 ++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/grep.c b/grep.c index 898be6ebf..8d73995e8 100644 --- a/grep.c +++ b/grep.c @@ -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: diff --git a/grep.h b/grep.h index 8a28a676f..d54adbe56 100644 --- a/grep.h +++ b/grep.h @@ -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; diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 91db352cc..30eaa9a54 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -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 && -- 2.26.2