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