aboutsummaryrefslogtreecommitdiffstats
path: root/grep.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-09-04 22:15:02 -0700
committerJunio C Hamano <gitster@pobox.com>2008-09-04 22:21:56 -0700
commita4d7d2c6dbc9e1294034171c31d87b24cf3b492e (patch)
tree6db0feebddb05ef8bdb2537832e2c2bfda248f89 /grep.h
parentf88d225feb117f0429540da90b2552e198fa2e82 (diff)
downloadgit-a4d7d2c6dbc9e1294034171c31d87b24cf3b492e.tar.gz
log --author/--committer: really match only with name part
When we tried to find commits done by AUTHOR, the first implementation tried to pattern match a line with "^author .*AUTHOR", which later was enhanced to strip leading caret and look for "^author AUTHOR" when the search pattern was anchored at the left end (i.e. --author="^AUTHOR"). This had a few problems: * When looking for fixed strings (e.g. "git log -F --author=x --grep=y"), the regexp internally used "^author .*x" would never match anything; * To match at the end (e.g. "git log --author='google.com>$'"), the generated regexp has to also match the trailing timestamp part the commit header lines have. Also, in order to determine if the '$' at the end means "match at the end of the line" or just a literal dollar sign (probably backslash-quoted), we would need to parse the regexp ourselves. An earlier alternative tried to make sure that a line matches "^author " (to limit by field name) and the user supplied pattern at the same time. While it solved the -F problem by introducing a special override for matching the "^author ", it did not solve the trailing timestamp nor tail match problem. It also would have matched every commit if --author=author was asked for, not because the author's email part had this string, but because every commit header line that talks about the author begins with that field name, regardleses of who wrote it. Instead of piling more hacks on top of hacks, this rethinks the grep machinery that is used to look for strings in the commit header, and makes sure that (1) field name matches literally at the beginning of the line, followed by a SP, and (2) the user supplied pattern is matched against the remainder of the line, excluding the trailing timestamp data. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.h')
-rw-r--r--grep.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/grep.h b/grep.h
index d252dd25f8..59b3f871ea 100644
--- a/grep.h
+++ b/grep.h
@@ -17,12 +17,18 @@ enum grep_context {
GREP_CONTEXT_BODY,
};
+enum grep_header_field {
+ GREP_HEADER_AUTHOR = 0,
+ GREP_HEADER_COMMITTER,
+};
+
struct grep_pat {
struct grep_pat *next;
const char *origin;
int no;
enum grep_pat_token token;
const char *pattern;
+ enum grep_header_field field;
regex_t regexp;
};
@@ -74,6 +80,7 @@ struct grep_opt {
};
extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
+extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
extern void compile_grep_patterns(struct grep_opt *opt);
extern void free_grep_patterns(struct grep_opt *opt);
extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);