From 1cedefdddea3b12d7777eaa523bd6e3fa30b2330 Mon Sep 17 00:00:00 2001 From: Dominik Vogt Date: Mon, 7 Apr 2008 13:34:53 +0200 Subject: [PATCH] Search checks reference names too Do not search for matches in hidden view elements. Signed-off-by: Jonas Fonseca --- tig.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/tig.c b/tig.c index 42a2da5..9d0dca1 100644 --- a/tig.c +++ b/tig.c @@ -3665,23 +3665,23 @@ blame_grep(struct view *view, struct line *line) struct blame_commit *commit = blame->commit; regmatch_t pmatch; -#define MATCH(text) \ - (*text && regexec(view->regex, text, 1, &pmatch, 0) != REG_NOMATCH) +#define MATCH(text, on) \ + (on && *text && regexec(view->regex, text, 1, &pmatch, 0) != REG_NOMATCH) if (commit) { char buf[DATE_COLS + 1]; - if (MATCH(commit->title) || - MATCH(commit->author) || - MATCH(commit->id)) + if (MATCH(commit->title, 1) || + MATCH(commit->author, opt_author) || + MATCH(commit->id, opt_date)) return TRUE; if (strftime(buf, sizeof(buf), DATE_FORMAT, &commit->time) && - MATCH(buf)) + MATCH(buf, 1)) return TRUE; } - return MATCH(blame->text); + return MATCH(blame->text, 1); #undef MATCH } @@ -5049,11 +5049,27 @@ main_request(struct view *view, enum request request, struct line *line) return REQ_NONE; } +static bool +grep_refs(struct ref **refs, regex_t *regex) +{ + regmatch_t pmatch; + size_t i = 0; + + if (!refs) + return FALSE; + do { + if (regexec(regex, refs[i]->name, 1, &pmatch, 0) != REG_NOMATCH) + return TRUE; + } while (refs[i++]->next); + + return FALSE; +} + static bool main_grep(struct view *view, struct line *line) { struct commit *commit = line->data; - enum { S_TITLE, S_AUTHOR, S_DATE, S_END } state; + enum { S_TITLE, S_AUTHOR, S_DATE, S_REFS, S_END } state; char buf[DATE_COLS + 1]; regmatch_t pmatch; @@ -5062,13 +5078,24 @@ main_grep(struct view *view, struct line *line) switch (state) { case S_TITLE: text = commit->title; break; - case S_AUTHOR: text = commit->author; break; + case S_AUTHOR: + if (!opt_author) + continue; + text = commit->author; + break; case S_DATE: + if (!opt_date) + continue; if (!strftime(buf, sizeof(buf), DATE_FORMAT, &commit->time)) continue; text = buf; break; - + case S_REFS: + if (!opt_show_refs) + continue; + if (grep_refs(commit->refs, view->regex) == TRUE) + return TRUE; + continue; default: return FALSE; } -- 2.32.0.93.g670b81a890