Code

Search checks reference names too
authorDominik Vogt <dvogt@ffm.tc.iot.dtag.de>
Mon, 7 Apr 2008 11:34:53 +0000 (13:34 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 17 Apr 2008 12:17:53 +0000 (14:17 +0200)
Do not search for matches in hidden view elements.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
tig.c

diff --git a/tig.c b/tig.c
index 42a2da5a18bcf01b56b51c46e1f420b781c95dab..9d0dca1a07d81694a5732f92d75f9b68ea41fd14 100644 (file)
--- 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;
                }