Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 1 | /* ui-log.c: functions for log output |
| 2 | * |
Lukas Fleischer | f7f26f8 | 2014-01-08 15:10:49 +0100 | [diff] [blame] | 3 | * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
| 9 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 10 | #include "ui-log.h" |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 11 | #include "html.h" |
Lars Hjemli | a4d1ca1 | 2008-03-24 16:50:57 +0100 | [diff] [blame] | 12 | #include "ui-shared.h" |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 13 | #include "argv-array.h" |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 14 | |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 15 | static int files, add_lines, rem_lines, lines_counted; |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 16 | |
Johan Herland | 268b34a | 2010-11-15 18:39:51 +0100 | [diff] [blame] | 17 | /* |
| 18 | * The list of available column colors in the commit graph. |
| 19 | */ |
| 20 | static const char *column_colors_html[] = { |
| 21 | "<span class='column1'>", |
| 22 | "<span class='column2'>", |
| 23 | "<span class='column3'>", |
| 24 | "<span class='column4'>", |
| 25 | "<span class='column5'>", |
| 26 | "<span class='column6'>", |
| 27 | "</span>", |
| 28 | }; |
| 29 | |
| 30 | #define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1) |
| 31 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 32 | static void count_lines(char *line, int size) |
Lars Hjemli | 80e577c | 2007-05-13 17:03:27 +0200 | [diff] [blame] | 33 | { |
Lars Hjemli | d04c473 | 2007-11-06 00:35:12 +0100 | [diff] [blame] | 34 | if (size <= 0) |
| 35 | return; |
| 36 | |
| 37 | if (line[0] == '+') |
| 38 | add_lines++; |
| 39 | |
| 40 | else if (line[0] == '-') |
| 41 | rem_lines++; |
Lars Hjemli | 80e577c | 2007-05-13 17:03:27 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 44 | static void inspect_files(struct diff_filepair *pair) |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 45 | { |
Lars Hjemli | c495cf0 | 2009-01-31 10:40:40 +0100 | [diff] [blame] | 46 | unsigned long old_size = 0; |
| 47 | unsigned long new_size = 0; |
| 48 | int binary = 0; |
| 49 | |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 50 | files++; |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 51 | if (ctx.repo->enable_log_linecount) |
Lars Hjemli | c495cf0 | 2009-01-31 10:40:40 +0100 | [diff] [blame] | 52 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
Johan Herland | 2cc8b99 | 2010-06-24 17:52:57 +0200 | [diff] [blame] | 53 | &new_size, &binary, 0, ctx.qry.ignorews, |
| 54 | count_lines); |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 57 | void show_commit_decorations(struct commit *commit) |
| 58 | { |
Christian Hesse | 17838ec | 2014-12-19 00:28:34 -0700 | [diff] [blame] | 59 | const struct name_decoration *deco; |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 60 | static char buf[1024]; |
| 61 | |
| 62 | buf[sizeof(buf) - 1] = 0; |
Christian Hesse | 17838ec | 2014-12-19 00:28:34 -0700 | [diff] [blame] | 63 | deco = get_name_decoration(&commit->object); |
Tim Nordell | 499b239 | 2016-02-26 14:57:30 -0600 | [diff] [blame] | 64 | if (!deco) |
| 65 | return; |
John Keeping | 927060c | 2013-05-18 15:54:49 +0100 | [diff] [blame] | 66 | html("<span class='decoration'>"); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 67 | while (deco) { |
Tim Nordell | 59d8fa1 | 2016-02-26 14:58:41 -0600 | [diff] [blame] | 68 | strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1); |
| 69 | switch(deco->type) { |
| 70 | case DECORATION_NONE: |
| 71 | /* If the git-core doesn't recognize it, |
| 72 | * don't display anything. */ |
| 73 | break; |
| 74 | case DECORATION_REF_LOCAL: |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 75 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, |
Tim Nordell | 59d8fa1 | 2016-02-26 14:58:41 -0600 | [diff] [blame] | 76 | ctx.qry.vpath, 0, NULL, NULL, |
| 77 | ctx.qry.showmsg, 0); |
| 78 | break; |
| 79 | case DECORATION_REF_TAG: |
John Keeping | c422b9b | 2015-01-15 22:18:14 +0000 | [diff] [blame] | 80 | cgit_tag_link(buf, NULL, "tag-deco", buf); |
Tim Nordell | 59d8fa1 | 2016-02-26 14:58:41 -0600 | [diff] [blame] | 81 | break; |
| 82 | case DECORATION_REF_REMOTE: |
Georg Müller | 0b6a716 | 2012-01-03 15:30:50 +0000 | [diff] [blame] | 83 | if (!ctx.repo->enable_remote_branches) |
Tim Nordell | 59d8fa1 | 2016-02-26 14:58:41 -0600 | [diff] [blame] | 84 | break; |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 85 | cgit_log_link(buf, NULL, "remote-deco", NULL, |
Tim Nordell | 59d8fa1 | 2016-02-26 14:58:41 -0600 | [diff] [blame] | 86 | oid_to_hex(&commit->object.oid), |
| 87 | ctx.qry.vpath, 0, NULL, NULL, |
| 88 | ctx.qry.showmsg, 0); |
| 89 | break; |
| 90 | default: |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 91 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, |
Tim Nordell | 59d8fa1 | 2016-02-26 14:58:41 -0600 | [diff] [blame] | 92 | oid_to_hex(&commit->object.oid), |
| 93 | ctx.qry.vpath); |
| 94 | break; |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 95 | } |
| 96 | deco = deco->next; |
| 97 | } |
John Keeping | 927060c | 2013-05-18 15:54:49 +0100 | [diff] [blame] | 98 | html("</span>"); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 99 | } |
| 100 | |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 101 | static void handle_rename(struct diff_filepair *pair) |
| 102 | { |
| 103 | /* |
| 104 | * After we have seen a rename, we generate links to the previous |
| 105 | * name of the file so that commit & diff views get fed the path |
| 106 | * that is correct for the commit they are showing, avoiding the |
| 107 | * need to walk the entire history leading back to every commit we |
| 108 | * show in order detect renames. |
| 109 | */ |
| 110 | if (0 != strcmp(ctx.qry.vpath, pair->two->path)) { |
| 111 | free(ctx.qry.vpath); |
| 112 | ctx.qry.vpath = xstrdup(pair->two->path); |
| 113 | } |
| 114 | inspect_files(pair); |
| 115 | } |
| 116 | |
| 117 | static int show_commit(struct commit *commit, struct rev_info *revs) |
| 118 | { |
| 119 | struct commit_list *parents = commit->parents; |
| 120 | struct commit *parent; |
| 121 | int found = 0, saved_fmt; |
| 122 | unsigned saved_flags = revs->diffopt.flags; |
| 123 | |
| 124 | |
| 125 | /* Always show if we're not in "follow" mode with a single file. */ |
| 126 | if (!ctx.qry.follow) |
| 127 | return 1; |
| 128 | |
| 129 | /* |
| 130 | * In "follow" mode, we don't show merges. This is consistent with |
| 131 | * "git log --follow -- <file>". |
| 132 | */ |
| 133 | if (parents && parents->next) |
| 134 | return 0; |
| 135 | |
| 136 | /* |
| 137 | * If this is the root commit, do what rev_info tells us. |
| 138 | */ |
| 139 | if (!parents) |
| 140 | return revs->show_root_diff; |
| 141 | |
| 142 | /* When we get here we have precisely one parent. */ |
| 143 | parent = parents->item; |
John Keeping | baa5ad1 | 2016-01-16 11:03:05 +0000 | [diff] [blame] | 144 | /* If we can't parse the commit, let print_commit() report an error. */ |
| 145 | if (parse_commit(parent)) |
| 146 | return 1; |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 147 | |
| 148 | files = 0; |
| 149 | add_lines = 0; |
| 150 | rem_lines = 0; |
| 151 | |
| 152 | DIFF_OPT_SET(&revs->diffopt, RECURSIVE); |
Christian Hesse | 559ab5e | 2016-01-05 07:38:53 +0100 | [diff] [blame] | 153 | diff_tree_sha1(parent->tree->object.oid.hash, |
| 154 | commit->tree->object.oid.hash, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 155 | "", &revs->diffopt); |
| 156 | diffcore_std(&revs->diffopt); |
| 157 | |
| 158 | found = !diff_queue_is_empty(); |
| 159 | saved_fmt = revs->diffopt.output_format; |
| 160 | revs->diffopt.output_format = DIFF_FORMAT_CALLBACK; |
| 161 | revs->diffopt.format_callback = cgit_diff_tree_cb; |
| 162 | revs->diffopt.format_callback_data = handle_rename; |
| 163 | diff_flush(&revs->diffopt); |
| 164 | revs->diffopt.output_format = saved_fmt; |
| 165 | revs->diffopt.flags = saved_flags; |
| 166 | |
| 167 | lines_counted = 1; |
| 168 | return found; |
| 169 | } |
| 170 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 171 | static void print_commit(struct commit *commit, struct rev_info *revs) |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 172 | { |
Lars Hjemli | 2101e26 | 2006-12-15 18:17:36 +0100 | [diff] [blame] | 173 | struct commitinfo *info; |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 174 | int columns = revs->graph ? 4 : 3; |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 175 | struct strbuf graphbuf = STRBUF_INIT; |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 176 | struct strbuf msgbuf = STRBUF_INIT; |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 177 | |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 178 | if (ctx.repo->enable_log_filecount) |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 179 | columns++; |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 180 | if (ctx.repo->enable_log_linecount) |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 181 | columns++; |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 182 | |
| 183 | if (revs->graph) { |
| 184 | /* Advance graph until current commit */ |
| 185 | while (!graph_next_line(revs->graph, &graphbuf)) { |
| 186 | /* Print graph segment in otherwise empty table row */ |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 187 | html("<tr class='nohover'><td class='commitgraph'>"); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 188 | html(graphbuf.buf); |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 189 | htmlf("</td><td colspan='%d' /></tr>\n", columns); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 190 | strbuf_setlen(&graphbuf, 0); |
| 191 | } |
| 192 | /* Current commit's graph segment is now ready in graphbuf */ |
| 193 | } |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 194 | |
Lars Hjemli | 2101e26 | 2006-12-15 18:17:36 +0100 | [diff] [blame] | 195 | info = cgit_parse_commit(commit); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 196 | htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : ""); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 197 | |
| 198 | if (revs->graph) { |
| 199 | /* Print graph segment for current commit */ |
| 200 | html("<td class='commitgraph'>"); |
| 201 | html(graphbuf.buf); |
| 202 | html("</td>"); |
| 203 | strbuf_setlen(&graphbuf, 0); |
| 204 | } |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 205 | else { |
| 206 | html("<td>"); |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 207 | cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 208 | html("</td>"); |
| 209 | } |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 210 | |
| 211 | htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : ""); |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 212 | if (ctx.qry.showmsg) { |
| 213 | /* line-wrap long commit subjects instead of truncating them */ |
| 214 | size_t subject_len = strlen(info->subject); |
| 215 | |
| 216 | if (subject_len > ctx.cfg.max_msg_len && |
| 217 | ctx.cfg.max_msg_len >= 15) { |
| 218 | /* symbol for signaling line-wrap (in PAGE_ENCODING) */ |
| 219 | const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 }; |
| 220 | int i = ctx.cfg.max_msg_len - strlen(wrap_symbol); |
| 221 | |
| 222 | /* Rewind i to preceding space character */ |
| 223 | while (i > 0 && !isspace(info->subject[i])) |
| 224 | --i; |
| 225 | if (!i) /* Oops, zero spaces. Reset i */ |
| 226 | i = ctx.cfg.max_msg_len - strlen(wrap_symbol); |
| 227 | |
| 228 | /* add remainder starting at i to msgbuf */ |
| 229 | strbuf_add(&msgbuf, info->subject + i, subject_len - i); |
| 230 | strbuf_trim(&msgbuf); |
| 231 | strbuf_add(&msgbuf, "\n\n", 2); |
| 232 | |
| 233 | /* Place wrap_symbol at position i in info->subject */ |
| 234 | strcpy(info->subject + i, wrap_symbol); |
| 235 | } |
| 236 | } |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 237 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
Christian Hesse | 559ab5e | 2016-01-05 07:38:53 +0100 | [diff] [blame] | 238 | oid_to_hex(&commit->object.oid), ctx.qry.vpath); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 239 | show_commit_decorations(commit); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 240 | html("</td><td>"); |
Jason A. Donenfeld | 786609b | 2014-01-13 16:24:40 +0100 | [diff] [blame] | 241 | cgit_open_filter(ctx.repo->email_filter, info->author_email, "log"); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 242 | html_txt(info->author); |
Jason A. Donenfeld | a5e1553 | 2014-01-13 04:04:52 +0100 | [diff] [blame] | 243 | cgit_close_filter(ctx.repo->email_filter); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 244 | |
| 245 | if (revs->graph) { |
| 246 | html("</td><td>"); |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 247 | cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 248 | } |
| 249 | |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 250 | if (!lines_counted && (ctx.repo->enable_log_filecount || |
| 251 | ctx.repo->enable_log_linecount)) { |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 252 | files = 0; |
Lars Hjemli | d04c473 | 2007-11-06 00:35:12 +0100 | [diff] [blame] | 253 | add_lines = 0; |
| 254 | rem_lines = 0; |
Johan Herland | 1415f3f | 2010-09-30 20:15:14 +0200 | [diff] [blame] | 255 | cgit_diff_commit(commit, inspect_files, ctx.qry.vpath); |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 256 | } |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 257 | |
| 258 | if (ctx.repo->enable_log_filecount) |
| 259 | htmlf("</td><td>%d", files); |
| 260 | if (ctx.repo->enable_log_linecount) |
Christian Hesse | 4fb4986 | 2016-06-29 09:37:57 +0200 | [diff] [blame^] | 261 | htmlf("</td><td><span class='deletions'>-%d</span>/" |
| 262 | "<span class='insertions'>+%d</span>", rem_lines, add_lines); |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 263 | |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 264 | html("</td></tr>\n"); |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 265 | |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 266 | if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */ |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 267 | html("<tr class='nohover'>"); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 268 | |
| 269 | if (ctx.qry.showmsg) { |
| 270 | /* Concatenate commit message + notes in msgbuf */ |
| 271 | if (info->msg && *(info->msg)) { |
| 272 | strbuf_addstr(&msgbuf, info->msg); |
| 273 | strbuf_addch(&msgbuf, '\n'); |
| 274 | } |
Christian Hesse | 559ab5e | 2016-01-05 07:38:53 +0100 | [diff] [blame] | 275 | format_display_notes(commit->object.oid.hash, |
John Keeping | 849ecd9 | 2013-04-08 09:00:22 +0100 | [diff] [blame] | 276 | &msgbuf, PAGE_ENCODING, 0); |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 277 | strbuf_addch(&msgbuf, '\n'); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 278 | strbuf_ltrim(&msgbuf); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 279 | } |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 280 | |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 281 | if (revs->graph) { |
| 282 | int lines = 0; |
| 283 | |
| 284 | /* Calculate graph padding */ |
| 285 | if (ctx.qry.showmsg) { |
| 286 | /* Count #lines in commit message + notes */ |
| 287 | const char *p = msgbuf.buf; |
| 288 | lines = 1; |
| 289 | while ((p = strchr(p, '\n'))) { |
| 290 | p++; |
| 291 | lines++; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /* Print graph padding */ |
| 296 | html("<td class='commitgraph'>"); |
| 297 | while (lines > 0 || !graph_is_commit_finished(revs->graph)) { |
| 298 | if (graphbuf.len) |
| 299 | html("\n"); |
| 300 | strbuf_setlen(&graphbuf, 0); |
| 301 | graph_next_line(revs->graph, &graphbuf); |
| 302 | html(graphbuf.buf); |
| 303 | lines--; |
| 304 | } |
| 305 | html("</td>\n"); |
| 306 | } |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 307 | else |
| 308 | html("<td/>"); /* Empty 'Age' column */ |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 309 | |
| 310 | /* Print msgbuf into remainder of table row */ |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 311 | htmlf("<td colspan='%d'%s>\n", columns - (revs->graph ? 1 : 0), |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 312 | ctx.qry.showmsg ? " class='logmsg'" : ""); |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 313 | html_txt(msgbuf.buf); |
Lars Hjemli | ab67164 | 2008-11-29 19:11:26 +0100 | [diff] [blame] | 314 | html("</td></tr>\n"); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 315 | } |
Johan Herland | 5a36c2a | 2010-11-15 18:39:49 +0100 | [diff] [blame] | 316 | |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 317 | strbuf_release(&msgbuf); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 318 | strbuf_release(&graphbuf); |
Lars Hjemli | aaa24bd | 2006-12-16 14:58:20 +0100 | [diff] [blame] | 319 | cgit_free_commitinfo(info); |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 320 | } |
| 321 | |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 322 | static const char *disambiguate_ref(const char *ref, int *must_free_result) |
Lars Hjemli | a1b01b2 | 2008-12-03 17:34:23 +0100 | [diff] [blame] | 323 | { |
Christian Hesse | de83de2 | 2015-07-28 10:42:01 +0200 | [diff] [blame] | 324 | struct object_id oid; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 325 | struct strbuf longref = STRBUF_INIT; |
Lars Hjemli | a1b01b2 | 2008-12-03 17:34:23 +0100 | [diff] [blame] | 326 | |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 327 | strbuf_addf(&longref, "refs/heads/%s", ref); |
Christian Hesse | de83de2 | 2015-07-28 10:42:01 +0200 | [diff] [blame] | 328 | if (get_sha1(longref.buf, oid.hash) == 0) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 329 | *must_free_result = 1; |
| 330 | return strbuf_detach(&longref, NULL); |
| 331 | } |
Lars Hjemli | a1b01b2 | 2008-12-03 17:34:23 +0100 | [diff] [blame] | 332 | |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 333 | *must_free_result = 0; |
| 334 | strbuf_release(&longref); |
Lars Hjemli | a1b01b2 | 2008-12-03 17:34:23 +0100 | [diff] [blame] | 335 | return ref; |
| 336 | } |
Lars Hjemli | 2101e26 | 2006-12-15 18:17:36 +0100 | [diff] [blame] | 337 | |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 338 | static char *next_token(char **src) |
| 339 | { |
| 340 | char *result; |
| 341 | |
| 342 | if (!src || !*src) |
| 343 | return NULL; |
| 344 | while (isspace(**src)) |
| 345 | (*src)++; |
| 346 | if (!**src) |
| 347 | return NULL; |
| 348 | result = *src; |
| 349 | while (**src) { |
| 350 | if (isspace(**src)) { |
| 351 | **src = '\0'; |
| 352 | (*src)++; |
| 353 | break; |
| 354 | } |
| 355 | (*src)++; |
| 356 | } |
| 357 | return result; |
| 358 | } |
| 359 | |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 360 | 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] | 361 | char *path, int pager, int commit_graph, int commit_sort) |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 362 | { |
| 363 | struct rev_info rev; |
| 364 | struct commit *commit; |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 365 | struct argv_array rev_argv = ARGV_ARRAY_INIT; |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 366 | int i, columns = commit_graph ? 4 : 3; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 367 | int must_free_tip = 0; |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 368 | |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 369 | /* rev_argv.argv[0] will be ignored by setup_revisions */ |
| 370 | argv_array_push(&rev_argv, "log_rev_setup"); |
Lars Hjemli | 48dc003 | 2007-05-13 11:27:46 +0200 | [diff] [blame] | 371 | |
Lars Hjemli | cd79c16 | 2007-06-17 14:58:45 +0200 | [diff] [blame] | 372 | if (!tip) |
Lars Hjemli | a1b01b2 | 2008-12-03 17:34:23 +0100 | [diff] [blame] | 373 | tip = ctx.qry.head; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 374 | tip = disambiguate_ref(tip, &must_free_tip); |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 375 | argv_array_push(&rev_argv, tip); |
Lars Hjemli | cd79c16 | 2007-06-17 14:58:45 +0200 | [diff] [blame] | 376 | |
Johan Herland | 52558a6 | 2010-10-28 17:05:39 +0200 | [diff] [blame] | 377 | if (grep && pattern && *pattern) { |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 378 | pattern = xstrdup(pattern); |
Lars Hjemli | a579fb0 | 2010-06-19 14:32:37 +0200 | [diff] [blame] | 379 | if (!strcmp(grep, "grep") || !strcmp(grep, "author") || |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 380 | !strcmp(grep, "committer")) { |
Lukas Fleischer | d76c438 | 2013-11-22 13:30:58 +0100 | [diff] [blame] | 381 | argv_array_pushf(&rev_argv, "--%s=%s", grep, pattern); |
| 382 | } else if (!strcmp(grep, "range")) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 383 | char *arg; |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 384 | /* Split the pattern at whitespace and add each token |
| 385 | * as a revision expression. Do not accept other |
| 386 | * rev-list options. Also, replace the previously |
| 387 | * pushed tip (it's no longer relevant). |
| 388 | */ |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 389 | argv_array_pop(&rev_argv); |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 390 | while ((arg = next_token(&pattern))) { |
| 391 | if (*arg == '-') { |
| 392 | fprintf(stderr, "Bad range expr: %s\n", |
| 393 | arg); |
| 394 | break; |
| 395 | } |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 396 | argv_array_push(&rev_argv, arg); |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 397 | } |
| 398 | } |
Lars Hjemli | a579fb0 | 2010-06-19 14:32:37 +0200 | [diff] [blame] | 399 | } |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 400 | |
| 401 | if (!path || !ctx.cfg.enable_follow_links) { |
| 402 | /* |
| 403 | * If we don't have a path, "follow" is a no-op so make sure |
| 404 | * the variable is set to false to avoid needing to check |
| 405 | * both this and whether we have a path everywhere. |
| 406 | */ |
| 407 | ctx.qry.follow = 0; |
| 408 | } |
| 409 | |
| 410 | if (commit_graph && !ctx.qry.follow) { |
Lukas Fleischer | d76c438 | 2013-11-22 13:30:58 +0100 | [diff] [blame] | 411 | argv_array_push(&rev_argv, "--graph"); |
| 412 | argv_array_push(&rev_argv, "--color"); |
Johan Herland | 268b34a | 2010-11-15 18:39:51 +0100 | [diff] [blame] | 413 | graph_set_column_colors(column_colors_html, |
| 414 | COLUMN_COLORS_HTML_MAX); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 415 | } |
Lars Hjemli | 68ca032 | 2007-10-28 15:23:00 +0100 | [diff] [blame] | 416 | |
Lukas Fleischer | d76c438 | 2013-11-22 13:30:58 +0100 | [diff] [blame] | 417 | if (commit_sort == 1) |
| 418 | argv_array_push(&rev_argv, "--date-order"); |
| 419 | else if (commit_sort == 2) |
| 420 | argv_array_push(&rev_argv, "--topo-order"); |
Tobias Bieniek | 792f813 | 2012-10-13 16:10:30 +0200 | [diff] [blame] | 421 | |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 422 | if (path && ctx.qry.follow) |
| 423 | argv_array_push(&rev_argv, "--follow"); |
John Keeping | 4046e8e | 2014-06-28 15:55:06 +0200 | [diff] [blame] | 424 | argv_array_push(&rev_argv, "--"); |
| 425 | if (path) |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 426 | argv_array_push(&rev_argv, path); |
Lars Hjemli | a3c3c04 | 2010-11-09 20:53:36 +0100 | [diff] [blame] | 427 | |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 428 | init_revisions(&rev, NULL); |
| 429 | rev.abbrev = DEFAULT_ABBREV; |
| 430 | rev.commit_format = CMIT_FMT_DEFAULT; |
| 431 | rev.verbose_header = 1; |
| 432 | rev.show_root_diff = 0; |
John Keeping | 4046e8e | 2014-06-28 15:55:06 +0200 | [diff] [blame] | 433 | rev.ignore_missing = 1; |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 434 | rev.simplify_history = 1; |
Lukas Fleischer | 9973ef0 | 2013-11-22 13:24:52 +0100 | [diff] [blame] | 435 | setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL); |
Lars Hjemli | 45c49d6 | 2009-09-13 21:56:45 +0200 | [diff] [blame] | 436 | load_ref_decorations(DECORATE_FULL_REFS); |
Lars Hjemli | ef2dc55 | 2009-01-11 12:16:18 +0100 | [diff] [blame] | 437 | rev.show_decorations = 1; |
Lars Hjemli | b7f3378 | 2008-10-05 19:19:59 +0200 | [diff] [blame] | 438 | rev.grep_filter.regflags |= REG_ICASE; |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 439 | |
| 440 | rev.diffopt.detect_rename = 1; |
| 441 | rev.diffopt.rename_limit = ctx.cfg.renamelimit; |
| 442 | if (ctx.qry.ignorews) |
| 443 | DIFF_XDL_SET(&rev.diffopt, IGNORE_WHITESPACE); |
| 444 | |
Lars Hjemli | b7f3378 | 2008-10-05 19:19:59 +0200 | [diff] [blame] | 445 | compile_grep_patterns(&rev.grep_filter); |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 446 | prepare_revision_walk(&rev); |
| 447 | |
John Keeping | 23c17d8 | 2015-08-14 12:47:15 +0100 | [diff] [blame] | 448 | if (pager) { |
| 449 | cgit_print_layout_start(); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 450 | html("<table class='list nowrap'>"); |
John Keeping | 23c17d8 | 2015-08-14 12:47:15 +0100 | [diff] [blame] | 451 | } |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 452 | |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 453 | html("<tr class='nohover'>"); |
Johan Herland | ad23026 | 2010-11-15 18:39:52 +0100 | [diff] [blame] | 454 | if (commit_graph) |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 455 | html("<th></th>"); |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 456 | else |
| 457 | html("<th class='left'>Age</th>"); |
Johan Herland | 9a8d39c | 2010-11-15 18:39:50 +0100 | [diff] [blame] | 458 | html("<th class='left'>Commit message"); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 459 | if (pager) { |
| 460 | html(" ("); |
Justin Waters | 1383fe3 | 2009-01-09 17:35:10 -0500 | [diff] [blame] | 461 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, |
| 462 | NULL, ctx.qry.head, ctx.qry.sha1, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 463 | ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 464 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1, |
| 465 | ctx.qry.follow); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 466 | html(")"); |
| 467 | } |
| 468 | html("</th><th class='left'>Author</th>"); |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 469 | if (rev.graph) |
Johan Herland | c2bfd40 | 2010-11-15 18:39:53 +0100 | [diff] [blame] | 470 | html("<th class='left'>Age</th>"); |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 471 | if (ctx.repo->enable_log_filecount) { |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 472 | html("<th class='left'>Files</th>"); |
| 473 | columns++; |
Julius Plenz | 2e6721e | 2011-03-10 17:03:22 +0100 | [diff] [blame] | 474 | } |
| 475 | if (ctx.repo->enable_log_linecount) { |
| 476 | html("<th class='left'>Lines</th>"); |
| 477 | columns++; |
Lars Hjemli | e189344 | 2007-05-18 13:55:52 +0200 | [diff] [blame] | 478 | } |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 479 | html("</tr>\n"); |
Lars Hjemli | 420712a | 2006-12-14 00:40:34 +0100 | [diff] [blame] | 480 | |
| 481 | if (ofs<0) |
| 482 | ofs = 0; |
| 483 | |
John Keeping | da1d4c7 | 2015-08-12 16:41:34 +0100 | [diff] [blame] | 484 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; /* nop */) { |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 485 | if (show_commit(commit, &rev)) |
| 486 | i++; |
John Keeping | 865afe0 | 2014-07-27 11:56:19 +0100 | [diff] [blame] | 487 | free_commit_buffer(commit); |
Lars Hjemli | 420712a | 2006-12-14 00:40:34 +0100 | [diff] [blame] | 488 | free_commit_list(commit->parents); |
| 489 | commit->parents = NULL; |
| 490 | } |
| 491 | |
John Keeping | da1d4c7 | 2015-08-12 16:41:34 +0100 | [diff] [blame] | 492 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; /* nop */) { |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 493 | /* |
| 494 | * In "follow" mode, we must count the files and lines the |
| 495 | * first time we invoke diff on a given commit, and we need |
| 496 | * to do that to see if the commit touches the path we care |
| 497 | * about, so we do it in show_commit. Hence we must clear |
| 498 | * lines_counted here. |
| 499 | * |
| 500 | * This has the side effect of avoiding running diff twice |
| 501 | * when we are both following renames and showing file |
| 502 | * and/or line counts. |
| 503 | */ |
| 504 | lines_counted = 0; |
| 505 | if (show_commit(commit, &rev)) { |
| 506 | i++; |
| 507 | print_commit(commit, &rev); |
| 508 | } |
John Keeping | 865afe0 | 2014-07-27 11:56:19 +0100 | [diff] [blame] | 509 | free_commit_buffer(commit); |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 510 | free_commit_list(commit->parents); |
| 511 | commit->parents = NULL; |
| 512 | } |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 513 | if (pager) { |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 514 | html("</table><ul class='pager'>"); |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 515 | if (ofs > 0) { |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 516 | html("<li>"); |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 517 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 518 | ctx.qry.sha1, ctx.qry.vpath, |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 519 | ofs - cnt, ctx.qry.grep, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 520 | ctx.qry.search, ctx.qry.showmsg, |
| 521 | ctx.qry.follow); |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 522 | html("</li>"); |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 523 | } |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 524 | if ((commit = get_revision(&rev)) != NULL) { |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 525 | html("<li>"); |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 526 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 527 | ctx.qry.sha1, ctx.qry.vpath, |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 528 | ofs + cnt, ctx.qry.grep, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 529 | ctx.qry.search, ctx.qry.showmsg, |
| 530 | ctx.qry.follow); |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 531 | html("</li>"); |
Ondrej Jirman | a922615 | 2007-05-26 03:26:14 +0200 | [diff] [blame] | 532 | } |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 533 | html("</ul>"); |
John Keeping | 23c17d8 | 2015-08-14 12:47:15 +0100 | [diff] [blame] | 534 | cgit_print_layout_end(); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 535 | } else if ((commit = get_revision(&rev)) != NULL) { |
Lukas Fleischer | ef8a97d | 2013-03-05 15:42:14 +0100 | [diff] [blame] | 536 | htmlf("<tr class='nohover'><td colspan='%d'>", columns); |
Johan Herland | afc4072 | 2010-06-11 14:50:47 +0200 | [diff] [blame] | 537 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 538 | ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, |
| 539 | ctx.qry.follow); |
Lars Hjemli | 5764fe9 | 2008-04-14 22:13:38 +0200 | [diff] [blame] | 540 | html("</td></tr>\n"); |
Lars Hjemli | 420712a | 2006-12-14 00:40:34 +0100 | [diff] [blame] | 541 | } |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 542 | |
| 543 | /* If we allocated tip then it is safe to cast away const. */ |
| 544 | if (must_free_tip) |
| 545 | free((char*) tip); |
Lars Hjemli | d14c5f6 | 2006-12-11 17:04:19 +0100 | [diff] [blame] | 546 | } |