Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "commit.h" |
Junio C Hamano | c4e05b1 | 2006-04-10 18:14:54 -0700 | [diff] [blame] | 3 | #include "diff.h" |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 4 | #include "revision.h" |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 5 | #include "list-objects.h" |
Linus Torvalds | 5fb61b8 | 2006-05-18 14:19:20 -0700 | [diff] [blame] | 6 | #include "builtin.h" |
Christian Couder | 50e62a8 | 2007-10-22 07:47:56 +0200 | [diff] [blame] | 7 | #include "log-tree.h" |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 8 | #include "graph.h" |
Christian Couder | a2ad79c | 2009-03-26 05:55:24 +0100 | [diff] [blame] | 9 | #include "bisect.h" |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 11 | static const char rev_list_usage[] = |
Stephan Beyer | 1b1dd23 | 2008-07-13 15:36:15 +0200 | [diff] [blame] | 12 | "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 13 | " limiting output:\n" |
Štěpán Němec | 62b4698 | 2010-10-08 19:31:15 +0200 | [diff] [blame] | 14 | " --max-count=<n>\n" |
| 15 | " --max-age=<epoch>\n" |
| 16 | " --min-age=<epoch>\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 17 | " --sparse\n" |
| 18 | " --no-merges\n" |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 19 | " --min-parents=<n>\n" |
| 20 | " --no-min-parents\n" |
| 21 | " --max-parents=<n>\n" |
| 22 | " --no-max-parents\n" |
Junio C Hamano | 93b74bc | 2006-01-27 01:39:24 -0800 | [diff] [blame] | 23 | " --remove-empty\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 24 | " --all\n" |
Uwe Kleine-König | a5aa930 | 2008-02-28 08:24:25 +0100 | [diff] [blame] | 25 | " --branches\n" |
| 26 | " --tags\n" |
| 27 | " --remotes\n" |
Junio C Hamano | 42cabc3 | 2006-09-05 21:39:02 -0700 | [diff] [blame] | 28 | " --stdin\n" |
Shawn O. Pearce | 2735089 | 2007-11-11 02:29:41 -0500 | [diff] [blame] | 29 | " --quiet\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 30 | " ordering output:\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 31 | " --topo-order\n" |
Junio C Hamano | 4c8725f | 2006-02-15 22:05:33 -0800 | [diff] [blame] | 32 | " --date-order\n" |
Kevin Ballard | 7ccd366 | 2008-03-19 02:16:28 -0400 | [diff] [blame] | 33 | " --reverse\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 34 | " formatting output:\n" |
| 35 | " --parents\n" |
Junio C Hamano | 72276a3 | 2008-04-03 23:01:47 -0700 | [diff] [blame] | 36 | " --children\n" |
Junio C Hamano | c649657 | 2006-02-19 03:32:31 -0800 | [diff] [blame] | 37 | " --objects | --objects-edge\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 38 | " --unpacked\n" |
| 39 | " --header | --pretty\n" |
Štěpán Němec | 62b4698 | 2010-10-08 19:31:15 +0200 | [diff] [blame] | 40 | " --abbrev=<n> | --no-abbrev\n" |
Junio C Hamano | 5c51c98 | 2006-04-06 21:32:36 -0700 | [diff] [blame] | 41 | " --abbrev-commit\n" |
Brian Gernhardt | b24bace | 2007-04-05 10:53:07 -0400 | [diff] [blame] | 42 | " --left-right\n" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 43 | " special purpose:\n" |
Junio C Hamano | 457f08a | 2007-03-21 22:15:54 -0700 | [diff] [blame] | 44 | " --bisect\n" |
Christian Couder | 50e62a8 | 2007-10-22 07:47:56 +0200 | [diff] [blame] | 45 | " --bisect-vars\n" |
| 46 | " --bisect-all" |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 47 | ; |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 48 | |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 49 | static void finish_commit(struct commit *commit, void *data); |
| 50 | static void show_commit(struct commit *commit, void *data) |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 51 | { |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 52 | struct rev_list_info *info = data; |
| 53 | struct rev_info *revs = info->revs; |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 54 | |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 55 | if (info->flags & REV_LIST_QUIET) { |
| 56 | finish_commit(commit, data); |
| 57 | return; |
| 58 | } |
| 59 | |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 60 | graph_show_commit(revs->graph); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 61 | |
Thomas Rast | f69c501 | 2010-06-10 13:47:23 +0200 | [diff] [blame] | 62 | if (revs->count) { |
Michael J Gruber | b388e14 | 2011-04-26 10:24:29 +0200 | [diff] [blame] | 63 | if (commit->object.flags & PATCHSAME) |
| 64 | revs->count_same++; |
| 65 | else if (commit->object.flags & SYMMETRIC_LEFT) |
Thomas Rast | f69c501 | 2010-06-10 13:47:23 +0200 | [diff] [blame] | 66 | revs->count_left++; |
| 67 | else |
| 68 | revs->count_right++; |
| 69 | finish_commit(commit, data); |
| 70 | return; |
| 71 | } |
| 72 | |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 73 | if (info->show_timestamp) |
Junio C Hamano | dc68c4f | 2006-03-22 00:22:00 -0800 | [diff] [blame] | 74 | printf("%lu ", commit->date); |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 75 | if (info->header_prefix) |
| 76 | fputs(info->header_prefix, stdout); |
Adam Simpkins | 7528f27 | 2008-05-25 00:07:21 -0700 | [diff] [blame] | 77 | |
Michael J Gruber | 1df2d65 | 2011-03-07 13:31:39 +0100 | [diff] [blame] | 78 | if (!revs->graph) |
| 79 | fputs(get_revision_mark(revs, commit), stdout); |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 80 | if (revs->abbrev_commit && revs->abbrev) |
| 81 | fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev), |
Junio C Hamano | 7594c4b | 2006-04-15 23:48:27 -0700 | [diff] [blame] | 82 | stdout); |
Junio C Hamano | 5c51c98 | 2006-04-06 21:32:36 -0700 | [diff] [blame] | 83 | else |
| 84 | fputs(sha1_to_hex(commit->object.sha1), stdout); |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 85 | if (revs->print_parents) { |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 86 | struct commit_list *parents = commit->parents; |
| 87 | while (parents) { |
Junio C Hamano | 1ed8415 | 2007-07-08 19:05:31 -0700 | [diff] [blame] | 88 | printf(" %s", sha1_to_hex(parents->item->object.sha1)); |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 89 | parents = parents->next; |
| 90 | } |
| 91 | } |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 92 | if (revs->children.name) { |
Junio C Hamano | 72276a3 | 2008-04-03 23:01:47 -0700 | [diff] [blame] | 93 | struct commit_list *children; |
| 94 | |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 95 | children = lookup_decoration(&revs->children, &commit->object); |
Junio C Hamano | 72276a3 | 2008-04-03 23:01:47 -0700 | [diff] [blame] | 96 | while (children) { |
| 97 | printf(" %s", sha1_to_hex(children->item->object.sha1)); |
| 98 | children = children->next; |
| 99 | } |
| 100 | } |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 101 | show_decorations(revs, commit); |
| 102 | if (revs->commit_format == CMIT_FMT_ONELINE) |
Junio C Hamano | d87449c | 2005-08-08 22:15:40 -0700 | [diff] [blame] | 103 | putchar(' '); |
| 104 | else |
| 105 | putchar('\n'); |
| 106 | |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 107 | if (revs->verbose_header && commit->buffer) { |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 108 | struct strbuf buf = STRBUF_INIT; |
Thomas Rast | dd2e794 | 2009-10-19 17:48:08 +0200 | [diff] [blame] | 109 | struct pretty_print_context ctx = {0}; |
| 110 | ctx.abbrev = revs->abbrev; |
| 111 | ctx.date_mode = revs->date_mode; |
Jeff King | f026c75 | 2012-05-04 01:25:18 -0400 | [diff] [blame] | 112 | ctx.date_mode_explicit = revs->date_mode_explicit; |
Jeff King | 6bf1394 | 2011-05-26 18:27:49 -0400 | [diff] [blame] | 113 | ctx.fmt = revs->commit_format; |
| 114 | pretty_print_commit(&ctx, commit, &buf); |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 115 | if (revs->graph) { |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 116 | if (buf.len) { |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 117 | if (revs->commit_format != CMIT_FMT_ONELINE) |
| 118 | graph_show_oneline(revs->graph); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 119 | |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 120 | graph_show_commit_msg(revs->graph, &buf); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * Add a newline after the commit message. |
| 124 | * |
| 125 | * Usually, this newline produces a blank |
| 126 | * padding line between entries, in which case |
| 127 | * we need to add graph padding on this line. |
| 128 | * |
| 129 | * However, the commit message may not end in a |
| 130 | * newline. In this case the newline simply |
| 131 | * ends the last line of the commit message, |
| 132 | * and we don't need any graph output. (This |
| 133 | * always happens with CMIT_FMT_ONELINE, and it |
| 134 | * happens with CMIT_FMT_USERFORMAT when the |
| 135 | * format doesn't explicitly end in a newline.) |
| 136 | */ |
| 137 | if (buf.len && buf.buf[buf.len - 1] == '\n') |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 138 | graph_show_padding(revs->graph); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 139 | putchar('\n'); |
| 140 | } else { |
| 141 | /* |
| 142 | * If the message buffer is empty, just show |
| 143 | * the rest of the graph output for this |
| 144 | * commit. |
| 145 | */ |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 146 | if (graph_show_remainder(revs->graph)) |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 147 | putchar('\n'); |
Erik Faye-Lund | 1fb5fdd | 2010-03-21 15:40:16 +0100 | [diff] [blame] | 148 | if (revs->commit_format == CMIT_FMT_ONELINE) |
| 149 | putchar('\n'); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 150 | } |
| 151 | } else { |
Erik Faye-Lund | 1fb5fdd | 2010-03-21 15:40:16 +0100 | [diff] [blame] | 152 | if (revs->commit_format != CMIT_FMT_USERFORMAT || |
Jeff King | 9130ac9 | 2010-10-07 14:25:43 -0400 | [diff] [blame] | 153 | buf.len) { |
| 154 | fwrite(buf.buf, 1, buf.len, stdout); |
| 155 | putchar(info->hdr_termination); |
| 156 | } |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 157 | } |
Pierre Habouzit | 674d172 | 2007-09-10 12:35:06 +0200 | [diff] [blame] | 158 | strbuf_release(&buf); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 159 | } else { |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 160 | if (graph_show_remainder(revs->graph)) |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 161 | putchar('\n'); |
Linus Torvalds | 7620d39 | 2005-07-04 16:36:48 -0700 | [diff] [blame] | 162 | } |
Theodore Ts'o | 06f59e9 | 2007-06-29 13:40:46 -0400 | [diff] [blame] | 163 | maybe_flush_or_die(stdout, "stdout"); |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 164 | finish_commit(commit, data); |
Shawn O. Pearce | 2735089 | 2007-11-11 02:29:41 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 167 | static void finish_commit(struct commit *commit, void *data) |
Shawn O. Pearce | 2735089 | 2007-11-11 02:29:41 -0500 | [diff] [blame] | 168 | { |
Linus Torvalds | cb11574 | 2006-06-17 18:47:58 -0700 | [diff] [blame] | 169 | if (commit->parents) { |
| 170 | free_commit_list(commit->parents); |
| 171 | commit->parents = NULL; |
| 172 | } |
Junio C Hamano | 4cac42b | 2006-08-27 21:19:39 -0700 | [diff] [blame] | 173 | free(commit->buffer); |
| 174 | commit->buffer = NULL; |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 177 | static void finish_object(struct object *obj, |
| 178 | const struct name_path *path, const char *name, |
| 179 | void *cb_data) |
Shawn O. Pearce | 2735089 | 2007-11-11 02:29:41 -0500 | [diff] [blame] | 180 | { |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 181 | struct rev_list_info *info = cb_data; |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 182 | if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1)) |
| 183 | die("missing blob object '%s'", sha1_to_hex(obj->sha1)); |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 184 | if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT) |
| 185 | parse_object(obj->sha1); |
Shawn O. Pearce | 2735089 | 2007-11-11 02:29:41 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 188 | static void show_object(struct object *obj, |
| 189 | const struct name_path *path, const char *component, |
| 190 | void *cb_data) |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 191 | { |
Clemens Buchacher | cb8da70 | 2012-02-13 21:17:11 +0100 | [diff] [blame] | 192 | struct rev_list_info *info = cb_data; |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 193 | finish_object(obj, path, component, cb_data); |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 194 | if (info->flags & REV_LIST_QUIET) |
| 195 | return; |
Junio C Hamano | 91f1751 | 2011-08-17 14:30:34 -0700 | [diff] [blame] | 196 | show_object_with_name(stdout, obj, path, component); |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 199 | static void show_edge(struct commit *commit) |
| 200 | { |
| 201 | printf("-%s\n", sha1_to_hex(commit->object.sha1)); |
| 202 | } |
| 203 | |
Christian Couder | 9f199b1 | 2009-02-21 09:26:01 +0100 | [diff] [blame] | 204 | static inline int log2i(int n) |
| 205 | { |
| 206 | int log2 = 0; |
| 207 | |
| 208 | for (; n > 1; n >>= 1) |
| 209 | log2++; |
| 210 | |
| 211 | return log2; |
| 212 | } |
| 213 | |
| 214 | static inline int exp2i(int n) |
| 215 | { |
| 216 | return 1 << n; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * Estimate the number of bisect steps left (after the current step) |
| 221 | * |
| 222 | * For any x between 0 included and 2^n excluded, the probability for |
| 223 | * n - 1 steps left looks like: |
| 224 | * |
| 225 | * P(2^n + x) == (2^n - x) / (2^n + x) |
| 226 | * |
| 227 | * and P(2^n + x) < 0.5 means 2^n < 3x |
| 228 | */ |
Christian Couder | 1c87654 | 2009-04-19 11:55:38 +0200 | [diff] [blame] | 229 | int estimate_bisect_steps(int all) |
Christian Couder | 9f199b1 | 2009-02-21 09:26:01 +0100 | [diff] [blame] | 230 | { |
| 231 | int n, x, e; |
| 232 | |
| 233 | if (all < 3) |
| 234 | return 0; |
| 235 | |
| 236 | n = log2i(all); |
| 237 | e = exp2i(n); |
| 238 | x = all - e; |
| 239 | |
| 240 | return (e < 3 * x) ? n : n - 1; |
| 241 | } |
| 242 | |
Christian Couder | 280e65c | 2009-04-19 11:55:43 +0200 | [diff] [blame] | 243 | void print_commit_list(struct commit_list *list, |
| 244 | const char *format_cur, |
| 245 | const char *format_last) |
| 246 | { |
| 247 | for ( ; list; list = list->next) { |
| 248 | const char *format = list->next ? format_cur : format_last; |
| 249 | printf(format, sha1_to_hex(list->item->object.sha1)); |
| 250 | } |
| 251 | } |
| 252 | |
Christian Couder | 38ef750 | 2009-04-21 07:54:10 +0200 | [diff] [blame] | 253 | static void print_var_str(const char *var, const char *val) |
Christian Couder | 280e65c | 2009-04-19 11:55:43 +0200 | [diff] [blame] | 254 | { |
Christian Couder | 38ef750 | 2009-04-21 07:54:10 +0200 | [diff] [blame] | 255 | printf("%s='%s'\n", var, val); |
Christian Couder | 280e65c | 2009-04-19 11:55:43 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Christian Couder | 38ef750 | 2009-04-21 07:54:10 +0200 | [diff] [blame] | 258 | static void print_var_int(const char *var, int val) |
Christian Couder | 280e65c | 2009-04-19 11:55:43 +0200 | [diff] [blame] | 259 | { |
Christian Couder | 38ef750 | 2009-04-21 07:54:10 +0200 | [diff] [blame] | 260 | printf("%s=%d\n", var, val); |
Christian Couder | 280e65c | 2009-04-19 11:55:43 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Junio C Hamano | f1c92c6 | 2010-01-11 22:21:18 -0800 | [diff] [blame] | 263 | static int show_bisect_vars(struct rev_list_info *info, int reaches, int all) |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 264 | { |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 265 | int cnt, flags = info->flags; |
Christian Couder | 280e65c | 2009-04-19 11:55:43 +0200 | [diff] [blame] | 266 | char hex[41] = ""; |
Christian Couder | 9518864 | 2009-03-26 05:55:49 +0100 | [diff] [blame] | 267 | struct commit_list *tried; |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 268 | struct rev_info *revs = info->revs; |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 269 | |
Nguyễn Thái Ngọc Duy | 8ba8fe0 | 2012-02-28 20:59:59 +0700 | [diff] [blame] | 270 | if (!revs->commits) |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 271 | return 1; |
| 272 | |
Christian Couder | 9af3589 | 2009-06-06 06:41:33 +0200 | [diff] [blame] | 273 | revs->commits = filter_skipped(revs->commits, &tried, |
| 274 | flags & BISECT_SHOW_ALL, |
| 275 | NULL, NULL); |
Christian Couder | 9518864 | 2009-03-26 05:55:49 +0100 | [diff] [blame] | 276 | |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 277 | /* |
Christian Couder | 7428d75 | 2009-03-26 05:55:41 +0100 | [diff] [blame] | 278 | * revs->commits can reach "reaches" commits among |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 279 | * "all" commits. If it is good, then there are |
| 280 | * (all-reaches) commits left to be bisected. |
| 281 | * On the other hand, if it is bad, then the set |
| 282 | * to bisect is "reaches". |
| 283 | * A bisect set of size N has (N-1) commits further |
| 284 | * to test, as we already know one bad one. |
| 285 | */ |
| 286 | cnt = all - reaches; |
| 287 | if (cnt < reaches) |
| 288 | cnt = reaches; |
Christian Couder | 6a17fad | 2009-03-26 05:55:35 +0100 | [diff] [blame] | 289 | |
Christian Couder | 9518864 | 2009-03-26 05:55:49 +0100 | [diff] [blame] | 290 | if (revs->commits) |
| 291 | strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1)); |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 292 | |
Christian Couder | 37c4c38 | 2009-03-29 11:55:43 +0200 | [diff] [blame] | 293 | if (flags & BISECT_SHOW_ALL) { |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 294 | traverse_commit_list(revs, show_commit, show_object, info); |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 295 | printf("------\n"); |
| 296 | } |
| 297 | |
Christian Couder | 38ef750 | 2009-04-21 07:54:10 +0200 | [diff] [blame] | 298 | print_var_str("bisect_rev", hex); |
| 299 | print_var_int("bisect_nr", cnt - 1); |
| 300 | print_var_int("bisect_good", all - reaches - 1); |
| 301 | print_var_int("bisect_bad", reaches - 1); |
| 302 | print_var_int("bisect_all", all); |
| 303 | print_var_int("bisect_steps", estimate_bisect_steps(all)); |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 308 | int cmd_rev_list(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 309 | { |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 310 | struct rev_info revs; |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 311 | struct rev_list_info info; |
Linus Torvalds | d9a8368 | 2006-02-27 08:54:36 -0800 | [diff] [blame] | 312 | int i; |
Christian Couder | ff62d73 | 2009-03-26 05:55:17 +0100 | [diff] [blame] | 313 | int bisect_list = 0; |
Junio C Hamano | 457f08a | 2007-03-21 22:15:54 -0700 | [diff] [blame] | 314 | int bisect_show_vars = 0; |
Christian Couder | 50e62a8 | 2007-10-22 07:47:56 +0200 | [diff] [blame] | 315 | int bisect_find_all = 0; |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 316 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 317 | git_config(git_default_config, NULL); |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 318 | init_revisions(&revs, prefix); |
Michael J Gruber | 7337b13 | 2010-03-22 14:36:30 +0100 | [diff] [blame] | 319 | revs.abbrev = DEFAULT_ABBREV; |
Junio C Hamano | 7594c4b | 2006-04-15 23:48:27 -0700 | [diff] [blame] | 320 | revs.commit_format = CMIT_FMT_UNSPECIFIED; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 321 | argc = setup_revisions(argc, argv, &revs, NULL); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 322 | |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 323 | memset(&info, 0, sizeof(info)); |
| 324 | info.revs = &revs; |
Linus Torvalds | ad3f9a7 | 2009-10-27 11:28:07 -0700 | [diff] [blame] | 325 | if (revs.bisect) |
| 326 | bisect_list = 1; |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 327 | |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 328 | if (DIFF_OPT_TST(&revs.diffopt, QUICK)) |
| 329 | info.flags |= REV_LIST_QUIET; |
Kay Sievers | fcfda02 | 2005-05-06 10:00:11 +0200 | [diff] [blame] | 330 | for (i = 1 ; i < argc; i++) { |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 331 | const char *arg = argv[i]; |
Kay Sievers | fcfda02 | 2005-05-06 10:00:11 +0200 | [diff] [blame] | 332 | |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 333 | if (!strcmp(arg, "--header")) { |
Junio C Hamano | 7594c4b | 2006-04-15 23:48:27 -0700 | [diff] [blame] | 334 | revs.verbose_header = 1; |
Linus Torvalds | 9d97aa6 | 2005-06-01 08:42:22 -0700 | [diff] [blame] | 335 | continue; |
| 336 | } |
Junio C Hamano | dc68c4f | 2006-03-22 00:22:00 -0800 | [diff] [blame] | 337 | if (!strcmp(arg, "--timestamp")) { |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 338 | info.show_timestamp = 1; |
Junio C Hamano | dc68c4f | 2006-03-22 00:22:00 -0800 | [diff] [blame] | 339 | continue; |
| 340 | } |
Linus Torvalds | 8b3a1e0 | 2005-06-17 22:54:50 -0700 | [diff] [blame] | 341 | if (!strcmp(arg, "--bisect")) { |
| 342 | bisect_list = 1; |
| 343 | continue; |
| 344 | } |
Christian Couder | 50e62a8 | 2007-10-22 07:47:56 +0200 | [diff] [blame] | 345 | if (!strcmp(arg, "--bisect-all")) { |
| 346 | bisect_list = 1; |
| 347 | bisect_find_all = 1; |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 348 | info.flags |= BISECT_SHOW_ALL; |
Christian Couder | 6e46cc0 | 2009-02-08 15:54:47 +0100 | [diff] [blame] | 349 | revs.show_decorations = 1; |
Christian Couder | 50e62a8 | 2007-10-22 07:47:56 +0200 | [diff] [blame] | 350 | continue; |
| 351 | } |
Junio C Hamano | 457f08a | 2007-03-21 22:15:54 -0700 | [diff] [blame] | 352 | if (!strcmp(arg, "--bisect-vars")) { |
| 353 | bisect_list = 1; |
| 354 | bisect_show_vars = 1; |
| 355 | continue; |
| 356 | } |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 357 | usage(rev_list_usage); |
| 358 | |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 359 | } |
Junio C Hamano | 7594c4b | 2006-04-15 23:48:27 -0700 | [diff] [blame] | 360 | if (revs.commit_format != CMIT_FMT_UNSPECIFIED) { |
| 361 | /* The command line has a --pretty */ |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 362 | info.hdr_termination = '\n'; |
Junio C Hamano | 7594c4b | 2006-04-15 23:48:27 -0700 | [diff] [blame] | 363 | if (revs.commit_format == CMIT_FMT_ONELINE) |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 364 | info.header_prefix = ""; |
Junio C Hamano | 7594c4b | 2006-04-15 23:48:27 -0700 | [diff] [blame] | 365 | else |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 366 | info.header_prefix = "commit "; |
Junio C Hamano | 7594c4b | 2006-04-15 23:48:27 -0700 | [diff] [blame] | 367 | } |
Junio C Hamano | db89665 | 2006-04-17 12:42:36 -0700 | [diff] [blame] | 368 | else if (revs.verbose_header) |
| 369 | /* Only --header was specified */ |
| 370 | revs.commit_format = CMIT_FMT_RAW; |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 371 | |
Christian Couder | d797257 | 2009-04-06 22:28:00 +0200 | [diff] [blame] | 372 | if ((!revs.commits && |
Junio C Hamano | 8c1f0b4 | 2006-04-14 22:43:34 -0700 | [diff] [blame] | 373 | (!(revs.tag_objects||revs.tree_objects||revs.blob_objects) && |
Linus Torvalds | 1f1e895 | 2006-06-19 17:42:35 -0700 | [diff] [blame] | 374 | !revs.pending.nr)) || |
Junio C Hamano | 8c1f0b4 | 2006-04-14 22:43:34 -0700 | [diff] [blame] | 375 | revs.diff) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 376 | usage(rev_list_usage); |
| 377 | |
Junio C Hamano | 80235ba | 2010-01-17 20:09:06 -0800 | [diff] [blame] | 378 | save_commit_buffer = (revs.verbose_header || |
| 379 | revs.grep_filter.pattern_list || |
| 380 | revs.grep_filter.header_list); |
Junio C Hamano | 4e1dc64 | 2006-04-14 15:57:32 -0700 | [diff] [blame] | 381 | if (bisect_list) |
| 382 | revs.limited = 1; |
Junio C Hamano | 9181ca2 | 2006-03-28 17:28:04 -0800 | [diff] [blame] | 383 | |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 384 | if (prepare_revision_walk(&revs)) |
| 385 | die("revision walk setup failed"); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 386 | if (revs.tree_objects) |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 387 | mark_edges_uninteresting(revs.commits, &revs, show_edge); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 388 | |
Junio C Hamano | 457f08a | 2007-03-21 22:15:54 -0700 | [diff] [blame] | 389 | if (bisect_list) { |
| 390 | int reaches = reaches, all = all; |
| 391 | |
Christian Couder | 50e62a8 | 2007-10-22 07:47:56 +0200 | [diff] [blame] | 392 | revs.commits = find_bisection(revs.commits, &reaches, &all, |
| 393 | bisect_find_all); |
Christian Couder | 9518864 | 2009-03-26 05:55:49 +0100 | [diff] [blame] | 394 | |
Christian Couder | 9996983 | 2009-03-26 05:55:30 +0100 | [diff] [blame] | 395 | if (bisect_show_vars) |
Christian Couder | 13858e5 | 2009-04-07 05:08:42 +0200 | [diff] [blame] | 396 | return show_bisect_vars(&info, reaches, all); |
Junio C Hamano | 457f08a | 2007-03-21 22:15:54 -0700 | [diff] [blame] | 397 | } |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 398 | |
Nguyễn Thái Ngọc Duy | 9899372 | 2012-02-28 21:00:00 +0700 | [diff] [blame] | 399 | traverse_commit_list(&revs, show_commit, show_object, &info); |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 400 | |
Thomas Rast | f69c501 | 2010-06-10 13:47:23 +0200 | [diff] [blame] | 401 | if (revs.count) { |
Michael J Gruber | b388e14 | 2011-04-26 10:24:29 +0200 | [diff] [blame] | 402 | if (revs.left_right && revs.cherry_mark) |
| 403 | printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same); |
| 404 | else if (revs.left_right) |
Thomas Rast | f69c501 | 2010-06-10 13:47:23 +0200 | [diff] [blame] | 405 | printf("%d\t%d\n", revs.count_left, revs.count_right); |
Michael J Gruber | b388e14 | 2011-04-26 10:24:29 +0200 | [diff] [blame] | 406 | else if (revs.cherry_mark) |
| 407 | printf("%d\t%d\n", revs.count_left + revs.count_right, revs.count_same); |
Thomas Rast | f69c501 | 2010-06-10 13:47:23 +0200 | [diff] [blame] | 408 | else |
| 409 | printf("%d\n", revs.count_left + revs.count_right); |
| 410 | } |
| 411 | |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 412 | return 0; |
| 413 | } |