diff options
author | Lars Hjemli | 2006-12-28 02:45:28 +0100 |
---|---|---|
committer | Lars Hjemli | 2006-12-28 02:45:28 +0100 |
commit | 732d68d240b95dc428c92fc94bce9adb8912094e (patch) | |
tree | 24c6ab907c2a8574da12e426144706ad63780868 | |
parent | Add generic support for search box in page header (diff) | |
download | cgit-732d68d240b95dc428c92fc94bce9adb8912094e.tar.gz cgit-732d68d240b95dc428c92fc94bce9adb8912094e.zip |
Add basic log filtering
This enables case-insensitive grep on logentris using the new search box Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 7 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | git.h | 68 | ||||
-rw-r--r-- | ui-log.c | 13 |
4 files changed, 83 insertions, 7 deletions
diff --git a/cgit.c b/cgit.c index 277b849..fba97d7 100644 --- a/cgit.c +++ b/cgit.c | |||
@@ -24,12 +24,15 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
24 | } | 24 | } |
25 | setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); | 25 | setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); |
26 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); | 26 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); |
27 | int show_search = 0; | ||
28 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | ||
29 | show_search = 1; | ||
27 | cgit_print_docstart(title, item); | 30 | cgit_print_docstart(title, item); |
28 | cgit_print_pageheader(title, 0); | 31 | cgit_print_pageheader(title, show_search); |
29 | if (!cgit_query_page) { | 32 | if (!cgit_query_page) { |
30 | cgit_print_summary(); | 33 | cgit_print_summary(); |
31 | } else if (!strcmp(cgit_query_page, "log")) { | 34 | } else if (!strcmp(cgit_query_page, "log")) { |
32 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100); | 35 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search); |
33 | } else if (!strcmp(cgit_query_page, "tree")) { | 36 | } else if (!strcmp(cgit_query_page, "tree")) { |
34 | cgit_print_tree(cgit_query_sha1); | 37 | cgit_print_tree(cgit_query_sha1); |
35 | } else if (!strcmp(cgit_query_page, "commit")) { | 38 | } else if (!strcmp(cgit_query_page, "commit")) { |
diff --git a/cgit.h b/cgit.h index e114a50..249650e 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -104,7 +104,7 @@ extern void cgit_print_pageheader(char *title, int show_search); | |||
104 | 104 | ||
105 | extern void cgit_print_repolist(struct cacheitem *item); | 105 | extern void cgit_print_repolist(struct cacheitem *item); |
106 | extern void cgit_print_summary(); | 106 | extern void cgit_print_summary(); |
107 | extern void cgit_print_log(const char *tip, int ofs, int cnt); | 107 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); |
108 | extern void cgit_print_view(const char *hex); | 108 | extern void cgit_print_view(const char *hex); |
109 | extern void cgit_print_tree(const char *hex); | 109 | extern void cgit_print_tree(const char *hex); |
110 | extern void cgit_print_commit(const char *hex); | 110 | extern void cgit_print_commit(const char *hex); |
diff --git a/git.h b/git.h index 922a167..b1e4828 100644 --- a/git.h +++ b/git.h | |||
@@ -31,7 +31,7 @@ | |||
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | #include <dirent.h> | 32 | #include <dirent.h> |
33 | #include <time.h> | 33 | #include <time.h> |
34 | 34 | #include <regex.h> | |
35 | 35 | ||
36 | /* On most systems <limits.h> would have given us this, but | 36 | /* On most systems <limits.h> would have given us this, but |
37 | * not on some systems (e.g. GNU/Hurd). | 37 | * not on some systems (e.g. GNU/Hurd). |
@@ -156,6 +156,72 @@ static inline void hashclr(unsigned char *hash) | |||
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | /* | ||
160 | * from git:grep.h | ||
161 | */ | ||
162 | |||
163 | enum grep_pat_token { | ||
164 | GREP_PATTERN, | ||
165 | GREP_PATTERN_HEAD, | ||
166 | GREP_PATTERN_BODY, | ||
167 | GREP_AND, | ||
168 | GREP_OPEN_PAREN, | ||
169 | GREP_CLOSE_PAREN, | ||
170 | GREP_NOT, | ||
171 | GREP_OR, | ||
172 | }; | ||
173 | |||
174 | enum grep_context { | ||
175 | GREP_CONTEXT_HEAD, | ||
176 | GREP_CONTEXT_BODY, | ||
177 | }; | ||
178 | |||
179 | struct grep_pat { | ||
180 | struct grep_pat *next; | ||
181 | const char *origin; | ||
182 | int no; | ||
183 | enum grep_pat_token token; | ||
184 | const char *pattern; | ||
185 | regex_t regexp; | ||
186 | }; | ||
187 | |||
188 | enum grep_expr_node { | ||
189 | GREP_NODE_ATOM, | ||
190 | GREP_NODE_NOT, | ||
191 | GREP_NODE_AND, | ||
192 | GREP_NODE_OR, | ||
193 | }; | ||
194 | |||
195 | struct grep_opt { | ||
196 | struct grep_pat *pattern_list; | ||
197 | struct grep_pat **pattern_tail; | ||
198 | struct grep_expr *pattern_expression; | ||
199 | int prefix_length; | ||
200 | regex_t regexp; | ||
201 | unsigned linenum:1; | ||
202 | unsigned invert:1; | ||
203 | unsigned status_only:1; | ||
204 | unsigned name_only:1; | ||
205 | unsigned unmatch_name_only:1; | ||
206 | unsigned count:1; | ||
207 | unsigned word_regexp:1; | ||
208 | unsigned fixed:1; | ||
209 | unsigned all_match:1; | ||
210 | #define GREP_BINARY_DEFAULT 0 | ||
211 | #define GREP_BINARY_NOMATCH 1 | ||
212 | #define GREP_BINARY_TEXT 2 | ||
213 | unsigned binary:2; | ||
214 | unsigned extended:1; | ||
215 | unsigned relative:1; | ||
216 | unsigned pathname:1; | ||
217 | int regflags; | ||
218 | unsigned pre_context; | ||
219 | unsigned post_context; | ||
220 | }; | ||
221 | |||
222 | |||
223 | extern void compile_grep_patterns(struct grep_opt *opt); | ||
224 | extern void free_grep_patterns(struct grep_opt *opt); | ||
159 | 225 | ||
160 | 226 | ||
161 | /* | 227 | /* |
diff --git a/ui-log.c b/ui-log.c index f3b16e7..c353b2a 100644 --- a/ui-log.c +++ b/ui-log.c | |||
@@ -32,19 +32,26 @@ void print_commit(struct commit *commit) | |||
32 | } | 32 | } |
33 | 33 | ||
34 | 34 | ||
35 | void cgit_print_log(const char *tip, int ofs, int cnt) | 35 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) |
36 | { | 36 | { |
37 | struct rev_info rev; | 37 | struct rev_info rev; |
38 | struct commit *commit; | 38 | struct commit *commit; |
39 | const char *argv[2] = {NULL, tip}; | 39 | const char *argv[3] = {NULL, tip, NULL}; |
40 | int argc = 2; | ||
40 | int i; | 41 | int i; |
41 | 42 | ||
43 | if (grep) | ||
44 | argv[argc++] = fmt("--grep=%s", grep); | ||
42 | init_revisions(&rev, NULL); | 45 | init_revisions(&rev, NULL); |
43 | rev.abbrev = DEFAULT_ABBREV; | 46 | rev.abbrev = DEFAULT_ABBREV; |
44 | rev.commit_format = CMIT_FMT_DEFAULT; | 47 | rev.commit_format = CMIT_FMT_DEFAULT; |
45 | rev.verbose_header = 1; | 48 | rev.verbose_header = 1; |
46 | rev.show_root_diff = 0; | 49 | rev.show_root_diff = 0; |
47 | setup_revisions(2, argv, &rev, NULL); | 50 | setup_revisions(argc, argv, &rev, NULL); |
51 | if (rev.grep_filter) { | ||
52 | rev.grep_filter->regflags |= REG_ICASE; | ||
53 | compile_grep_patterns(rev.grep_filter); | ||
54 | } | ||
48 | prepare_revision_walk(&rev); | 55 | prepare_revision_walk(&rev); |
49 | 56 | ||
50 | html("<h2>Log</h2>"); | 57 | html("<h2>Log</h2>"); |