Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 1 | /* ui-log.c: functions for log output |
| 2 | * |
| 3 | * Copyright (C) 2006 Lars Hjemli |
| 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
| 9 | #include "cgit.h" |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 10 | #include "html.h" |
Lars Hjemli | a4d1ca1 | 2008-03-24 16:50:57 +0100 | [diff] [blame] | 11 | #include "ui-shared.h" |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 12 | #include "vector.h" |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 13 | |
Lars Hjemli | d04c473 | 2007-11-06 00:35:12 +0100 | [diff] [blame] | 14 | int files, add_lines, rem_lines; |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 15 | |
Johan Herland | 268b34a | 2010-11-15 18:39:51 +0100 | [diff] [blame] | 16 | /* |
| 17 | * The list of available column colors in the commit graph. |
| 18 | */ |
| 19 | static const char *column_colors_html[] = { |
| 20 | "<span class='column1'>", |
| 21 | "<span class='column2'>", |
| 22 | "<span class='column3'>", |
| 23 | "<span class='column4'>", |
| 24 | "<span class='column5'>", |
| 25 | "<span class='column6'>", |
| 26 | "</span>", |
| 27 | }; |
| 28 | |
| 29 | #define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1) |
| 30 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 31 | static void count_lines(char *line, int size) |
Lars Hjemli | 80e577c | 2007-05-13 17:03:27 +0200 | [diff] [blame] | 32 | { |
Lars Hjemli | d04c473 | 2007-11-06 00:35:12 +0100 | [diff] [blame] | 33 | if (size <= 0) |
| 34 | return; |
| 35 | |
| 36 | if (line[0] == '+') |
| 37 | add_lines++; |
| 38 | |
| 39 | else if (line[0] == '-') |
| 40 | rem_lines++; |
Lars Hjemli | 80e577c | 2007-05-13 17:03:27 +0200 | [diff] [blame] | 41 | } |
| 42 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 43 | static void inspect_files(struct diff_filepair *pair) |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 44 | { |
Lars Hjemli | c495cf0 | 2009-01-31 10:40:40 +0100 | [diff] [blame] | 45 | unsigned long old_size = 0; |
| 46 | unsigned long new_size = 0; |
| 47 | int binary = 0; |
| 48 | |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 49 | files++; |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 50 | if (ctx.repo->enable_log_linecount) |
Lars Hjemli | c495cf0 | 2009-01-31 10:40:40 +0100 | [diff] [blame] | 51 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
Johan Herland | 2cc8b99 | 2010-06-24 17:52:57 +0200 | [diff] [blame] | 52 | &new_size, &binary, 0, ctx.qry.ignorews, |
| 53 | count_lines); |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 56 | void show_commit_decorations(struct commit *commit) |
| 57 | { |
| 58 | struct name_decoration *deco; |
| 59 | static char buf[1024]; |
| 60 | |
| 61 | buf[sizeof(buf) - 1] = 0; |
| 62 | deco = lookup_decoration(&name_decoration, &commit->object); |
| 63 | while (deco) { |
| 64 | if (!prefixcmp(deco->name, "refs/heads/")) { |
| 65 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 66 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, |
| 67 | ctx.qry.vpath, 0, NULL, NULL, |
| 68 | ctx.qry.showmsg); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 69 | } |
| 70 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { |
| 71 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); |
| 72 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
| 73 | } |
Lars Hjemli | 0730ee6 | 2009-08-16 19:52:27 +0200 | [diff] [blame] | 74 | else if (!prefixcmp(deco->name, "refs/tags/")) { |
| 75 | strncpy(buf, deco->name + 10, sizeof(buf) - 1); |
| 76 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
| 77 | } |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 78 | else if (!prefixcmp(deco->name, "refs/remotes/")) { |
Georg Müller | 0b6a716 | 2012-01-03 15:30:50 +0000 | [diff] [blame] | 79 | if (!ctx.repo->enable_remote_branches) |
| 80 | goto next; |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 81 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); |
| 82 | cgit_log_link(buf, NULL, "remote-deco", NULL, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 83 | sha1_to_hex(commit->object.sha1), |
| 84 | ctx.qry.vpath, 0, NULL, NULL, |
| 85 | ctx.qry.showmsg); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 86 | } |
| 87 | else { |
| 88 | strncpy(buf, deco->name, sizeof(buf) - 1); |
| 89 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 90 | sha1_to_hex(commit->object.sha1), |
| 91 | ctx.qry.vpath, 0); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 92 | } |
Georg Müller | 0b6a716 | 2012-01-03 15:30:50 +0000 | [diff] [blame] | 93 | next: |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 94 | deco = deco->next; |
| 95 | } |
| 96 | } |
| 97 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 98 | static void print_commit(struct commit *commit, struct rev_info *revs) |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 99 | { |
Lars Hjemli | 2101e26 | 2006-12-15 18:17:36 +0100 | [diff] [blame] | 100 | struct commitinfo *info; |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 101 | int columns = revs->graph ? 4 : 3; |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 102 | struct strbuf graphbuf = STRBUF_INIT; |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 103 | struct strbuf msgbuf = STRBUF_INIT; |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 104 | |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 105 | if (ctx.repo->enable_log_filecount) |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 106 | columns++; |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 107 | if (ctx.repo->enable_log_linecount) |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 108 | columns++; |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 109 | |
| 110 | if (revs->graph) { |
| 111 | /* Advance graph until current commit */ |
| 112 | while (!graph_next_line(revs->graph, &graphbuf)) { |
| 113 | /* Print graph segment in otherwise empty table row */ |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 114 | html("<tr class='nohover'><td class='commitgraph'>"); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 115 | html(graphbuf.buf); |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 116 | htmlf("</td><td colspan='%d' /></tr>\n", columns); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 117 | strbuf_setlen(&graphbuf, 0); |
| 118 | } |
| 119 | /* Current commit's graph segment is now ready in graphbuf */ |
| 120 | } |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 121 | |
Lars Hjemli | 2101e26 | 2006-12-15 18:17:36 +0100 | [diff] [blame] | 122 | info = cgit_parse_commit(commit); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 123 | htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : ""); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 124 | |
| 125 | if (revs->graph) { |
| 126 | /* Print graph segment for current commit */ |
| 127 | html("<td class='commitgraph'>"); |
| 128 | html(graphbuf.buf); |
| 129 | html("</td>"); |
| 130 | strbuf_setlen(&graphbuf, 0); |
| 131 | } |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 132 | else { |
| 133 | html("<td>"); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 134 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 135 | html("</td>"); |
| 136 | } |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 137 | |
| 138 | htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : ""); |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 139 | if (ctx.qry.showmsg) { |
| 140 | /* line-wrap long commit subjects instead of truncating them */ |
| 141 | size_t subject_len = strlen(info->subject); |
| 142 | |
| 143 | if (subject_len > ctx.cfg.max_msg_len && |
| 144 | ctx.cfg.max_msg_len >= 15) { |
| 145 | /* symbol for signaling line-wrap (in PAGE_ENCODING) */ |
| 146 | const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 }; |
| 147 | int i = ctx.cfg.max_msg_len - strlen(wrap_symbol); |
| 148 | |
| 149 | /* Rewind i to preceding space character */ |
| 150 | while (i > 0 && !isspace(info->subject[i])) |
| 151 | --i; |
| 152 | if (!i) /* Oops, zero spaces. Reset i */ |
| 153 | i = ctx.cfg.max_msg_len - strlen(wrap_symbol); |
| 154 | |
| 155 | /* add remainder starting at i to msgbuf */ |
| 156 | strbuf_add(&msgbuf, info->subject + i, subject_len - i); |
| 157 | strbuf_trim(&msgbuf); |
| 158 | strbuf_add(&msgbuf, "\n\n", 2); |
| 159 | |
| 160 | /* Place wrap_symbol at position i in info->subject */ |
| 161 | strcpy(info->subject + i, wrap_symbol); |
| 162 | } |
| 163 | } |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 164 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 165 | sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 166 | show_commit_decorations(commit); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 167 | html("</td><td>"); |
| 168 | html_txt(info->author); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 169 | |
| 170 | if (revs->graph) { |
| 171 | html("</td><td>"); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 172 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 175 | if (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount) { |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 176 | files = 0; |
Lars Hjemli | d04c473 | 2007-11-06 00:35:12 +0100 | [diff] [blame] | 177 | add_lines = 0; |
| 178 | rem_lines = 0; |
Johan Herland | 1415f3f | 2010-09-30 20:15:14 +0200 | [diff] [blame] | 179 | cgit_diff_commit(commit, inspect_files, ctx.qry.vpath); |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 180 | } |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 181 | |
| 182 | if (ctx.repo->enable_log_filecount) |
| 183 | htmlf("</td><td>%d", files); |
| 184 | if (ctx.repo->enable_log_linecount) |
| 185 | htmlf("</td><td>-%d/+%d", rem_lines, add_lines); |
| 186 | |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 187 | html("</td></tr>\n"); |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 188 | |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 189 | if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */ |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 190 | html("<tr class='nohover'>"); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 191 | |
| 192 | if (ctx.qry.showmsg) { |
| 193 | /* Concatenate commit message + notes in msgbuf */ |
| 194 | if (info->msg && *(info->msg)) { |
| 195 | strbuf_addstr(&msgbuf, info->msg); |
| 196 | strbuf_addch(&msgbuf, '\n'); |
| 197 | } |
John Keeping | 849ecd9 | 2013-04-08 09:00:22 +0100 | [diff] [blame] | 198 | format_display_notes(commit->object.sha1, |
| 199 | &msgbuf, PAGE_ENCODING, 0); |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 200 | strbuf_addch(&msgbuf, '\n'); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 201 | strbuf_ltrim(&msgbuf); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 202 | } |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 203 | |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 204 | if (revs->graph) { |
| 205 | int lines = 0; |
| 206 | |
| 207 | /* Calculate graph padding */ |
| 208 | if (ctx.qry.showmsg) { |
| 209 | /* Count #lines in commit message + notes */ |
| 210 | const char *p = msgbuf.buf; |
| 211 | lines = 1; |
| 212 | while ((p = strchr(p, '\n'))) { |
| 213 | p++; |
| 214 | lines++; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /* Print graph padding */ |
| 219 | html("<td class='commitgraph'>"); |
| 220 | while (lines > 0 || !graph_is_commit_finished(revs->graph)) { |
| 221 | if (graphbuf.len) |
| 222 | html("\n"); |
| 223 | strbuf_setlen(&graphbuf, 0); |
| 224 | graph_next_line(revs->graph, &graphbuf); |
| 225 | html(graphbuf.buf); |
| 226 | lines--; |
| 227 | } |
| 228 | html("</td>\n"); |
| 229 | } |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 230 | else |
| 231 | html("<td/>"); /* Empty 'Age' column */ |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 232 | |
| 233 | /* Print msgbuf into remainder of table row */ |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 234 | htmlf("<td colspan='%d'%s>\n", columns - (revs->graph ? 1 : 0), |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 235 | ctx.qry.showmsg ? " class='logmsg'" : ""); |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 236 | html_txt(msgbuf.buf); |
Lars Hjemli | ab67164 | 2008-11-29 19:11:26 +0100 | [diff] [blame] | 237 | html("</td></tr>\n"); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 238 | } |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 239 | |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 240 | strbuf_release(&msgbuf); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 241 | strbuf_release(&graphbuf); |
Lars Hjemli | aaa24bd | 2006-12-16 14:58:20 +0100 | [diff] [blame] | 242 | cgit_free_commitinfo(info); |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Lars Hjemli | a1b01b2 | 2008-12-03 17:34:23 +0100 | [diff] [blame] | 245 | static const char *disambiguate_ref(const char *ref) |
| 246 | { |
| 247 | unsigned char sha1[20]; |
| 248 | const char *longref; |
| 249 | |
| 250 | longref = fmt("refs/heads/%s", ref); |
| 251 | if (get_sha1(longref, sha1) == 0) |
| 252 | return longref; |
| 253 | |
| 254 | return ref; |
| 255 | } |
Lars Hjemli | 2101e26 | 2006-12-15 18:17:36 +0100 | [diff] [blame] | 256 | |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 257 | static char *next_token(char **src) |
| 258 | { |
| 259 | char *result; |
| 260 | |
| 261 | if (!src || !*src) |
| 262 | return NULL; |
| 263 | while (isspace(**src)) |
| 264 | (*src)++; |
| 265 | if (!**src) |
| 266 | return NULL; |
| 267 | result = *src; |
| 268 | while (**src) { |
| 269 | if (isspace(**src)) { |
| 270 | **src = '\0'; |
| 271 | (*src)++; |
| 272 | break; |
| 273 | } |
| 274 | (*src)++; |
| 275 | } |
| 276 | return result; |
| 277 | } |
| 278 | |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 279 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, |
Tobias Bieniek | 792f813 | 2012-10-13 16:10:30 +0200 | [diff] [blame] | 280 | char *path, int pager, int commit_graph, int commit_sort) |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 281 | { |
| 282 | struct rev_info rev; |
| 283 | struct commit *commit; |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 284 | struct vector vec = VECTOR_INIT(char *); |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 285 | int i, columns = commit_graph ? 4 : 3; |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 286 | char *arg; |
| 287 | |
| 288 | /* First argv is NULL */ |
| 289 | vector_push(&vec, NULL, 0); |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 290 | |
Lars Hjemli | cd79c16 | 2007-06-17 14:58:45 +0200 | [diff] [blame] | 291 | if (!tip) |
Lars Hjemli | a1b01b2 | 2008-12-03 17:34:23 +0100 | [diff] [blame] | 292 | tip = ctx.qry.head; |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 293 | tip = disambiguate_ref(tip); |
| 294 | vector_push(&vec, &tip, 0); |
Lars Hjemli | cd79c16 | 2007-06-17 14:58:45 +0200 | [diff] [blame] | 295 | |
Johan Herland | 52558a6 | 2010-10-28 17:05:39 +0200 | [diff] [blame] | 296 | if (grep && pattern && *pattern) { |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 297 | pattern = xstrdup(pattern); |
Lars Hjemli | a579fb0 | 2010-06-19 14:32:37 +0200 | [diff] [blame] | 298 | if (!strcmp(grep, "grep") || !strcmp(grep, "author") || |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 299 | !strcmp(grep, "committer")) { |
| 300 | arg = fmt("--%s=%s", grep, pattern); |
| 301 | vector_push(&vec, &arg, 0); |
| 302 | } |
| 303 | if (!strcmp(grep, "range")) { |
| 304 | /* Split the pattern at whitespace and add each token |
| 305 | * as a revision expression. Do not accept other |
| 306 | * rev-list options. Also, replace the previously |
| 307 | * pushed tip (it's no longer relevant). |
| 308 | */ |
| 309 | vec.count--; |
| 310 | while ((arg = next_token(&pattern))) { |
| 311 | if (*arg == '-') { |
| 312 | fprintf(stderr, "Bad range expr: %s\n", |
| 313 | arg); |
| 314 | break; |
| 315 | } |
| 316 | vector_push(&vec, &arg, 0); |
| 317 | } |
| 318 | } |
Lars Hjemli | a579fb0 | 2010-06-19 14:32:37 +0200 | [diff] [blame] | 319 | } |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 320 | if (commit_graph) { |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 321 | static const char *graph_arg = "--graph"; |
Johan Herland | 268b34a | 2010-11-15 18:39:51 +0100 | [diff] [blame] | 322 | static const char *color_arg = "--color"; |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 323 | vector_push(&vec, &graph_arg, 0); |
Johan Herland | 268b34a | 2010-11-15 18:39:51 +0100 | [diff] [blame] | 324 | vector_push(&vec, &color_arg, 0); |
| 325 | graph_set_column_colors(column_colors_html, |
| 326 | COLUMN_COLORS_HTML_MAX); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 327 | } |
Lars Hjemli | 68ca032 | 2007-10-28 15:23:00 +0100 | [diff] [blame] | 328 | |
Tobias Bieniek | 792f813 | 2012-10-13 16:10:30 +0200 | [diff] [blame] | 329 | if (commit_sort == 1) { |
| 330 | static const char *date_order_arg = "--date-order"; |
| 331 | vector_push(&vec, &date_order_arg, 0); |
| 332 | } else if (commit_sort == 2) { |
| 333 | static const char *topo_order_arg = "--topo-order"; |
| 334 | vector_push(&vec, &topo_order_arg, 0); |
| 335 | } |
| 336 | |
Lars Hjemli | 9fb53af | 2007-05-14 11:10:59 +0200 | [diff] [blame] | 337 | if (path) { |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 338 | arg = "--"; |
| 339 | vector_push(&vec, &arg, 0); |
| 340 | vector_push(&vec, &path, 0); |
Lars Hjemli | 9fb53af | 2007-05-14 11:10:59 +0200 | [diff] [blame] | 341 | } |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 342 | |
| 343 | /* Make sure the vector is NULL-terminated */ |
| 344 | vector_push(&vec, NULL, 0); |
| 345 | vec.count--; |
| 346 | |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 347 | init_revisions(&rev, NULL); |
| 348 | rev.abbrev = DEFAULT_ABBREV; |
| 349 | rev.commit_format = CMIT_FMT_DEFAULT; |
| 350 | rev.verbose_header = 1; |
| 351 | rev.show_root_diff = 0; |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 352 | setup_revisions(vec.count, vec.data, &rev, NULL); |
Lars Hjemli | 45c49d6 | 2009-09-13 21:56:45 +0200 | [diff] [blame] | 353 | load_ref_decorations(DECORATE_FULL_REFS); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 354 | rev.show_decorations = 1; |
Lars Hjemli | b7f3378 | 2008-10-05 19:19:59 +0200 | [diff] [blame] | 355 | rev.grep_filter.regflags |= REG_ICASE; |
| 356 | compile_grep_patterns(&rev.grep_filter); |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 357 | prepare_revision_walk(&rev); |
| 358 | |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 359 | if (pager) |
| 360 | html("<table class='list nowrap'>"); |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 361 | |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 362 | html("<tr class='nohover'>"); |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 363 | if (commit_graph) |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 364 | html("<th></th>"); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 365 | else |
| 366 | html("<th class='left'>Age</th>"); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 367 | html("<th class='left'>Commit message"); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 368 | if (pager) { |
| 369 | html(" ("); |
Justin Waters | 1383fe3 | 2009-01-09 17:35:10 -0500 | [diff] [blame] | 370 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, |
| 371 | NULL, ctx.qry.head, ctx.qry.sha1, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 372 | ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 373 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); |
| 374 | html(")"); |
| 375 | } |
| 376 | html("</th><th class='left'>Author</th>"); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 377 | if (commit_graph) |
| 378 | html("<th class='left'>Age</th>"); |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 379 | if (ctx.repo->enable_log_filecount) { |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 380 | html("<th class='left'>Files</th>"); |
| 381 | columns++; |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 382 | } |
| 383 | if (ctx.repo->enable_log_linecount) { |
| 384 | html("<th class='left'>Lines</th>"); |
| 385 | columns++; |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 386 | } |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 387 | html("</tr>\n"); |
Lars Hjemli | 420712a | 2006-12-14 00:40:34 +0100 | [diff] [blame] | 388 | |
| 389 | if (ofs<0) |
| 390 | ofs = 0; |
| 391 | |
| 392 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
| 393 | free(commit->buffer); |
| 394 | commit->buffer = NULL; |
| 395 | free_commit_list(commit->parents); |
| 396 | commit->parents = NULL; |
| 397 | } |
| 398 | |
John Keeping | 849ecd9 | 2013-04-08 09:00:22 +0100 | [diff] [blame] | 399 | init_display_notes(NULL); |
Lars Hjemli | 420712a | 2006-12-14 00:40:34 +0100 | [diff] [blame] | 400 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 401 | print_commit(commit, &rev); |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 402 | free(commit->buffer); |
| 403 | commit->buffer = NULL; |
| 404 | free_commit_list(commit->parents); |
| 405 | commit->parents = NULL; |
| 406 | } |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 407 | if (pager) { |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 408 | html("</table><ul class='pager'>"); |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 409 | if (ofs > 0) { |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 410 | html("<li>"); |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 411 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 412 | ctx.qry.sha1, ctx.qry.vpath, |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 413 | ofs - cnt, ctx.qry.grep, |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 414 | ctx.qry.search, ctx.qry.showmsg); |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 415 | html("</li>"); |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 416 | } |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 417 | if ((commit = get_revision(&rev)) != NULL) { |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 418 | html("<li>"); |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 419 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 420 | ctx.qry.sha1, ctx.qry.vpath, |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 421 | ofs + cnt, ctx.qry.grep, |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 422 | ctx.qry.search, ctx.qry.showmsg); |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 423 | html("</li>"); |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 424 | } |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 425 | html("</ul>"); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 426 | } else if ((commit = get_revision(&rev)) != NULL) { |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 427 | htmlf("<tr class='nohover'><td colspan='%d'>", columns); |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 428 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, |
| 429 | ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 430 | html("</td></tr>\n"); |
Lars Hjemli | 420712a | 2006-12-14 00:40:34 +0100 | [diff] [blame] | 431 | } |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 432 | } |