| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "tag.h" |
| 3 | #include "blob.h" |
| 4 | #include "tree.h" |
| 5 | #include "commit.h" |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 6 | #include "diff.h" |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 7 | #include "refs.h" |
| 8 | #include "revision.h" |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 9 | #include "graph.h" |
| Junio C Hamano | 8ecae9b | 2006-09-17 22:43:40 | [diff] [blame] | 10 | #include "grep.h" |
| Johannes Schindelin | 8860fd4 | 2007-01-11 10:47:48 | [diff] [blame] | 11 | #include "reflog-walk.h" |
| Junio C Hamano | d7a17ca | 2007-04-09 10:40:38 | [diff] [blame] | 12 | #include "patch-ids.h" |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 13 | #include "decorate.h" |
| Linus Torvalds | 78892e3 | 2008-11-03 19:25:46 | [diff] [blame] | 14 | #include "log-tree.h" |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 15 | |
| Linus Torvalds | cdcefbc | 2007-11-03 18:11:10 | [diff] [blame] | 16 | volatile show_early_output_fn_t show_early_output; |
| 17 | |
| Linus Torvalds | cf2ab91 | 2009-04-11 01:15:26 | [diff] [blame] | 18 | char *path_name(const struct name_path *path, const char *name) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 19 | { |
| Linus Torvalds | cf2ab91 | 2009-04-11 01:15:26 | [diff] [blame] | 20 | const struct name_path *p; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 21 | char *n, *m; |
| 22 | int nlen = strlen(name); |
| 23 | int len = nlen + 1; |
| 24 | |
| 25 | for (p = path; p; p = p->up) { |
| 26 | if (p->elem_len) |
| 27 | len += p->elem_len + 1; |
| 28 | } |
| 29 | n = xmalloc(len); |
| 30 | m = n + len - (nlen + 1); |
| 31 | strcpy(m, name); |
| 32 | for (p = path; p; p = p->up) { |
| 33 | if (p->elem_len) { |
| 34 | m -= p->elem_len + 1; |
| 35 | memcpy(m, p->elem, p->elem_len); |
| 36 | m[p->elem_len] = '/'; |
| 37 | } |
| 38 | } |
| 39 | return n; |
| 40 | } |
| 41 | |
| Linus Torvalds | 1f1e895 | 2006-06-20 00:42:35 | [diff] [blame] | 42 | void add_object(struct object *obj, |
| 43 | struct object_array *p, |
| 44 | struct name_path *path, |
| 45 | const char *name) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 46 | { |
| Linus Torvalds | 1f1e895 | 2006-06-20 00:42:35 | [diff] [blame] | 47 | add_object_array(obj, path_name(path, name), p); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void mark_blob_uninteresting(struct blob *blob) |
| 51 | { |
| Martin Koegler | c1ee901 | 2008-02-18 20:47:54 | [diff] [blame] | 52 | if (!blob) |
| 53 | return; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 54 | if (blob->object.flags & UNINTERESTING) |
| 55 | return; |
| 56 | blob->object.flags |= UNINTERESTING; |
| 57 | } |
| 58 | |
| 59 | void mark_tree_uninteresting(struct tree *tree) |
| 60 | { |
| Linus Torvalds | f75e53e | 2006-05-29 19:20:14 | [diff] [blame] | 61 | struct tree_desc desc; |
| Linus Torvalds | 4c068a9 | 2006-05-30 16:45:45 | [diff] [blame] | 62 | struct name_entry entry; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 63 | struct object *obj = &tree->object; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 64 | |
| Martin Koegler | c1ee901 | 2008-02-18 20:47:54 | [diff] [blame] | 65 | if (!tree) |
| 66 | return; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 67 | if (obj->flags & UNINTERESTING) |
| 68 | return; |
| 69 | obj->flags |= UNINTERESTING; |
| 70 | if (!has_sha1_file(obj->sha1)) |
| 71 | return; |
| 72 | if (parse_tree(tree) < 0) |
| 73 | die("bad tree %s", sha1_to_hex(obj->sha1)); |
| Linus Torvalds | f75e53e | 2006-05-29 19:20:14 | [diff] [blame] | 74 | |
| Linus Torvalds | 6fda5e5 | 2007-03-21 17:08:25 | [diff] [blame] | 75 | init_tree_desc(&desc, tree->buffer, tree->size); |
| Linus Torvalds | 4c068a9 | 2006-05-30 16:45:45 | [diff] [blame] | 76 | while (tree_entry(&desc, &entry)) { |
| Linus Torvalds | 4d1012c | 2007-11-11 23:35:23 | [diff] [blame] | 77 | switch (object_type(entry.mode)) { |
| 78 | case OBJ_TREE: |
| Linus Torvalds | 4c068a9 | 2006-05-30 16:45:45 | [diff] [blame] | 79 | mark_tree_uninteresting(lookup_tree(entry.sha1)); |
| Linus Torvalds | 4d1012c | 2007-11-11 23:35:23 | [diff] [blame] | 80 | break; |
| 81 | case OBJ_BLOB: |
| Linus Torvalds | 4c068a9 | 2006-05-30 16:45:45 | [diff] [blame] | 82 | mark_blob_uninteresting(lookup_blob(entry.sha1)); |
| Linus Torvalds | 4d1012c | 2007-11-11 23:35:23 | [diff] [blame] | 83 | break; |
| 84 | default: |
| 85 | /* Subproject commit - not in this repository */ |
| 86 | break; |
| 87 | } |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 88 | } |
| Linus Torvalds | f75e53e | 2006-05-29 19:20:14 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * We don't care about the tree any more |
| 92 | * after it has been marked uninteresting. |
| 93 | */ |
| 94 | free(tree->buffer); |
| 95 | tree->buffer = NULL; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void mark_parents_uninteresting(struct commit *commit) |
| 99 | { |
| 100 | struct commit_list *parents = commit->parents; |
| 101 | |
| 102 | while (parents) { |
| 103 | struct commit *commit = parents->item; |
| Matthias Urlichs | d2c4af7 | 2006-03-09 04:04:36 | [diff] [blame] | 104 | if (!(commit->object.flags & UNINTERESTING)) { |
| 105 | commit->object.flags |= UNINTERESTING; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 106 | |
| Matthias Urlichs | d2c4af7 | 2006-03-09 04:04:36 | [diff] [blame] | 107 | /* |
| 108 | * Normally we haven't parsed the parent |
| 109 | * yet, so we won't have a parent of a parent |
| 110 | * here. However, it may turn out that we've |
| 111 | * reached this commit some other way (where it |
| 112 | * wasn't uninteresting), in which case we need |
| 113 | * to mark its parents recursively too.. |
| 114 | */ |
| 115 | if (commit->parents) |
| 116 | mark_parents_uninteresting(commit); |
| 117 | } |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * A missing commit is ok iff its parent is marked |
| 121 | * uninteresting. |
| 122 | * |
| 123 | * We just mark such a thing parsed, so that when |
| 124 | * it is popped next time around, we won't be trying |
| 125 | * to parse it and get an error. |
| 126 | */ |
| 127 | if (!has_sha1_file(commit->object.sha1)) |
| 128 | commit->object.parsed = 1; |
| 129 | parents = parents->next; |
| 130 | } |
| 131 | } |
| 132 | |
| Junio C Hamano | 2d93b9f | 2007-06-08 09:24:58 | [diff] [blame] | 133 | static void add_pending_object_with_mode(struct rev_info *revs, struct object *obj, const char *name, unsigned mode) |
| Martin Koegler | bb6c2fb | 2007-04-22 16:43:59 | [diff] [blame] | 134 | { |
| Linus Torvalds | aa27e46 | 2007-02-28 00:22:52 | [diff] [blame] | 135 | if (revs->no_walk && (obj->flags & UNINTERESTING)) |
| Linus Torvalds | f222abd | 2009-07-13 21:41:12 | [diff] [blame] | 136 | revs->no_walk = 0; |
| Junio C Hamano | 105e473 | 2010-01-26 21:48:28 | [diff] [blame] | 137 | if (revs->reflog_info && obj->type == OBJ_COMMIT) { |
| 138 | struct strbuf buf = STRBUF_INIT; |
| 139 | int len = interpret_branch_name(name, &buf); |
| 140 | int st; |
| 141 | |
| 142 | if (0 < len && name[len] && buf.len) |
| 143 | strbuf_addstr(&buf, name + len); |
| 144 | st = add_reflog_for_walk(revs->reflog_info, |
| 145 | (struct commit *)obj, |
| 146 | buf.buf[0] ? buf.buf: name); |
| 147 | strbuf_release(&buf); |
| 148 | if (st) |
| 149 | return; |
| 150 | } |
| Martin Koegler | bb6c2fb | 2007-04-22 16:43:59 | [diff] [blame] | 151 | add_object_array_with_mode(obj, name, &revs->pending, mode); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 152 | } |
| 153 | |
| Junio C Hamano | 2d93b9f | 2007-06-08 09:24:58 | [diff] [blame] | 154 | void add_pending_object(struct rev_info *revs, struct object *obj, const char *name) |
| 155 | { |
| 156 | add_pending_object_with_mode(revs, obj, name, S_IFINVALID); |
| 157 | } |
| 158 | |
| Junio C Hamano | 3384a2d | 2007-12-11 18:09:04 | [diff] [blame] | 159 | void add_head_to_pending(struct rev_info *revs) |
| 160 | { |
| 161 | unsigned char sha1[20]; |
| 162 | struct object *obj; |
| 163 | if (get_sha1("HEAD", sha1)) |
| 164 | return; |
| 165 | obj = parse_object(sha1); |
| 166 | if (!obj) |
| 167 | return; |
| 168 | add_pending_object(revs, obj, "HEAD"); |
| 169 | } |
| 170 | |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 171 | static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 172 | { |
| 173 | struct object *object; |
| 174 | |
| 175 | object = parse_object(sha1); |
| 176 | if (!object) |
| 177 | die("bad object %s", name); |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 178 | object->flags |= flags; |
| 179 | return object; |
| 180 | } |
| 181 | |
| 182 | static struct commit *handle_commit(struct rev_info *revs, struct object *object, const char *name) |
| 183 | { |
| 184 | unsigned long flags = object->flags; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * Tag object? Look what it points to.. |
| 188 | */ |
| Linus Torvalds | 1974632 | 2006-07-12 03:45:31 | [diff] [blame] | 189 | while (object->type == OBJ_TAG) { |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 190 | struct tag *tag = (struct tag *) object; |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 191 | if (revs->tag_objects && !(flags & UNINTERESTING)) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 192 | add_pending_object(revs, object, tag->tag); |
| Martin Koegler | 9684afd | 2008-02-18 20:48:01 | [diff] [blame] | 193 | if (!tag->tagged) |
| 194 | die("bad tag"); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 195 | object = parse_object(tag->tagged->sha1); |
| Junio C Hamano | aeeae1b | 2009-01-28 07:19:30 | [diff] [blame] | 196 | if (!object) { |
| 197 | if (flags & UNINTERESTING) |
| 198 | return NULL; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 199 | die("bad object %s", sha1_to_hex(tag->tagged->sha1)); |
| Junio C Hamano | aeeae1b | 2009-01-28 07:19:30 | [diff] [blame] | 200 | } |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Commit object? Just return it, we'll do all the complex |
| 205 | * reachability crud. |
| 206 | */ |
| Linus Torvalds | 1974632 | 2006-07-12 03:45:31 | [diff] [blame] | 207 | if (object->type == OBJ_COMMIT) { |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 208 | struct commit *commit = (struct commit *)object; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 209 | if (parse_commit(commit) < 0) |
| 210 | die("unable to parse commit %s", name); |
| Linus Torvalds | d9a8368 | 2006-02-27 16:54:36 | [diff] [blame] | 211 | if (flags & UNINTERESTING) { |
| Linus Torvalds | 4262c1b | 2006-04-19 03:31:41 | [diff] [blame] | 212 | commit->object.flags |= UNINTERESTING; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 213 | mark_parents_uninteresting(commit); |
| Linus Torvalds | d9a8368 | 2006-02-27 16:54:36 | [diff] [blame] | 214 | revs->limited = 1; |
| 215 | } |
| Linus Torvalds | 0f3a290 | 2008-10-27 19:51:59 | [diff] [blame] | 216 | if (revs->show_source && !commit->util) |
| 217 | commit->util = (void *) name; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 218 | return commit; |
| 219 | } |
| 220 | |
| 221 | /* |
| Mike Ralphson | 3ea3c21 | 2009-04-17 18:13:30 | [diff] [blame] | 222 | * Tree object? Either mark it uninteresting, or add it |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 223 | * to the list of objects to look at later.. |
| 224 | */ |
| Linus Torvalds | 1974632 | 2006-07-12 03:45:31 | [diff] [blame] | 225 | if (object->type == OBJ_TREE) { |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 226 | struct tree *tree = (struct tree *)object; |
| 227 | if (!revs->tree_objects) |
| 228 | return NULL; |
| 229 | if (flags & UNINTERESTING) { |
| 230 | mark_tree_uninteresting(tree); |
| 231 | return NULL; |
| 232 | } |
| 233 | add_pending_object(revs, object, ""); |
| 234 | return NULL; |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * Blob object? You know the drill by now.. |
| 239 | */ |
| Linus Torvalds | 1974632 | 2006-07-12 03:45:31 | [diff] [blame] | 240 | if (object->type == OBJ_BLOB) { |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 241 | struct blob *blob = (struct blob *)object; |
| 242 | if (!revs->blob_objects) |
| 243 | return NULL; |
| 244 | if (flags & UNINTERESTING) { |
| 245 | mark_blob_uninteresting(blob); |
| 246 | return NULL; |
| 247 | } |
| 248 | add_pending_object(revs, object, ""); |
| 249 | return NULL; |
| 250 | } |
| 251 | die("%s is unknown object", name); |
| 252 | } |
| 253 | |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 254 | static int everybody_uninteresting(struct commit_list *orig) |
| 255 | { |
| 256 | struct commit_list *list = orig; |
| 257 | while (list) { |
| 258 | struct commit *commit = list->item; |
| 259 | list = list->next; |
| 260 | if (commit->object.flags & UNINTERESTING) |
| 261 | continue; |
| 262 | return 0; |
| 263 | } |
| 264 | return 1; |
| 265 | } |
| 266 | |
| Junio C Hamano | 0a4ba7f | 2007-03-14 20:12:18 | [diff] [blame] | 267 | /* |
| 268 | * The goal is to get REV_TREE_NEW as the result only if the |
| Linus Torvalds | ceff8e7 | 2009-06-03 01:34:01 | [diff] [blame] | 269 | * diff consists of all '+' (and no other changes), REV_TREE_OLD |
| 270 | * if the whole diff is removal of old data, and otherwise |
| 271 | * REV_TREE_DIFFERENT (of course if the trees are the same we |
| 272 | * want REV_TREE_SAME). |
| 273 | * That means that once we get to REV_TREE_DIFFERENT, we do not |
| 274 | * have to look any further. |
| Junio C Hamano | 0a4ba7f | 2007-03-14 20:12:18 | [diff] [blame] | 275 | */ |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 276 | static int tree_difference = REV_TREE_SAME; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 277 | |
| 278 | static void file_add_remove(struct diff_options *options, |
| 279 | int addremove, unsigned mode, |
| 280 | const unsigned char *sha1, |
| Jens Lehmann | e3d42c4 | 2010-01-18 20:26:18 | [diff] [blame] | 281 | const char *fullpath, unsigned dirty_submodule) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 282 | { |
| Linus Torvalds | ceff8e7 | 2009-06-03 01:34:01 | [diff] [blame] | 283 | int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 284 | |
| Linus Torvalds | ceff8e7 | 2009-06-03 01:34:01 | [diff] [blame] | 285 | tree_difference |= diff; |
| Junio C Hamano | dd47aa3 | 2007-03-14 20:18:15 | [diff] [blame] | 286 | if (tree_difference == REV_TREE_DIFFERENT) |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 287 | DIFF_OPT_SET(options, HAS_CHANGES); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void file_change(struct diff_options *options, |
| 291 | unsigned old_mode, unsigned new_mode, |
| 292 | const unsigned char *old_sha1, |
| 293 | const unsigned char *new_sha1, |
| Jens Lehmann | e3d42c4 | 2010-01-18 20:26:18 | [diff] [blame] | 294 | const char *fullpath, |
| 295 | unsigned old_dirty_submodule, unsigned new_dirty_submodule) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 296 | { |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 297 | tree_difference = REV_TREE_DIFFERENT; |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 298 | DIFF_OPT_SET(options, HAS_CHANGES); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 299 | } |
| 300 | |
| Linus Torvalds | 3a5e860 | 2008-11-03 18:45:41 | [diff] [blame] | 301 | static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct commit *commit) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 302 | { |
| Linus Torvalds | 3a5e860 | 2008-11-03 18:45:41 | [diff] [blame] | 303 | struct tree *t1 = parent->tree; |
| 304 | struct tree *t2 = commit->tree; |
| 305 | |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 306 | if (!t1) |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 307 | return REV_TREE_NEW; |
| Linus Torvalds | ceff8e7 | 2009-06-03 01:34:01 | [diff] [blame] | 308 | if (!t2) |
| 309 | return REV_TREE_OLD; |
| Linus Torvalds | 78892e3 | 2008-11-03 19:25:46 | [diff] [blame] | 310 | |
| 311 | if (revs->simplify_by_decoration) { |
| 312 | /* |
| 313 | * If we are simplifying by decoration, then the commit |
| 314 | * is worth showing if it has a tag pointing at it. |
| 315 | */ |
| 316 | if (lookup_decoration(&name_decoration, &commit->object)) |
| 317 | return REV_TREE_DIFFERENT; |
| 318 | /* |
| 319 | * A commit that is not pointed by a tag is uninteresting |
| 320 | * if we are not limited by path. This means that you will |
| 321 | * see the usual "commits that touch the paths" plus any |
| 322 | * tagged commit by specifying both --simplify-by-decoration |
| 323 | * and pathspec. |
| 324 | */ |
| 325 | if (!revs->prune_data) |
| 326 | return REV_TREE_SAME; |
| 327 | } |
| Linus Torvalds | ceff8e7 | 2009-06-03 01:34:01 | [diff] [blame] | 328 | |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 329 | tree_difference = REV_TREE_SAME; |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 330 | DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES); |
| Junio C Hamano | c4e05b1 | 2006-04-11 01:14:54 | [diff] [blame] | 331 | if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "", |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 332 | &revs->pruning) < 0) |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 333 | return REV_TREE_DIFFERENT; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 334 | return tree_difference; |
| 335 | } |
| 336 | |
| Linus Torvalds | 3a5e860 | 2008-11-03 18:45:41 | [diff] [blame] | 337 | static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 338 | { |
| 339 | int retval; |
| 340 | void *tree; |
| Linus Torvalds | 6fda5e5 | 2007-03-21 17:08:25 | [diff] [blame] | 341 | unsigned long size; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 342 | struct tree_desc empty, real; |
| Linus Torvalds | 3a5e860 | 2008-11-03 18:45:41 | [diff] [blame] | 343 | struct tree *t1 = commit->tree; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 344 | |
| 345 | if (!t1) |
| 346 | return 0; |
| 347 | |
| Linus Torvalds | 6fda5e5 | 2007-03-21 17:08:25 | [diff] [blame] | 348 | tree = read_object_with_reference(t1->object.sha1, tree_type, &size, NULL); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 349 | if (!tree) |
| 350 | return 0; |
| Linus Torvalds | 6fda5e5 | 2007-03-21 17:08:25 | [diff] [blame] | 351 | init_tree_desc(&real, tree, size); |
| 352 | init_tree_desc(&empty, "", 0); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 353 | |
| Junio C Hamano | 0a4ba7f | 2007-03-14 20:12:18 | [diff] [blame] | 354 | tree_difference = REV_TREE_SAME; |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 355 | DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES); |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 356 | retval = diff_tree(&empty, &real, "", &revs->pruning); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 357 | free(tree); |
| 358 | |
| Junio C Hamano | 0a4ba7f | 2007-03-14 20:12:18 | [diff] [blame] | 359 | return retval >= 0 && (tree_difference == REV_TREE_SAME); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) |
| 363 | { |
| 364 | struct commit_list **pp, *parent; |
| Linus Torvalds | 6631c73 | 2006-07-01 03:21:59 | [diff] [blame] | 365 | int tree_changed = 0, tree_same = 0; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 366 | |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 367 | /* |
| 368 | * If we don't do pruning, everything is interesting |
| 369 | */ |
| Linus Torvalds | 7dc0fe3 | 2007-11-13 07:16:08 | [diff] [blame] | 370 | if (!revs->prune) |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 371 | return; |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 372 | |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 373 | if (!commit->tree) |
| 374 | return; |
| 375 | |
| 376 | if (!commit->parents) { |
| Linus Torvalds | 3a5e860 | 2008-11-03 18:45:41 | [diff] [blame] | 377 | if (rev_same_tree_as_empty(revs, commit)) |
| Linus Torvalds | 7dc0fe3 | 2007-11-13 07:16:08 | [diff] [blame] | 378 | commit->object.flags |= TREESAME; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 379 | return; |
| 380 | } |
| 381 | |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 382 | /* |
| 383 | * Normal non-merge commit? If we don't want to make the |
| 384 | * history dense, we consider it always to be a change.. |
| 385 | */ |
| Linus Torvalds | 7dc0fe3 | 2007-11-13 07:16:08 | [diff] [blame] | 386 | if (!revs->dense && !commit->parents->next) |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 387 | return; |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 388 | |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 389 | pp = &commit->parents; |
| 390 | while ((parent = *pp) != NULL) { |
| 391 | struct commit *p = parent->item; |
| 392 | |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 393 | if (parse_commit(p) < 0) |
| 394 | die("cannot simplify commit %s (because of %s)", |
| 395 | sha1_to_hex(commit->object.sha1), |
| 396 | sha1_to_hex(p->object.sha1)); |
| Linus Torvalds | 3a5e860 | 2008-11-03 18:45:41 | [diff] [blame] | 397 | switch (rev_compare_tree(revs, p, commit)) { |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 398 | case REV_TREE_SAME: |
| Linus Torvalds | 6631c73 | 2006-07-01 03:21:59 | [diff] [blame] | 399 | tree_same = 1; |
| Linus Torvalds | 9202434 | 2006-06-11 17:57:35 | [diff] [blame] | 400 | if (!revs->simplify_history || (p->object.flags & UNINTERESTING)) { |
| Junio C Hamano | f3219fb | 2006-03-11 05:59:37 | [diff] [blame] | 401 | /* Even if a merge with an uninteresting |
| 402 | * side branch brought the entire change |
| 403 | * we are interested in, we do not want |
| 404 | * to lose the other branches of this |
| 405 | * merge, so we just keep going. |
| 406 | */ |
| 407 | pp = &parent->next; |
| 408 | continue; |
| 409 | } |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 410 | parent->next = NULL; |
| 411 | commit->parents = parent; |
| Linus Torvalds | 7dc0fe3 | 2007-11-13 07:16:08 | [diff] [blame] | 412 | commit->object.flags |= TREESAME; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 413 | return; |
| 414 | |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 415 | case REV_TREE_NEW: |
| 416 | if (revs->remove_empty_trees && |
| Linus Torvalds | 3a5e860 | 2008-11-03 18:45:41 | [diff] [blame] | 417 | rev_same_tree_as_empty(revs, p)) { |
| Junio C Hamano | c348f31 | 2006-03-12 21:39:31 | [diff] [blame] | 418 | /* We are adding all the specified |
| 419 | * paths from this parent, so the |
| 420 | * history beyond this parent is not |
| 421 | * interesting. Remove its parents |
| 422 | * (they are grandparents for us). |
| 423 | * IOW, we pretend this parent is a |
| 424 | * "root" commit. |
| Junio C Hamano | a41e109 | 2006-03-12 21:39:31 | [diff] [blame] | 425 | */ |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 426 | if (parse_commit(p) < 0) |
| 427 | die("cannot simplify commit %s (invalid %s)", |
| 428 | sha1_to_hex(commit->object.sha1), |
| 429 | sha1_to_hex(p->object.sha1)); |
| Junio C Hamano | c348f31 | 2006-03-12 21:39:31 | [diff] [blame] | 430 | p->parents = NULL; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 431 | } |
| 432 | /* fallthrough */ |
| Linus Torvalds | ceff8e7 | 2009-06-03 01:34:01 | [diff] [blame] | 433 | case REV_TREE_OLD: |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 434 | case REV_TREE_DIFFERENT: |
| Junio C Hamano | f3219fb | 2006-03-11 05:59:37 | [diff] [blame] | 435 | tree_changed = 1; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 436 | pp = &parent->next; |
| 437 | continue; |
| 438 | } |
| 439 | die("bad tree compare for commit %s", sha1_to_hex(commit->object.sha1)); |
| 440 | } |
| Linus Torvalds | 6631c73 | 2006-07-01 03:21:59 | [diff] [blame] | 441 | if (tree_changed && !tree_same) |
| Linus Torvalds | 7dc0fe3 | 2007-11-13 07:16:08 | [diff] [blame] | 442 | return; |
| 443 | commit->object.flags |= TREESAME; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 444 | } |
| 445 | |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 446 | static void insert_by_date_cached(struct commit *p, struct commit_list **head, |
| 447 | struct commit_list *cached_base, struct commit_list **cache) |
| 448 | { |
| 449 | struct commit_list *new_entry; |
| 450 | |
| 451 | if (cached_base && p->date < cached_base->item->date) |
| 452 | new_entry = insert_by_date(p, &cached_base->next); |
| 453 | else |
| 454 | new_entry = insert_by_date(p, head); |
| 455 | |
| 456 | if (cache && (!*cache || p->date < (*cache)->item->date)) |
| 457 | *cache = new_entry; |
| 458 | } |
| 459 | |
| 460 | static int add_parents_to_list(struct rev_info *revs, struct commit *commit, |
| 461 | struct commit_list **list, struct commit_list **cache_ptr) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 462 | { |
| 463 | struct commit_list *parent = commit->parents; |
| Junio C Hamano | 577ed5c | 2006-10-23 00:32:47 | [diff] [blame] | 464 | unsigned left_flag; |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 465 | struct commit_list *cached_base = cache_ptr ? *cache_ptr : NULL; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 466 | |
| Linus Torvalds | 3381c79 | 2006-04-09 00:05:58 | [diff] [blame] | 467 | if (commit->object.flags & ADDED) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 468 | return 0; |
| Linus Torvalds | 3381c79 | 2006-04-09 00:05:58 | [diff] [blame] | 469 | commit->object.flags |= ADDED; |
| 470 | |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 471 | /* |
| 472 | * If the commit is uninteresting, don't try to |
| 473 | * prune parents - we want the maximal uninteresting |
| 474 | * set. |
| 475 | * |
| 476 | * Normally we haven't parsed the parent |
| 477 | * yet, so we won't have a parent of a parent |
| 478 | * here. However, it may turn out that we've |
| 479 | * reached this commit some other way (where it |
| 480 | * wasn't uninteresting), in which case we need |
| 481 | * to mark its parents recursively too.. |
| 482 | */ |
| 483 | if (commit->object.flags & UNINTERESTING) { |
| 484 | while (parent) { |
| 485 | struct commit *p = parent->item; |
| 486 | parent = parent->next; |
| Junio C Hamano | aeeae1b | 2009-01-28 07:19:30 | [diff] [blame] | 487 | if (p) |
| 488 | p->object.flags |= UNINTERESTING; |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 489 | if (parse_commit(p) < 0) |
| Junio C Hamano | aeeae1b | 2009-01-28 07:19:30 | [diff] [blame] | 490 | continue; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 491 | if (p->parents) |
| 492 | mark_parents_uninteresting(p); |
| 493 | if (p->object.flags & SEEN) |
| 494 | continue; |
| 495 | p->object.flags |= SEEN; |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 496 | insert_by_date_cached(p, list, cached_base, cache_ptr); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 497 | } |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 498 | return 0; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Ok, the commit wasn't uninteresting. Try to |
| 503 | * simplify the commit history and find the parent |
| 504 | * that has no differences in the path set if one exists. |
| 505 | */ |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 506 | try_to_simplify_commit(revs, commit); |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 507 | |
| Linus Torvalds | ba1d450 | 2006-04-15 19:09:56 | [diff] [blame] | 508 | if (revs->no_walk) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 509 | return 0; |
| Linus Torvalds | ba1d450 | 2006-04-15 19:09:56 | [diff] [blame] | 510 | |
| Junio C Hamano | 577ed5c | 2006-10-23 00:32:47 | [diff] [blame] | 511 | left_flag = (commit->object.flags & SYMMETRIC_LEFT); |
| Junio C Hamano | 0053e90 | 2007-03-13 08:57:22 | [diff] [blame] | 512 | |
| Stephen R. van den Berg | d9c292e | 2008-04-27 17:32:46 | [diff] [blame] | 513 | for (parent = commit->parents; parent; parent = parent->next) { |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 514 | struct commit *p = parent->item; |
| 515 | |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 516 | if (parse_commit(p) < 0) |
| 517 | return -1; |
| Linus Torvalds | 0f3a290 | 2008-10-27 19:51:59 | [diff] [blame] | 518 | if (revs->show_source && !p->util) |
| 519 | p->util = commit->util; |
| Junio C Hamano | 577ed5c | 2006-10-23 00:32:47 | [diff] [blame] | 520 | p->object.flags |= left_flag; |
| Lars Hjemli | ad1012e | 2008-05-12 15:12:36 | [diff] [blame] | 521 | if (!(p->object.flags & SEEN)) { |
| 522 | p->object.flags |= SEEN; |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 523 | insert_by_date_cached(p, list, cached_base, cache_ptr); |
| Lars Hjemli | ad1012e | 2008-05-12 15:12:36 | [diff] [blame] | 524 | } |
| Junio C Hamano | 60d30b0 | 2008-08-01 05:17:13 | [diff] [blame] | 525 | if (revs->first_parent_only) |
| Stephen R. van den Berg | d9c292e | 2008-04-27 17:32:46 | [diff] [blame] | 526 | break; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 527 | } |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 528 | return 0; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 529 | } |
| 530 | |
| Johannes Schindelin | 36d56de | 2007-07-10 13:50:49 | [diff] [blame] | 531 | static void cherry_pick_list(struct commit_list *list, struct rev_info *revs) |
| Junio C Hamano | d7a17ca | 2007-04-09 10:40:38 | [diff] [blame] | 532 | { |
| 533 | struct commit_list *p; |
| 534 | int left_count = 0, right_count = 0; |
| 535 | int left_first; |
| 536 | struct patch_ids ids; |
| 537 | |
| 538 | /* First count the commits on the left and on the right */ |
| 539 | for (p = list; p; p = p->next) { |
| 540 | struct commit *commit = p->item; |
| 541 | unsigned flags = commit->object.flags; |
| 542 | if (flags & BOUNDARY) |
| 543 | ; |
| 544 | else if (flags & SYMMETRIC_LEFT) |
| 545 | left_count++; |
| 546 | else |
| 547 | right_count++; |
| 548 | } |
| 549 | |
| Thomas Rast | 36c0797 | 2010-02-20 11:42:04 | [diff] [blame] | 550 | if (!left_count || !right_count) |
| 551 | return; |
| 552 | |
| Junio C Hamano | d7a17ca | 2007-04-09 10:40:38 | [diff] [blame] | 553 | left_first = left_count < right_count; |
| 554 | init_patch_ids(&ids); |
| Johannes Schindelin | 36d56de | 2007-07-10 13:50:49 | [diff] [blame] | 555 | if (revs->diffopt.nr_paths) { |
| 556 | ids.diffopts.nr_paths = revs->diffopt.nr_paths; |
| 557 | ids.diffopts.paths = revs->diffopt.paths; |
| 558 | ids.diffopts.pathlens = revs->diffopt.pathlens; |
| 559 | } |
| Junio C Hamano | d7a17ca | 2007-04-09 10:40:38 | [diff] [blame] | 560 | |
| 561 | /* Compute patch-ids for one side */ |
| 562 | for (p = list; p; p = p->next) { |
| 563 | struct commit *commit = p->item; |
| 564 | unsigned flags = commit->object.flags; |
| 565 | |
| 566 | if (flags & BOUNDARY) |
| 567 | continue; |
| 568 | /* |
| 569 | * If we have fewer left, left_first is set and we omit |
| 570 | * commits on the right branch in this loop. If we have |
| 571 | * fewer right, we skip the left ones. |
| 572 | */ |
| 573 | if (left_first != !!(flags & SYMMETRIC_LEFT)) |
| 574 | continue; |
| 575 | commit->util = add_commit_patch_id(commit, &ids); |
| 576 | } |
| 577 | |
| 578 | /* Check the other side */ |
| 579 | for (p = list; p; p = p->next) { |
| 580 | struct commit *commit = p->item; |
| 581 | struct patch_id *id; |
| 582 | unsigned flags = commit->object.flags; |
| 583 | |
| 584 | if (flags & BOUNDARY) |
| 585 | continue; |
| 586 | /* |
| 587 | * If we have fewer left, left_first is set and we omit |
| 588 | * commits on the left branch in this loop. |
| 589 | */ |
| 590 | if (left_first == !!(flags & SYMMETRIC_LEFT)) |
| 591 | continue; |
| 592 | |
| 593 | /* |
| 594 | * Have we seen the same patch id? |
| 595 | */ |
| 596 | id = has_commit_patch_id(commit, &ids); |
| 597 | if (!id) |
| 598 | continue; |
| 599 | id->seen = 1; |
| 600 | commit->object.flags |= SHOWN; |
| 601 | } |
| 602 | |
| 603 | /* Now check the original side for seen ones */ |
| 604 | for (p = list; p; p = p->next) { |
| 605 | struct commit *commit = p->item; |
| 606 | struct patch_id *ent; |
| 607 | |
| 608 | ent = commit->util; |
| 609 | if (!ent) |
| 610 | continue; |
| 611 | if (ent->seen) |
| 612 | commit->object.flags |= SHOWN; |
| 613 | commit->util = NULL; |
| 614 | } |
| 615 | |
| 616 | free_patch_ids(&ids); |
| 617 | } |
| 618 | |
| Linus Torvalds | 7d00419 | 2008-03-18 01:56:33 | [diff] [blame] | 619 | /* How many extra uninteresting commits we want to see.. */ |
| 620 | #define SLOP 5 |
| 621 | |
| 622 | static int still_interesting(struct commit_list *src, unsigned long date, int slop) |
| Linus Torvalds | 3131b71 | 2008-02-09 22:02:07 | [diff] [blame] | 623 | { |
| Linus Torvalds | 7d00419 | 2008-03-18 01:56:33 | [diff] [blame] | 624 | /* |
| 625 | * No source list at all? We're definitely done.. |
| 626 | */ |
| 627 | if (!src) |
| 628 | return 0; |
| 629 | |
| 630 | /* |
| 631 | * Does the destination list contain entries with a date |
| 632 | * before the source list? Definitely _not_ done. |
| 633 | */ |
| 634 | if (date < src->item->date) |
| 635 | return SLOP; |
| 636 | |
| 637 | /* |
| 638 | * Does the source list still have interesting commits in |
| 639 | * it? Definitely not done.. |
| 640 | */ |
| 641 | if (!everybody_uninteresting(src)) |
| 642 | return SLOP; |
| 643 | |
| 644 | /* Ok, we're closing in.. */ |
| 645 | return slop-1; |
| Linus Torvalds | 3131b71 | 2008-02-09 22:02:07 | [diff] [blame] | 646 | } |
| 647 | |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 648 | static int limit_list(struct rev_info *revs) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 649 | { |
| Linus Torvalds | 7d00419 | 2008-03-18 01:56:33 | [diff] [blame] | 650 | int slop = SLOP; |
| 651 | unsigned long date = ~0ul; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 652 | struct commit_list *list = revs->commits; |
| 653 | struct commit_list *newlist = NULL; |
| 654 | struct commit_list **p = &newlist; |
| 655 | |
| 656 | while (list) { |
| 657 | struct commit_list *entry = list; |
| 658 | struct commit *commit = list->item; |
| 659 | struct object *obj = &commit->object; |
| Linus Torvalds | cdcefbc | 2007-11-03 18:11:10 | [diff] [blame] | 660 | show_early_output_fn_t show; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 661 | |
| 662 | list = list->next; |
| 663 | free(entry); |
| 664 | |
| 665 | if (revs->max_age != -1 && (commit->date < revs->max_age)) |
| 666 | obj->flags |= UNINTERESTING; |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 667 | if (add_parents_to_list(revs, commit, &list, NULL) < 0) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 668 | return -1; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 669 | if (obj->flags & UNINTERESTING) { |
| 670 | mark_parents_uninteresting(commit); |
| Linus Torvalds | 7d00419 | 2008-03-18 01:56:33 | [diff] [blame] | 671 | if (revs->show_all) |
| 672 | p = &commit_list_insert(commit, p)->next; |
| 673 | slop = still_interesting(list, date, slop); |
| 674 | if (slop) |
| Linus Torvalds | 3131b71 | 2008-02-09 22:02:07 | [diff] [blame] | 675 | continue; |
| Linus Torvalds | 7d00419 | 2008-03-18 01:56:33 | [diff] [blame] | 676 | /* If showing all, add the whole pending list to the end */ |
| 677 | if (revs->show_all) |
| 678 | *p = list; |
| 679 | break; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 680 | } |
| 681 | if (revs->min_age != -1 && (commit->date > revs->min_age)) |
| 682 | continue; |
| Linus Torvalds | 7d00419 | 2008-03-18 01:56:33 | [diff] [blame] | 683 | date = commit->date; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 684 | p = &commit_list_insert(commit, p)->next; |
| Linus Torvalds | cdcefbc | 2007-11-03 18:11:10 | [diff] [blame] | 685 | |
| 686 | show = show_early_output; |
| 687 | if (!show) |
| 688 | continue; |
| 689 | |
| 690 | show(revs, newlist); |
| 691 | show_early_output = NULL; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 692 | } |
| Junio C Hamano | d7a17ca | 2007-04-09 10:40:38 | [diff] [blame] | 693 | if (revs->cherry_pick) |
| Johannes Schindelin | 36d56de | 2007-07-10 13:50:49 | [diff] [blame] | 694 | cherry_pick_list(newlist, revs); |
| Junio C Hamano | d7a17ca | 2007-04-09 10:40:38 | [diff] [blame] | 695 | |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 696 | revs->commits = newlist; |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 697 | return 0; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 698 | } |
| 699 | |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 700 | struct all_refs_cb { |
| 701 | int all_flags; |
| Shawn O. Pearce | 71b03b4 | 2006-12-22 00:49:06 | [diff] [blame] | 702 | int warned_bad_reflog; |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 703 | struct rev_info *all_revs; |
| 704 | const char *name_for_errormsg; |
| 705 | }; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 706 | |
| Junio C Hamano | 8da1977 | 2006-09-21 05:02:01 | [diff] [blame] | 707 | static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 708 | { |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 709 | struct all_refs_cb *cb = cb_data; |
| 710 | struct object *object = get_reference(cb->all_revs, path, sha1, |
| 711 | cb->all_flags); |
| Johannes Schindelin | 3d1efd8 | 2007-02-23 01:56:31 | [diff] [blame] | 712 | add_pending_object(cb->all_revs, object, path); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 713 | return 0; |
| 714 | } |
| 715 | |
| Ilari Liusvaara | d08bae7 | 2010-01-20 09:48:25 | [diff] [blame] | 716 | static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs, |
| 717 | unsigned flags) |
| 718 | { |
| 719 | cb->all_revs = revs; |
| 720 | cb->all_flags = flags; |
| 721 | } |
| 722 | |
| Uwe Kleine-König | a5aa930 | 2008-02-28 07:24:25 | [diff] [blame] | 723 | static void handle_refs(struct rev_info *revs, unsigned flags, |
| 724 | int (*for_each)(each_ref_fn, void *)) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 725 | { |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 726 | struct all_refs_cb cb; |
| Ilari Liusvaara | d08bae7 | 2010-01-20 09:48:25 | [diff] [blame] | 727 | init_all_refs_cb(&cb, revs, flags); |
| Uwe Kleine-König | a5aa930 | 2008-02-28 07:24:25 | [diff] [blame] | 728 | for_each(handle_one_ref, &cb); |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 729 | } |
| 730 | |
| Shawn O. Pearce | 71b03b4 | 2006-12-22 00:49:06 | [diff] [blame] | 731 | static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data) |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 732 | { |
| 733 | struct all_refs_cb *cb = cb_data; |
| Shawn O. Pearce | 71b03b4 | 2006-12-22 00:49:06 | [diff] [blame] | 734 | if (!is_null_sha1(sha1)) { |
| 735 | struct object *o = parse_object(sha1); |
| 736 | if (o) { |
| 737 | o->flags |= cb->all_flags; |
| 738 | add_pending_object(cb->all_revs, o, ""); |
| 739 | } |
| 740 | else if (!cb->warned_bad_reflog) { |
| Theodore Ts'o | 46efd2d | 2007-03-30 23:07:05 | [diff] [blame] | 741 | warning("reflog of '%s' references pruned commits", |
| Shawn O. Pearce | 71b03b4 | 2006-12-22 00:49:06 | [diff] [blame] | 742 | cb->name_for_errormsg); |
| 743 | cb->warned_bad_reflog = 1; |
| 744 | } |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 745 | } |
| Shawn O. Pearce | 71b03b4 | 2006-12-22 00:49:06 | [diff] [blame] | 746 | } |
| 747 | |
| Johannes Schindelin | 883d60f | 2007-01-08 00:59:54 | [diff] [blame] | 748 | static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, |
| 749 | const char *email, unsigned long timestamp, int tz, |
| 750 | const char *message, void *cb_data) |
| Shawn O. Pearce | 71b03b4 | 2006-12-22 00:49:06 | [diff] [blame] | 751 | { |
| 752 | handle_one_reflog_commit(osha1, cb_data); |
| 753 | handle_one_reflog_commit(nsha1, cb_data); |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data) |
| 758 | { |
| 759 | struct all_refs_cb *cb = cb_data; |
| Shawn O. Pearce | 71b03b4 | 2006-12-22 00:49:06 | [diff] [blame] | 760 | cb->warned_bad_reflog = 0; |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 761 | cb->name_for_errormsg = path; |
| 762 | for_each_reflog_ent(path, handle_one_reflog_ent, cb_data); |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | static void handle_reflog(struct rev_info *revs, unsigned flags) |
| 767 | { |
| 768 | struct all_refs_cb cb; |
| 769 | cb.all_revs = revs; |
| 770 | cb.all_flags = flags; |
| Junio C Hamano | 25b51e2 | 2007-02-13 07:06:54 | [diff] [blame] | 771 | for_each_reflog(handle_one_reflog, &cb); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 772 | } |
| 773 | |
| Junio C Hamano | ea4a19e | 2006-04-30 07:54:29 | [diff] [blame] | 774 | static int add_parents_only(struct rev_info *revs, const char *arg, int flags) |
| 775 | { |
| 776 | unsigned char sha1[20]; |
| 777 | struct object *it; |
| 778 | struct commit *commit; |
| 779 | struct commit_list *parents; |
| 780 | |
| 781 | if (*arg == '^') { |
| 782 | flags ^= UNINTERESTING; |
| 783 | arg++; |
| 784 | } |
| 785 | if (get_sha1(arg, sha1)) |
| 786 | return 0; |
| 787 | while (1) { |
| 788 | it = get_reference(revs, arg, sha1, 0); |
| Linus Torvalds | 1974632 | 2006-07-12 03:45:31 | [diff] [blame] | 789 | if (it->type != OBJ_TAG) |
| Junio C Hamano | ea4a19e | 2006-04-30 07:54:29 | [diff] [blame] | 790 | break; |
| Martin Koegler | 9684afd | 2008-02-18 20:48:01 | [diff] [blame] | 791 | if (!((struct tag*)it)->tagged) |
| 792 | return 0; |
| Shawn Pearce | e702496 | 2006-08-23 06:49:00 | [diff] [blame] | 793 | hashcpy(sha1, ((struct tag*)it)->tagged->sha1); |
| Junio C Hamano | ea4a19e | 2006-04-30 07:54:29 | [diff] [blame] | 794 | } |
| Linus Torvalds | 1974632 | 2006-07-12 03:45:31 | [diff] [blame] | 795 | if (it->type != OBJ_COMMIT) |
| Junio C Hamano | ea4a19e | 2006-04-30 07:54:29 | [diff] [blame] | 796 | return 0; |
| 797 | commit = (struct commit *)it; |
| 798 | for (parents = commit->parents; parents; parents = parents->next) { |
| 799 | it = &parents->item->object; |
| 800 | it->flags |= flags; |
| 801 | add_pending_object(revs, it, arg); |
| 802 | } |
| 803 | return 1; |
| 804 | } |
| 805 | |
| Linus Torvalds | db6296a | 2006-07-29 04:21:48 | [diff] [blame] | 806 | void init_revisions(struct rev_info *revs, const char *prefix) |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 807 | { |
| 808 | memset(revs, 0, sizeof(*revs)); |
| Junio C Hamano | 8e8f998 | 2006-04-15 05:19:38 | [diff] [blame] | 809 | |
| Junio C Hamano | 6b9c58f | 2006-04-16 06:46:36 | [diff] [blame] | 810 | revs->abbrev = DEFAULT_ABBREV; |
| Junio C Hamano | 8e8f998 | 2006-04-15 05:19:38 | [diff] [blame] | 811 | revs->ignore_merges = 1; |
| Linus Torvalds | 9202434 | 2006-06-11 17:57:35 | [diff] [blame] | 812 | revs->simplify_history = 1; |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 813 | DIFF_OPT_SET(&revs->pruning, RECURSIVE); |
| Junio C Hamano | 90b1994 | 2009-05-23 08:15:35 | [diff] [blame] | 814 | DIFF_OPT_SET(&revs->pruning, QUICK); |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 815 | revs->pruning.add_remove = file_add_remove; |
| 816 | revs->pruning.change = file_change; |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 817 | revs->lifo = 1; |
| 818 | revs->dense = 1; |
| Linus Torvalds | db6296a | 2006-07-29 04:21:48 | [diff] [blame] | 819 | revs->prefix = prefix; |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 820 | revs->max_age = -1; |
| 821 | revs->min_age = -1; |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 822 | revs->skip_count = -1; |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 823 | revs->max_count = -1; |
| 824 | |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 825 | revs->commit_format = CMIT_FMT_DEFAULT; |
| 826 | |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 827 | revs->grep_filter.status_only = 1; |
| 828 | revs->grep_filter.pattern_tail = &(revs->grep_filter.pattern_list); |
| Junio C Hamano | 80235ba | 2010-01-18 04:09:06 | [diff] [blame] | 829 | revs->grep_filter.header_tail = &(revs->grep_filter.header_list); |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 830 | revs->grep_filter.regflags = REG_NEWLINE; |
| 831 | |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 832 | diff_setup(&revs->diffopt); |
| Junio C Hamano | c0cb4a0 | 2008-02-13 08:34:39 | [diff] [blame] | 833 | if (prefix && !revs->diffopt.prefix) { |
| Junio C Hamano | cd676a5 | 2008-02-12 22:26:02 | [diff] [blame] | 834 | revs->diffopt.prefix = prefix; |
| 835 | revs->diffopt.prefix_length = strlen(prefix); |
| 836 | } |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 837 | } |
| 838 | |
| Rene Scharfe | 0d2c9d6 | 2006-07-01 23:29:37 | [diff] [blame] | 839 | static void add_pending_commit_list(struct rev_info *revs, |
| 840 | struct commit_list *commit_list, |
| 841 | unsigned int flags) |
| 842 | { |
| 843 | while (commit_list) { |
| 844 | struct object *object = &commit_list->item->object; |
| 845 | object->flags |= flags; |
| 846 | add_pending_object(revs, object, sha1_to_hex(object->sha1)); |
| 847 | commit_list = commit_list->next; |
| 848 | } |
| 849 | } |
| 850 | |
| Junio C Hamano | ae3e5e1 | 2006-07-03 09:59:32 | [diff] [blame] | 851 | static void prepare_show_merge(struct rev_info *revs) |
| 852 | { |
| 853 | struct commit_list *bases; |
| 854 | struct commit *head, *other; |
| 855 | unsigned char sha1[20]; |
| 856 | const char **prune = NULL; |
| 857 | int i, prune_num = 1; /* counting terminating NULL */ |
| 858 | |
| 859 | if (get_sha1("HEAD", sha1) || !(head = lookup_commit(sha1))) |
| 860 | die("--merge without HEAD?"); |
| 861 | if (get_sha1("MERGE_HEAD", sha1) || !(other = lookup_commit(sha1))) |
| 862 | die("--merge without MERGE_HEAD?"); |
| 863 | add_pending_object(revs, &head->object, "HEAD"); |
| 864 | add_pending_object(revs, &other->object, "MERGE_HEAD"); |
| 865 | bases = get_merge_bases(head, other, 1); |
| Junio C Hamano | e82447b | 2008-02-27 07:18:38 | [diff] [blame] | 866 | add_pending_commit_list(revs, bases, UNINTERESTING); |
| 867 | free_commit_list(bases); |
| 868 | head->object.flags |= SYMMETRIC_LEFT; |
| Junio C Hamano | ae3e5e1 | 2006-07-03 09:59:32 | [diff] [blame] | 869 | |
| 870 | if (!active_nr) |
| 871 | read_cache(); |
| 872 | for (i = 0; i < active_nr; i++) { |
| 873 | struct cache_entry *ce = active_cache[i]; |
| 874 | if (!ce_stage(ce)) |
| 875 | continue; |
| 876 | if (ce_path_match(ce, revs->prune_data)) { |
| 877 | prune_num++; |
| 878 | prune = xrealloc(prune, sizeof(*prune) * prune_num); |
| 879 | prune[prune_num-2] = ce->name; |
| 880 | prune[prune_num-1] = NULL; |
| 881 | } |
| 882 | while ((i+1 < active_nr) && |
| 883 | ce_same_name(ce, active_cache[i+1])) |
| 884 | i++; |
| 885 | } |
| 886 | revs->prune_data = prune; |
| Junio C Hamano | e82447b | 2008-02-27 07:18:38 | [diff] [blame] | 887 | revs->limited = 1; |
| Junio C Hamano | ae3e5e1 | 2006-07-03 09:59:32 | [diff] [blame] | 888 | } |
| 889 | |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 890 | int handle_revision_arg(const char *arg, struct rev_info *revs, |
| 891 | int flags, |
| 892 | int cant_be_filename) |
| 893 | { |
| Martin Koegler | bb6c2fb | 2007-04-22 16:43:59 | [diff] [blame] | 894 | unsigned mode; |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 895 | char *dotdot; |
| 896 | struct object *object; |
| 897 | unsigned char sha1[20]; |
| 898 | int local_flags; |
| 899 | |
| 900 | dotdot = strstr(arg, ".."); |
| 901 | if (dotdot) { |
| 902 | unsigned char from_sha1[20]; |
| 903 | const char *next = dotdot + 2; |
| 904 | const char *this = arg; |
| 905 | int symmetric = *next == '.'; |
| 906 | unsigned int flags_exclude = flags ^ UNINTERESTING; |
| 907 | |
| 908 | *dotdot = 0; |
| 909 | next += symmetric; |
| 910 | |
| 911 | if (!*next) |
| 912 | next = "HEAD"; |
| 913 | if (dotdot == arg) |
| 914 | this = "HEAD"; |
| 915 | if (!get_sha1(this, from_sha1) && |
| 916 | !get_sha1(next, sha1)) { |
| 917 | struct commit *a, *b; |
| 918 | struct commit_list *exclude; |
| 919 | |
| 920 | a = lookup_commit_reference(from_sha1); |
| 921 | b = lookup_commit_reference(sha1); |
| 922 | if (!a || !b) { |
| 923 | die(symmetric ? |
| 924 | "Invalid symmetric difference expression %s...%s" : |
| 925 | "Invalid revision range %s..%s", |
| 926 | arg, next); |
| 927 | } |
| 928 | |
| 929 | if (!cant_be_filename) { |
| 930 | *dotdot = '.'; |
| 931 | verify_non_filename(revs->prefix, arg); |
| 932 | } |
| 933 | |
| 934 | if (symmetric) { |
| 935 | exclude = get_merge_bases(a, b, 1); |
| 936 | add_pending_commit_list(revs, exclude, |
| 937 | flags_exclude); |
| 938 | free_commit_list(exclude); |
| Junio C Hamano | 577ed5c | 2006-10-23 00:32:47 | [diff] [blame] | 939 | a->object.flags |= flags | SYMMETRIC_LEFT; |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 940 | } else |
| 941 | a->object.flags |= flags_exclude; |
| 942 | b->object.flags |= flags; |
| 943 | add_pending_object(revs, &a->object, this); |
| 944 | add_pending_object(revs, &b->object, next); |
| 945 | return 0; |
| 946 | } |
| 947 | *dotdot = '.'; |
| 948 | } |
| 949 | dotdot = strstr(arg, "^@"); |
| 950 | if (dotdot && !dotdot[2]) { |
| 951 | *dotdot = 0; |
| 952 | if (add_parents_only(revs, arg, flags)) |
| 953 | return 0; |
| 954 | *dotdot = '^'; |
| 955 | } |
| Junio C Hamano | 62476c8 | 2006-10-31 22:22:34 | [diff] [blame] | 956 | dotdot = strstr(arg, "^!"); |
| 957 | if (dotdot && !dotdot[2]) { |
| 958 | *dotdot = 0; |
| 959 | if (!add_parents_only(revs, arg, flags ^ UNINTERESTING)) |
| 960 | *dotdot = '^'; |
| 961 | } |
| 962 | |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 963 | local_flags = 0; |
| 964 | if (*arg == '^') { |
| 965 | local_flags = UNINTERESTING; |
| 966 | arg++; |
| 967 | } |
| Martin Koegler | bb6c2fb | 2007-04-22 16:43:59 | [diff] [blame] | 968 | if (get_sha1_with_mode(arg, sha1, &mode)) |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 969 | return -1; |
| 970 | if (!cant_be_filename) |
| 971 | verify_non_filename(revs->prefix, arg); |
| 972 | object = get_reference(revs, arg, sha1, flags ^ local_flags); |
| Martin Koegler | bb6c2fb | 2007-04-22 16:43:59 | [diff] [blame] | 973 | add_pending_object_with_mode(revs, object, arg, mode); |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 974 | return 0; |
| 975 | } |
| 976 | |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 977 | static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb, const char ***prune_data) |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 978 | { |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 979 | const char **prune = *prune_data; |
| 980 | int prune_nr; |
| 981 | int prune_alloc; |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 982 | |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 983 | /* count existing ones */ |
| 984 | if (!prune) |
| 985 | prune_nr = 0; |
| 986 | else |
| 987 | for (prune_nr = 0; prune[prune_nr]; prune_nr++) |
| 988 | ; |
| 989 | prune_alloc = prune_nr; /* not really, but we do not know */ |
| 990 | |
| 991 | while (strbuf_getwholeline(sb, stdin, '\n') != EOF) { |
| 992 | int len = sb->len; |
| 993 | if (len && sb->buf[len - 1] == '\n') |
| 994 | sb->buf[--len] = '\0'; |
| 995 | ALLOC_GROW(prune, prune_nr+1, prune_alloc); |
| 996 | prune[prune_nr++] = xstrdup(sb->buf); |
| 997 | } |
| 998 | if (prune) { |
| 999 | ALLOC_GROW(prune, prune_nr+1, prune_alloc); |
| 1000 | prune[prune_nr] = NULL; |
| 1001 | } |
| 1002 | *prune_data = prune; |
| 1003 | } |
| 1004 | |
| 1005 | static void read_revisions_from_stdin(struct rev_info *revs, const char ***prune) |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 1006 | { |
| Junio C Hamano | 63d564b | 2009-11-20 10:00:40 | [diff] [blame] | 1007 | struct strbuf sb; |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 1008 | int seen_dashdash = 0; |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 1009 | |
| Junio C Hamano | 63d564b | 2009-11-20 10:00:40 | [diff] [blame] | 1010 | strbuf_init(&sb, 1000); |
| 1011 | while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) { |
| 1012 | int len = sb.len; |
| 1013 | if (len && sb.buf[len - 1] == '\n') |
| 1014 | sb.buf[--len] = '\0'; |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 1015 | if (!len) |
| 1016 | break; |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 1017 | if (sb.buf[0] == '-') { |
| 1018 | if (len == 2 && sb.buf[1] == '-') { |
| 1019 | seen_dashdash = 1; |
| 1020 | break; |
| 1021 | } |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 1022 | die("options not supported in --stdin mode"); |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 1023 | } |
| Junio C Hamano | 63d564b | 2009-11-20 10:00:40 | [diff] [blame] | 1024 | if (handle_revision_arg(sb.buf, revs, 0, 1)) |
| 1025 | die("bad revision '%s'", sb.buf); |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 1026 | } |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 1027 | if (seen_dashdash) |
| 1028 | read_pathspec_from_stdin(revs, &sb, prune); |
| Junio C Hamano | 63d564b | 2009-11-20 10:00:40 | [diff] [blame] | 1029 | strbuf_release(&sb); |
| Adam Brewster | 1fc561d | 2008-07-05 21:26:39 | [diff] [blame] | 1030 | } |
| 1031 | |
| Junio C Hamano | 2d10c55 | 2006-09-20 20:21:56 | [diff] [blame] | 1032 | static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what) |
| 1033 | { |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 1034 | append_grep_pattern(&revs->grep_filter, ptn, "command line", 0, what); |
| Junio C Hamano | 2d10c55 | 2006-09-20 20:21:56 | [diff] [blame] | 1035 | } |
| 1036 | |
| Junio C Hamano | a4d7d2c | 2008-09-05 05:15:02 | [diff] [blame] | 1037 | static void add_header_grep(struct rev_info *revs, enum grep_header_field field, const char *pattern) |
| Junio C Hamano | bd95fcd | 2006-09-18 00:23:20 | [diff] [blame] | 1038 | { |
| Junio C Hamano | a4d7d2c | 2008-09-05 05:15:02 | [diff] [blame] | 1039 | append_header_grep_pattern(&revs->grep_filter, field, pattern); |
| Junio C Hamano | bd95fcd | 2006-09-18 00:23:20 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | static void add_message_grep(struct rev_info *revs, const char *pattern) |
| 1043 | { |
| Junio C Hamano | 2d10c55 | 2006-09-20 20:21:56 | [diff] [blame] | 1044 | add_grep(revs, pattern, GREP_PATTERN_BODY); |
| Junio C Hamano | bd95fcd | 2006-09-18 00:23:20 | [diff] [blame] | 1045 | } |
| 1046 | |
| Pierre Habouzit | 6b61ec0 | 2008-07-09 21:38:34 | [diff] [blame] | 1047 | static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv, |
| 1048 | int *unkc, const char **unkv) |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1049 | { |
| 1050 | const char *arg = argv[0]; |
| 1051 | |
| 1052 | /* pseudo revision arguments */ |
| 1053 | if (!strcmp(arg, "--all") || !strcmp(arg, "--branches") || |
| 1054 | !strcmp(arg, "--tags") || !strcmp(arg, "--remotes") || |
| 1055 | !strcmp(arg, "--reflog") || !strcmp(arg, "--not") || |
| Linus Torvalds | ad3f9a7 | 2009-10-27 18:28:07 | [diff] [blame] | 1056 | !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") || |
| 1057 | !strcmp(arg, "--bisect")) |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1058 | { |
| 1059 | unkv[(*unkc)++] = arg; |
| Pierre Habouzit | 0fe8c13 | 2008-07-31 10:22:23 | [diff] [blame] | 1060 | return 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | if (!prefixcmp(arg, "--max-count=")) { |
| 1064 | revs->max_count = atoi(arg + 12); |
| 1065 | } else if (!prefixcmp(arg, "--skip=")) { |
| 1066 | revs->skip_count = atoi(arg + 7); |
| 1067 | } else if ((*arg == '-') && isdigit(arg[1])) { |
| 1068 | /* accept -<digit>, like traditional "head" */ |
| 1069 | revs->max_count = atoi(arg + 1); |
| 1070 | } else if (!strcmp(arg, "-n")) { |
| 1071 | if (argc <= 1) |
| 1072 | return error("-n requires an argument"); |
| 1073 | revs->max_count = atoi(argv[1]); |
| 1074 | return 2; |
| 1075 | } else if (!prefixcmp(arg, "-n")) { |
| 1076 | revs->max_count = atoi(arg + 2); |
| 1077 | } else if (!prefixcmp(arg, "--max-age=")) { |
| 1078 | revs->max_age = atoi(arg + 10); |
| 1079 | } else if (!prefixcmp(arg, "--since=")) { |
| 1080 | revs->max_age = approxidate(arg + 8); |
| 1081 | } else if (!prefixcmp(arg, "--after=")) { |
| 1082 | revs->max_age = approxidate(arg + 8); |
| 1083 | } else if (!prefixcmp(arg, "--min-age=")) { |
| 1084 | revs->min_age = atoi(arg + 10); |
| 1085 | } else if (!prefixcmp(arg, "--before=")) { |
| 1086 | revs->min_age = approxidate(arg + 9); |
| 1087 | } else if (!prefixcmp(arg, "--until=")) { |
| 1088 | revs->min_age = approxidate(arg + 8); |
| 1089 | } else if (!strcmp(arg, "--first-parent")) { |
| 1090 | revs->first_parent_only = 1; |
| 1091 | } else if (!strcmp(arg, "-g") || !strcmp(arg, "--walk-reflogs")) { |
| 1092 | init_reflog_walk(&revs->reflog_info); |
| 1093 | } else if (!strcmp(arg, "--default")) { |
| 1094 | if (argc <= 1) |
| 1095 | return error("bad --default argument"); |
| 1096 | revs->def = argv[1]; |
| 1097 | return 2; |
| 1098 | } else if (!strcmp(arg, "--merge")) { |
| 1099 | revs->show_merge = 1; |
| 1100 | } else if (!strcmp(arg, "--topo-order")) { |
| 1101 | revs->lifo = 1; |
| 1102 | revs->topo_order = 1; |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1103 | } else if (!strcmp(arg, "--simplify-merges")) { |
| 1104 | revs->simplify_merges = 1; |
| 1105 | revs->rewrite_parents = 1; |
| 1106 | revs->simplify_history = 0; |
| 1107 | revs->limited = 1; |
| Linus Torvalds | 78892e3 | 2008-11-03 19:25:46 | [diff] [blame] | 1108 | } else if (!strcmp(arg, "--simplify-by-decoration")) { |
| 1109 | revs->simplify_merges = 1; |
| 1110 | revs->rewrite_parents = 1; |
| 1111 | revs->simplify_history = 0; |
| 1112 | revs->simplify_by_decoration = 1; |
| 1113 | revs->limited = 1; |
| 1114 | revs->prune = 1; |
| Lars Hjemli | 33e7018 | 2009-08-15 14:23:12 | [diff] [blame] | 1115 | load_ref_decorations(DECORATE_SHORT_REFS); |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1116 | } else if (!strcmp(arg, "--date-order")) { |
| 1117 | revs->lifo = 0; |
| 1118 | revs->topo_order = 1; |
| 1119 | } else if (!prefixcmp(arg, "--early-output")) { |
| 1120 | int count = 100; |
| 1121 | switch (arg[14]) { |
| 1122 | case '=': |
| 1123 | count = atoi(arg+15); |
| 1124 | /* Fallthrough */ |
| 1125 | case 0: |
| 1126 | revs->topo_order = 1; |
| 1127 | revs->early_output = count; |
| 1128 | } |
| 1129 | } else if (!strcmp(arg, "--parents")) { |
| 1130 | revs->rewrite_parents = 1; |
| 1131 | revs->print_parents = 1; |
| 1132 | } else if (!strcmp(arg, "--dense")) { |
| 1133 | revs->dense = 1; |
| 1134 | } else if (!strcmp(arg, "--sparse")) { |
| 1135 | revs->dense = 0; |
| 1136 | } else if (!strcmp(arg, "--show-all")) { |
| 1137 | revs->show_all = 1; |
| 1138 | } else if (!strcmp(arg, "--remove-empty")) { |
| 1139 | revs->remove_empty_trees = 1; |
| Linus Torvalds | b8e8db2 | 2009-06-29 17:28:25 | [diff] [blame] | 1140 | } else if (!strcmp(arg, "--merges")) { |
| 1141 | revs->merges_only = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1142 | } else if (!strcmp(arg, "--no-merges")) { |
| 1143 | revs->no_merges = 1; |
| 1144 | } else if (!strcmp(arg, "--boundary")) { |
| 1145 | revs->boundary = 1; |
| 1146 | } else if (!strcmp(arg, "--left-right")) { |
| 1147 | revs->left_right = 1; |
| 1148 | } else if (!strcmp(arg, "--cherry-pick")) { |
| 1149 | revs->cherry_pick = 1; |
| 1150 | revs->limited = 1; |
| 1151 | } else if (!strcmp(arg, "--objects")) { |
| 1152 | revs->tag_objects = 1; |
| 1153 | revs->tree_objects = 1; |
| 1154 | revs->blob_objects = 1; |
| 1155 | } else if (!strcmp(arg, "--objects-edge")) { |
| 1156 | revs->tag_objects = 1; |
| 1157 | revs->tree_objects = 1; |
| 1158 | revs->blob_objects = 1; |
| 1159 | revs->edge_hint = 1; |
| 1160 | } else if (!strcmp(arg, "--unpacked")) { |
| 1161 | revs->unpacked = 1; |
| Junio C Hamano | 03a9683 | 2009-02-28 08:00:21 | [diff] [blame] | 1162 | } else if (!prefixcmp(arg, "--unpacked=")) { |
| 1163 | die("--unpacked=<packfile> no longer supported."); |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1164 | } else if (!strcmp(arg, "-r")) { |
| 1165 | revs->diff = 1; |
| 1166 | DIFF_OPT_SET(&revs->diffopt, RECURSIVE); |
| 1167 | } else if (!strcmp(arg, "-t")) { |
| 1168 | revs->diff = 1; |
| 1169 | DIFF_OPT_SET(&revs->diffopt, RECURSIVE); |
| 1170 | DIFF_OPT_SET(&revs->diffopt, TREE_IN_RECURSIVE); |
| 1171 | } else if (!strcmp(arg, "-m")) { |
| 1172 | revs->ignore_merges = 0; |
| 1173 | } else if (!strcmp(arg, "-c")) { |
| 1174 | revs->diff = 1; |
| 1175 | revs->dense_combined_merges = 0; |
| 1176 | revs->combine_merges = 1; |
| 1177 | } else if (!strcmp(arg, "--cc")) { |
| 1178 | revs->diff = 1; |
| 1179 | revs->dense_combined_merges = 1; |
| 1180 | revs->combine_merges = 1; |
| 1181 | } else if (!strcmp(arg, "-v")) { |
| 1182 | revs->verbose_header = 1; |
| 1183 | } else if (!strcmp(arg, "--pretty")) { |
| 1184 | revs->verbose_header = 1; |
| Junio C Hamano | 66b2ed0 | 2010-01-20 21:59:36 | [diff] [blame] | 1185 | revs->pretty_given = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1186 | get_commit_format(arg+8, revs); |
| Nanako Shiraishi | 3a4c1a5 | 2009-02-24 09:59:14 | [diff] [blame] | 1187 | } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) { |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1188 | revs->verbose_header = 1; |
| Junio C Hamano | 66b2ed0 | 2010-01-20 21:59:36 | [diff] [blame] | 1189 | revs->pretty_given = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1190 | get_commit_format(arg+9, revs); |
| Junio C Hamano | 66b2ed0 | 2010-01-20 21:59:36 | [diff] [blame] | 1191 | } else if (!strcmp(arg, "--show-notes")) { |
| 1192 | revs->show_notes = 1; |
| 1193 | revs->show_notes_given = 1; |
| 1194 | } else if (!strcmp(arg, "--no-notes")) { |
| 1195 | revs->show_notes = 0; |
| 1196 | revs->show_notes_given = 1; |
| Nanako Shiraishi | de84acc | 2009-02-24 09:59:16 | [diff] [blame] | 1197 | } else if (!strcmp(arg, "--oneline")) { |
| 1198 | revs->verbose_header = 1; |
| 1199 | get_commit_format("oneline", revs); |
| Junio C Hamano | 7dccadf | 2010-01-21 22:57:41 | [diff] [blame] | 1200 | revs->pretty_given = 1; |
| Nanako Shiraishi | de84acc | 2009-02-24 09:59:16 | [diff] [blame] | 1201 | revs->abbrev_commit = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1202 | } else if (!strcmp(arg, "--graph")) { |
| 1203 | revs->topo_order = 1; |
| 1204 | revs->rewrite_parents = 1; |
| 1205 | revs->graph = graph_init(revs); |
| 1206 | } else if (!strcmp(arg, "--root")) { |
| 1207 | revs->show_root_diff = 1; |
| 1208 | } else if (!strcmp(arg, "--no-commit-id")) { |
| 1209 | revs->no_commit_id = 1; |
| 1210 | } else if (!strcmp(arg, "--always")) { |
| 1211 | revs->always_show_header = 1; |
| 1212 | } else if (!strcmp(arg, "--no-abbrev")) { |
| 1213 | revs->abbrev = 0; |
| 1214 | } else if (!strcmp(arg, "--abbrev")) { |
| 1215 | revs->abbrev = DEFAULT_ABBREV; |
| 1216 | } else if (!prefixcmp(arg, "--abbrev=")) { |
| 1217 | revs->abbrev = strtoul(arg + 9, NULL, 10); |
| 1218 | if (revs->abbrev < MINIMUM_ABBREV) |
| 1219 | revs->abbrev = MINIMUM_ABBREV; |
| 1220 | else if (revs->abbrev > 40) |
| 1221 | revs->abbrev = 40; |
| 1222 | } else if (!strcmp(arg, "--abbrev-commit")) { |
| 1223 | revs->abbrev_commit = 1; |
| 1224 | } else if (!strcmp(arg, "--full-diff")) { |
| 1225 | revs->diff = 1; |
| 1226 | revs->full_diff = 1; |
| 1227 | } else if (!strcmp(arg, "--full-history")) { |
| 1228 | revs->simplify_history = 0; |
| 1229 | } else if (!strcmp(arg, "--relative-date")) { |
| 1230 | revs->date_mode = DATE_RELATIVE; |
| Jeff King | f4ea32f | 2009-09-24 08:28:15 | [diff] [blame] | 1231 | revs->date_mode_explicit = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1232 | } else if (!strncmp(arg, "--date=", 7)) { |
| 1233 | revs->date_mode = parse_date_format(arg + 7); |
| Jeff King | f4ea32f | 2009-09-24 08:28:15 | [diff] [blame] | 1234 | revs->date_mode_explicit = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1235 | } else if (!strcmp(arg, "--log-size")) { |
| 1236 | revs->show_log_size = 1; |
| 1237 | } |
| 1238 | /* |
| 1239 | * Grepping the commit log |
| 1240 | */ |
| 1241 | else if (!prefixcmp(arg, "--author=")) { |
| Junio C Hamano | a4d7d2c | 2008-09-05 05:15:02 | [diff] [blame] | 1242 | add_header_grep(revs, GREP_HEADER_AUTHOR, arg+9); |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1243 | } else if (!prefixcmp(arg, "--committer=")) { |
| Junio C Hamano | a4d7d2c | 2008-09-05 05:15:02 | [diff] [blame] | 1244 | add_header_grep(revs, GREP_HEADER_COMMITTER, arg+12); |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1245 | } else if (!prefixcmp(arg, "--grep=")) { |
| 1246 | add_message_grep(revs, arg+7); |
| 1247 | } else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) { |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 1248 | revs->grep_filter.regflags |= REG_EXTENDED; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1249 | } else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) { |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 1250 | revs->grep_filter.regflags |= REG_ICASE; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1251 | } else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) { |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 1252 | revs->grep_filter.fixed = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1253 | } else if (!strcmp(arg, "--all-match")) { |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 1254 | revs->grep_filter.all_match = 1; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1255 | } else if (!prefixcmp(arg, "--encoding=")) { |
| 1256 | arg += 11; |
| 1257 | if (strcmp(arg, "none")) |
| 1258 | git_log_output_encoding = xstrdup(arg); |
| 1259 | else |
| 1260 | git_log_output_encoding = ""; |
| 1261 | } else if (!strcmp(arg, "--reverse")) { |
| 1262 | revs->reverse ^= 1; |
| 1263 | } else if (!strcmp(arg, "--children")) { |
| 1264 | revs->children.name = "children"; |
| 1265 | revs->limited = 1; |
| 1266 | } else { |
| 1267 | int opts = diff_opt_parse(&revs->diffopt, argv, argc); |
| 1268 | if (!opts) |
| 1269 | unkv[(*unkc)++] = arg; |
| 1270 | return opts; |
| 1271 | } |
| 1272 | |
| 1273 | return 1; |
| 1274 | } |
| 1275 | |
| Pierre Habouzit | 6b61ec0 | 2008-07-09 21:38:34 | [diff] [blame] | 1276 | void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, |
| 1277 | const struct option *options, |
| 1278 | const char * const usagestr[]) |
| 1279 | { |
| 1280 | int n = handle_revision_opt(revs, ctx->argc, ctx->argv, |
| 1281 | &ctx->cpidx, ctx->out); |
| 1282 | if (n <= 0) { |
| 1283 | error("unknown option `%s'", ctx->argv[0]); |
| 1284 | usage_with_options(usagestr, options); |
| 1285 | } |
| 1286 | ctx->argv += n; |
| 1287 | ctx->argc -= n; |
| 1288 | } |
| 1289 | |
| Linus Torvalds | ad3f9a7 | 2009-10-27 18:28:07 | [diff] [blame] | 1290 | static int for_each_bad_bisect_ref(each_ref_fn fn, void *cb_data) |
| 1291 | { |
| 1292 | return for_each_ref_in("refs/bisect/bad", fn, cb_data); |
| 1293 | } |
| 1294 | |
| 1295 | static int for_each_good_bisect_ref(each_ref_fn fn, void *cb_data) |
| 1296 | { |
| 1297 | return for_each_ref_in("refs/bisect/good", fn, cb_data); |
| 1298 | } |
| 1299 | |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 1300 | static void append_prune_data(const char ***prune_data, const char **av) |
| 1301 | { |
| 1302 | const char **prune = *prune_data; |
| 1303 | int prune_nr; |
| 1304 | int prune_alloc; |
| 1305 | |
| 1306 | if (!prune) { |
| 1307 | *prune_data = av; |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | /* count existing ones */ |
| 1312 | for (prune_nr = 0; prune[prune_nr]; prune_nr++) |
| 1313 | ; |
| 1314 | prune_alloc = prune_nr; /* not really, but we do not know */ |
| 1315 | |
| 1316 | while (*av) { |
| 1317 | ALLOC_GROW(prune, prune_nr+1, prune_alloc); |
| 1318 | prune[prune_nr++] = *av; |
| 1319 | av++; |
| 1320 | } |
| 1321 | if (prune) { |
| 1322 | ALLOC_GROW(prune, prune_nr+1, prune_alloc); |
| 1323 | prune[prune_nr] = NULL; |
| 1324 | } |
| 1325 | *prune_data = prune; |
| 1326 | } |
| 1327 | |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1328 | /* |
| 1329 | * Parse revision information, filling in the "rev_info" structure, |
| 1330 | * and removing the used arguments from the argument list. |
| 1331 | * |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1332 | * Returns the number of arguments left that weren't recognized |
| 1333 | * (which are also moved to the head of the argument list) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1334 | */ |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1335 | int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def) |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1336 | { |
| Dave Olszewski | 8fcaca3 | 2010-03-13 22:47:05 | [diff] [blame] | 1337 | int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0; |
| Junio C Hamano | 5486ef0 | 2009-11-20 10:33:28 | [diff] [blame] | 1338 | const char **prune_data = NULL; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1339 | |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1340 | /* First, search for "--" */ |
| 1341 | seen_dashdash = 0; |
| 1342 | for (i = 1; i < argc; i++) { |
| 1343 | const char *arg = argv[i]; |
| 1344 | if (strcmp(arg, "--")) |
| 1345 | continue; |
| 1346 | argv[i] = NULL; |
| 1347 | argc = i; |
| Junio C Hamano | a65f200 | 2007-08-31 05:58:26 | [diff] [blame] | 1348 | if (argv[i + 1]) |
| Junio C Hamano | 5486ef0 | 2009-11-20 10:33:28 | [diff] [blame] | 1349 | prune_data = argv + i + 1; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1350 | seen_dashdash = 1; |
| 1351 | break; |
| 1352 | } |
| 1353 | |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1354 | /* Second, deal with arguments and options */ |
| 1355 | flags = 0; |
| Junio C Hamano | 8b3dce5 | 2009-11-03 14:59:18 | [diff] [blame] | 1356 | read_from_stdin = 0; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1357 | for (left = i = 1; i < argc; i++) { |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1358 | const char *arg = argv[i]; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1359 | if (*arg == '-') { |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1360 | int opts; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1361 | |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1362 | if (!strcmp(arg, "--all")) { |
| Uwe Kleine-König | a5aa930 | 2008-02-28 07:24:25 | [diff] [blame] | 1363 | handle_refs(revs, flags, for_each_ref); |
| Johannes Schindelin | f0298cf | 2009-01-16 12:52:53 | [diff] [blame] | 1364 | handle_refs(revs, flags, head_ref); |
| Uwe Kleine-König | a5aa930 | 2008-02-28 07:24:25 | [diff] [blame] | 1365 | continue; |
| 1366 | } |
| 1367 | if (!strcmp(arg, "--branches")) { |
| 1368 | handle_refs(revs, flags, for_each_branch_ref); |
| 1369 | continue; |
| 1370 | } |
| Linus Torvalds | ad3f9a7 | 2009-10-27 18:28:07 | [diff] [blame] | 1371 | if (!strcmp(arg, "--bisect")) { |
| 1372 | handle_refs(revs, flags, for_each_bad_bisect_ref); |
| 1373 | handle_refs(revs, flags ^ UNINTERESTING, for_each_good_bisect_ref); |
| 1374 | revs->bisect = 1; |
| 1375 | continue; |
| 1376 | } |
| Uwe Kleine-König | a5aa930 | 2008-02-28 07:24:25 | [diff] [blame] | 1377 | if (!strcmp(arg, "--tags")) { |
| 1378 | handle_refs(revs, flags, for_each_tag_ref); |
| 1379 | continue; |
| 1380 | } |
| 1381 | if (!strcmp(arg, "--remotes")) { |
| 1382 | handle_refs(revs, flags, for_each_remote_ref); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1383 | continue; |
| 1384 | } |
| Ilari Liusvaara | d08bae7 | 2010-01-20 09:48:25 | [diff] [blame] | 1385 | if (!prefixcmp(arg, "--glob=")) { |
| 1386 | struct all_refs_cb cb; |
| 1387 | init_all_refs_cb(&cb, revs, flags); |
| 1388 | for_each_glob_ref(handle_one_ref, arg + 7, &cb); |
| 1389 | continue; |
| 1390 | } |
| Ilari Liusvaara | b09fe97 | 2010-01-20 09:48:26 | [diff] [blame] | 1391 | if (!prefixcmp(arg, "--branches=")) { |
| 1392 | struct all_refs_cb cb; |
| 1393 | init_all_refs_cb(&cb, revs, flags); |
| 1394 | for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb); |
| 1395 | continue; |
| 1396 | } |
| 1397 | if (!prefixcmp(arg, "--tags=")) { |
| 1398 | struct all_refs_cb cb; |
| 1399 | init_all_refs_cb(&cb, revs, flags); |
| 1400 | for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb); |
| 1401 | continue; |
| 1402 | } |
| 1403 | if (!prefixcmp(arg, "--remotes=")) { |
| 1404 | struct all_refs_cb cb; |
| 1405 | init_all_refs_cb(&cb, revs, flags); |
| 1406 | for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb); |
| 1407 | continue; |
| 1408 | } |
| Junio C Hamano | 6304929 | 2006-12-19 01:25:28 | [diff] [blame] | 1409 | if (!strcmp(arg, "--reflog")) { |
| 1410 | handle_reflog(revs, flags); |
| 1411 | continue; |
| 1412 | } |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1413 | if (!strcmp(arg, "--not")) { |
| 1414 | flags ^= UNINTERESTING; |
| 1415 | continue; |
| 1416 | } |
| Johannes Schindelin | 8e64006 | 2007-07-23 23:38:40 | [diff] [blame] | 1417 | if (!strcmp(arg, "--no-walk")) { |
| 1418 | revs->no_walk = 1; |
| 1419 | continue; |
| 1420 | } |
| 1421 | if (!strcmp(arg, "--do-walk")) { |
| 1422 | revs->no_walk = 0; |
| 1423 | continue; |
| 1424 | } |
| Junio C Hamano | 8b3dce5 | 2009-11-03 14:59:18 | [diff] [blame] | 1425 | if (!strcmp(arg, "--stdin")) { |
| 1426 | if (revs->disable_stdin) { |
| 1427 | argv[left++] = arg; |
| 1428 | continue; |
| 1429 | } |
| 1430 | if (read_from_stdin++) |
| 1431 | die("--stdin given twice?"); |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 1432 | read_revisions_from_stdin(revs, &prune_data); |
| Junio C Hamano | 8b3dce5 | 2009-11-03 14:59:18 | [diff] [blame] | 1433 | continue; |
| 1434 | } |
| Junio C Hamano | 2d10c55 | 2006-09-20 20:21:56 | [diff] [blame] | 1435 | |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1436 | opts = handle_revision_opt(revs, argc - i, argv + i, &left, argv); |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1437 | if (opts > 0) { |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1438 | i += opts - 1; |
| 1439 | continue; |
| 1440 | } |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1441 | if (opts < 0) |
| 1442 | exit(128); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1443 | continue; |
| 1444 | } |
| Rene Scharfe | 0d2c9d6 | 2006-07-01 23:29:37 | [diff] [blame] | 1445 | |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 1446 | if (handle_revision_arg(arg, revs, flags, seen_dashdash)) { |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1447 | int j; |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 1448 | if (seen_dashdash || *arg == '^') |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1449 | die("bad revision '%s'", arg); |
| 1450 | |
| Junio C Hamano | ea92f41 | 2006-04-26 22:09:27 | [diff] [blame] | 1451 | /* If we didn't have a "--": |
| 1452 | * (1) all filenames must exist; |
| 1453 | * (2) all rev-args must not be interpretable |
| 1454 | * as a valid filename. |
| 1455 | * but the latter we have checked in the main loop. |
| 1456 | */ |
| Linus Torvalds | e23d0b4 | 2006-04-26 17:15:54 | [diff] [blame] | 1457 | for (j = i; j < argc; j++) |
| 1458 | verify_filename(revs->prefix, argv[j]); |
| 1459 | |
| Junio C Hamano | 60da8b1 | 2009-11-20 10:50:21 | [diff] [blame] | 1460 | append_prune_data(&prune_data, argv + i); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1461 | break; |
| 1462 | } |
| Dave Olszewski | 8fcaca3 | 2010-03-13 22:47:05 | [diff] [blame] | 1463 | else |
| 1464 | got_rev_arg = 1; |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1465 | } |
| Junio C Hamano | 5d6f093 | 2006-09-06 04:28:36 | [diff] [blame] | 1466 | |
| Junio C Hamano | 5486ef0 | 2009-11-20 10:33:28 | [diff] [blame] | 1467 | if (prune_data) |
| 1468 | revs->prune_data = get_pathspec(revs->prefix, prune_data); |
| 1469 | |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1470 | if (revs->def == NULL) |
| 1471 | revs->def = def; |
| 1472 | if (revs->show_merge) |
| Junio C Hamano | ae3e5e1 | 2006-07-03 09:59:32 | [diff] [blame] | 1473 | prepare_show_merge(revs); |
| Dave Olszewski | 8fcaca3 | 2010-03-13 22:47:05 | [diff] [blame] | 1474 | if (revs->def && !revs->pending.nr && !got_rev_arg) { |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1475 | unsigned char sha1[20]; |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1476 | struct object *object; |
| Martin Koegler | bb6c2fb | 2007-04-22 16:43:59 | [diff] [blame] | 1477 | unsigned mode; |
| Pierre Habouzit | 02e5422 | 2008-07-08 13:19:33 | [diff] [blame] | 1478 | if (get_sha1_with_mode(revs->def, sha1, &mode)) |
| 1479 | die("bad default revision '%s'", revs->def); |
| 1480 | object = get_reference(revs, revs->def, sha1, 0); |
| 1481 | add_pending_object_with_mode(revs, object, revs->def, mode); |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1482 | } |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 1483 | |
| Linus Torvalds | b7bb760 | 2007-09-29 16:50:39 | [diff] [blame] | 1484 | /* Did the user ask for any diff output? Run the diff! */ |
| 1485 | if (revs->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) |
| 1486 | revs->diff = 1; |
| 1487 | |
| Arjen Laarhoven | 0faf2da | 2007-12-25 11:06:47 | [diff] [blame] | 1488 | /* Pickaxe, diff-filter and rename following need diffs */ |
| 1489 | if (revs->diffopt.pickaxe || |
| 1490 | revs->diffopt.filter || |
| 1491 | DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES)) |
| Linus Torvalds | b7bb760 | 2007-09-29 16:50:39 | [diff] [blame] | 1492 | revs->diff = 1; |
| 1493 | |
| Junio C Hamano | 9dad9d2 | 2006-10-31 02:58:03 | [diff] [blame] | 1494 | if (revs->topo_order) |
| Junio C Hamano | 5306968 | 2006-04-02 02:38:25 | [diff] [blame] | 1495 | revs->limited = 1; |
| 1496 | |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 1497 | if (revs->prune_data) { |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1498 | diff_tree_setup_paths(revs->prune_data, &revs->pruning); |
| Linus Torvalds | 750f7b6 | 2007-06-19 21:22:46 | [diff] [blame] | 1499 | /* Can't prune commits with rename following: the paths change.. */ |
| Pierre Habouzit | 8f67f8a | 2007-11-10 19:05:14 | [diff] [blame] | 1500 | if (!DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES)) |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 1501 | revs->prune = 1; |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1502 | if (!revs->full_diff) |
| 1503 | diff_tree_setup_paths(revs->prune_data, &revs->diffopt); |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 1504 | } |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1505 | if (revs->combine_merges) { |
| 1506 | revs->ignore_merges = 0; |
| Timo Hirvonen | 0e677e1 | 2006-06-24 17:25:08 | [diff] [blame] | 1507 | if (revs->dense_combined_merges && !revs->diffopt.output_format) |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1508 | revs->diffopt.output_format = DIFF_FORMAT_PATCH; |
| 1509 | } |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1510 | revs->diffopt.abbrev = revs->abbrev; |
| Junio C Hamano | 72ee96c | 2006-08-09 19:45:27 | [diff] [blame] | 1511 | if (diff_setup_done(&revs->diffopt) < 0) |
| 1512 | die("diff_setup_done failed"); |
| Fredrik Kuivinen | 8efdc32 | 2006-03-10 09:21:39 | [diff] [blame] | 1513 | |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 1514 | compile_grep_patterns(&revs->grep_filter); |
| Junio C Hamano | bd95fcd | 2006-09-18 00:23:20 | [diff] [blame] | 1515 | |
| Shawn O. Pearce | d56651c | 2007-08-20 02:33:43 | [diff] [blame] | 1516 | if (revs->reverse && revs->reflog_info) |
| 1517 | die("cannot combine --reverse with --walk-reflogs"); |
| Junio C Hamano | 8bb6588 | 2008-07-08 22:25:44 | [diff] [blame] | 1518 | if (revs->rewrite_parents && revs->children.name) |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 1519 | die("cannot combine --parents and --children"); |
| Shawn O. Pearce | d56651c | 2007-08-20 02:33:43 | [diff] [blame] | 1520 | |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 1521 | /* |
| 1522 | * Limitations on the graph functionality |
| 1523 | */ |
| 1524 | if (revs->reverse && revs->graph) |
| 1525 | die("cannot combine --reverse with --graph"); |
| 1526 | |
| 1527 | if (revs->reflog_info && revs->graph) |
| 1528 | die("cannot combine --walk-reflogs with --graph"); |
| 1529 | |
| Linus Torvalds | ae56354 | 2006-02-26 00:19:46 | [diff] [blame] | 1530 | return left; |
| 1531 | } |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1532 | |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 1533 | static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child) |
| 1534 | { |
| 1535 | struct commit_list *l = xcalloc(1, sizeof(*l)); |
| 1536 | |
| 1537 | l->item = child; |
| 1538 | l->next = add_decoration(&revs->children, &parent->object, l); |
| 1539 | } |
| 1540 | |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1541 | static int remove_duplicate_parents(struct commit *commit) |
| 1542 | { |
| 1543 | struct commit_list **pp, *p; |
| 1544 | int surviving_parents; |
| 1545 | |
| 1546 | /* Examine existing parents while marking ones we have seen... */ |
| 1547 | pp = &commit->parents; |
| 1548 | while ((p = *pp) != NULL) { |
| 1549 | struct commit *parent = p->item; |
| 1550 | if (parent->object.flags & TMP_MARK) { |
| 1551 | *pp = p->next; |
| 1552 | continue; |
| 1553 | } |
| 1554 | parent->object.flags |= TMP_MARK; |
| 1555 | pp = &p->next; |
| 1556 | } |
| 1557 | /* count them while clearing the temporary mark */ |
| 1558 | surviving_parents = 0; |
| 1559 | for (p = commit->parents; p; p = p->next) { |
| 1560 | p->item->object.flags &= ~TMP_MARK; |
| 1561 | surviving_parents++; |
| 1562 | } |
| 1563 | return surviving_parents; |
| 1564 | } |
| 1565 | |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1566 | struct merge_simplify_state { |
| 1567 | struct commit *simplified; |
| 1568 | }; |
| 1569 | |
| 1570 | static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs, struct commit *commit) |
| 1571 | { |
| 1572 | struct merge_simplify_state *st; |
| 1573 | |
| 1574 | st = lookup_decoration(&revs->merge_simplification, &commit->object); |
| 1575 | if (!st) { |
| 1576 | st = xcalloc(1, sizeof(*st)); |
| 1577 | add_decoration(&revs->merge_simplification, &commit->object, st); |
| 1578 | } |
| 1579 | return st; |
| 1580 | } |
| 1581 | |
| 1582 | static struct commit_list **simplify_one(struct rev_info *revs, struct commit *commit, struct commit_list **tail) |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1583 | { |
| 1584 | struct commit_list *p; |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1585 | struct merge_simplify_state *st, *pst; |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1586 | int cnt; |
| 1587 | |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1588 | st = locate_simplify_state(revs, commit); |
| 1589 | |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1590 | /* |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1591 | * Have we handled this one? |
| 1592 | */ |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1593 | if (st->simplified) |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1594 | return tail; |
| 1595 | |
| 1596 | /* |
| 1597 | * An UNINTERESTING commit simplifies to itself, so does a |
| 1598 | * root commit. We do not rewrite parents of such commit |
| 1599 | * anyway. |
| 1600 | */ |
| 1601 | if ((commit->object.flags & UNINTERESTING) || !commit->parents) { |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1602 | st->simplified = commit; |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1603 | return tail; |
| 1604 | } |
| 1605 | |
| 1606 | /* |
| 1607 | * Do we know what commit all of our parents should be rewritten to? |
| 1608 | * Otherwise we are not ready to rewrite this one yet. |
| 1609 | */ |
| 1610 | for (cnt = 0, p = commit->parents; p; p = p->next) { |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1611 | pst = locate_simplify_state(revs, p->item); |
| 1612 | if (!pst->simplified) { |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1613 | tail = &commit_list_insert(p->item, tail)->next; |
| 1614 | cnt++; |
| 1615 | } |
| 1616 | } |
| Junio C Hamano | 53030f8 | 2008-08-18 07:37:34 | [diff] [blame] | 1617 | if (cnt) { |
| 1618 | tail = &commit_list_insert(commit, tail)->next; |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1619 | return tail; |
| Junio C Hamano | 53030f8 | 2008-08-18 07:37:34 | [diff] [blame] | 1620 | } |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1621 | |
| 1622 | /* |
| 1623 | * Rewrite our list of parents. |
| 1624 | */ |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1625 | for (p = commit->parents; p; p = p->next) { |
| 1626 | pst = locate_simplify_state(revs, p->item); |
| 1627 | p->item = pst->simplified; |
| 1628 | } |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1629 | cnt = remove_duplicate_parents(commit); |
| 1630 | |
| 1631 | /* |
| 1632 | * It is possible that we are a merge and one side branch |
| 1633 | * does not have any commit that touches the given paths; |
| 1634 | * in such a case, the immediate parents will be rewritten |
| 1635 | * to different commits. |
| 1636 | * |
| 1637 | * o----X X: the commit we are looking at; |
| 1638 | * / / o: a commit that touches the paths; |
| 1639 | * ---o----' |
| 1640 | * |
| 1641 | * Further reduce the parents by removing redundant parents. |
| 1642 | */ |
| 1643 | if (1 < cnt) { |
| 1644 | struct commit_list *h = reduce_heads(commit->parents); |
| 1645 | cnt = commit_list_count(h); |
| 1646 | free_commit_list(commit->parents); |
| 1647 | commit->parents = h; |
| 1648 | } |
| 1649 | |
| 1650 | /* |
| 1651 | * A commit simplifies to itself if it is a root, if it is |
| 1652 | * UNINTERESTING, if it touches the given paths, or if it is a |
| 1653 | * merge and its parents simplifies to more than one commits |
| 1654 | * (the first two cases are already handled at the beginning of |
| 1655 | * this function). |
| 1656 | * |
| 1657 | * Otherwise, it simplifies to what its sole parent simplifies to. |
| 1658 | */ |
| 1659 | if (!cnt || |
| 1660 | (commit->object.flags & UNINTERESTING) || |
| 1661 | !(commit->object.flags & TREESAME) || |
| 1662 | (1 < cnt)) |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1663 | st->simplified = commit; |
| 1664 | else { |
| 1665 | pst = locate_simplify_state(revs, commit->parents->item); |
| 1666 | st->simplified = pst->simplified; |
| 1667 | } |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1668 | return tail; |
| 1669 | } |
| 1670 | |
| 1671 | static void simplify_merges(struct rev_info *revs) |
| 1672 | { |
| 1673 | struct commit_list *list; |
| 1674 | struct commit_list *yet_to_do, **tail; |
| 1675 | |
| Junio C Hamano | 5eac739 | 2008-08-14 20:52:36 | [diff] [blame] | 1676 | if (!revs->topo_order) |
| 1677 | sort_in_topological_order(&revs->commits, revs->lifo); |
| 1678 | if (!revs->prune) |
| 1679 | return; |
| Junio C Hamano | 6534703 | 2008-08-04 00:47:16 | [diff] [blame] | 1680 | |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1681 | /* feed the list reversed */ |
| 1682 | yet_to_do = NULL; |
| 1683 | for (list = revs->commits; list; list = list->next) |
| 1684 | commit_list_insert(list->item, &yet_to_do); |
| 1685 | while (yet_to_do) { |
| 1686 | list = yet_to_do; |
| 1687 | yet_to_do = NULL; |
| 1688 | tail = &yet_to_do; |
| 1689 | while (list) { |
| 1690 | struct commit *commit = list->item; |
| 1691 | struct commit_list *next = list->next; |
| 1692 | free(list); |
| 1693 | list = next; |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1694 | tail = simplify_one(revs, commit, tail); |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | /* clean up the result, removing the simplified ones */ |
| 1699 | list = revs->commits; |
| 1700 | revs->commits = NULL; |
| 1701 | tail = &revs->commits; |
| 1702 | while (list) { |
| 1703 | struct commit *commit = list->item; |
| 1704 | struct commit_list *next = list->next; |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1705 | struct merge_simplify_state *st; |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1706 | free(list); |
| 1707 | list = next; |
| Junio C Hamano | faf0156 | 2008-08-14 17:59:44 | [diff] [blame] | 1708 | st = locate_simplify_state(revs, commit); |
| 1709 | if (st->simplified == commit) |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1710 | tail = &commit_list_insert(commit, tail)->next; |
| 1711 | } |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1712 | } |
| 1713 | |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 1714 | static void set_children(struct rev_info *revs) |
| 1715 | { |
| 1716 | struct commit_list *l; |
| 1717 | for (l = revs->commits; l; l = l->next) { |
| 1718 | struct commit *commit = l->item; |
| 1719 | struct commit_list *p; |
| 1720 | |
| 1721 | for (p = commit->parents; p; p = p->next) |
| 1722 | add_child(revs, p->item, commit); |
| 1723 | } |
| 1724 | } |
| 1725 | |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1726 | int prepare_revision_walk(struct rev_info *revs) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1727 | { |
| Linus Torvalds | 1f1e895 | 2006-06-20 00:42:35 | [diff] [blame] | 1728 | int nr = revs->pending.nr; |
| Junio C Hamano | 94d2367 | 2007-01-11 06:36:16 | [diff] [blame] | 1729 | struct object_array_entry *e, *list; |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1730 | |
| Junio C Hamano | 94d2367 | 2007-01-11 06:36:16 | [diff] [blame] | 1731 | e = list = revs->pending.objects; |
| Linus Torvalds | 1f1e895 | 2006-06-20 00:42:35 | [diff] [blame] | 1732 | revs->pending.nr = 0; |
| 1733 | revs->pending.alloc = 0; |
| 1734 | revs->pending.objects = NULL; |
| 1735 | while (--nr >= 0) { |
| Junio C Hamano | 94d2367 | 2007-01-11 06:36:16 | [diff] [blame] | 1736 | struct commit *commit = handle_commit(revs, e->item, e->name); |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1737 | if (commit) { |
| 1738 | if (!(commit->object.flags & SEEN)) { |
| 1739 | commit->object.flags |= SEEN; |
| 1740 | insert_by_date(commit, &revs->commits); |
| 1741 | } |
| 1742 | } |
| Junio C Hamano | 94d2367 | 2007-01-11 06:36:16 | [diff] [blame] | 1743 | e++; |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1744 | } |
| Junio C Hamano | 94d2367 | 2007-01-11 06:36:16 | [diff] [blame] | 1745 | free(list); |
| Linus Torvalds | cd2bdc5 | 2006-04-14 23:52:13 | [diff] [blame] | 1746 | |
| Linus Torvalds | ba1d450 | 2006-04-15 19:09:56 | [diff] [blame] | 1747 | if (revs->no_walk) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1748 | return 0; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1749 | if (revs->limited) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1750 | if (limit_list(revs) < 0) |
| 1751 | return -1; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1752 | if (revs->topo_order) |
| Linus Torvalds | 23c17d4 | 2007-11-02 20:32:58 | [diff] [blame] | 1753 | sort_in_topological_order(&revs->commits, revs->lifo); |
| Junio C Hamano | 6546b59 | 2008-07-31 08:17:41 | [diff] [blame] | 1754 | if (revs->simplify_merges) |
| 1755 | simplify_merges(revs); |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 1756 | if (revs->children.name) |
| 1757 | set_children(revs); |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1758 | return 0; |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1759 | } |
| 1760 | |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1761 | enum rewrite_result { |
| 1762 | rewrite_one_ok, |
| 1763 | rewrite_one_noparents, |
| 1764 | rewrite_one_error, |
| 1765 | }; |
| 1766 | |
| 1767 | static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp) |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1768 | { |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 1769 | struct commit_list *cache = NULL; |
| 1770 | |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1771 | for (;;) { |
| 1772 | struct commit *p = *pp; |
| Linus Torvalds | 3381c79 | 2006-04-09 00:05:58 | [diff] [blame] | 1773 | if (!revs->limited) |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 1774 | if (add_parents_to_list(revs, p, &revs->commits, &cache) < 0) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1775 | return rewrite_one_error; |
| Linus Torvalds | 6631c73 | 2006-07-01 03:21:59 | [diff] [blame] | 1776 | if (p->parents && p->parents->next) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1777 | return rewrite_one_ok; |
| Linus Torvalds | 7dc0fe3 | 2007-11-13 07:16:08 | [diff] [blame] | 1778 | if (p->object.flags & UNINTERESTING) |
| 1779 | return rewrite_one_ok; |
| 1780 | if (!(p->object.flags & TREESAME)) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1781 | return rewrite_one_ok; |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1782 | if (!p->parents) |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1783 | return rewrite_one_noparents; |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1784 | *pp = p->parents->item; |
| 1785 | } |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1786 | } |
| 1787 | |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1788 | static int rewrite_parents(struct rev_info *revs, struct commit *commit) |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1789 | { |
| 1790 | struct commit_list **pp = &commit->parents; |
| 1791 | while (*pp) { |
| 1792 | struct commit_list *parent = *pp; |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1793 | switch (rewrite_one(revs, &parent->item)) { |
| 1794 | case rewrite_one_ok: |
| 1795 | break; |
| 1796 | case rewrite_one_noparents: |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1797 | *pp = parent->next; |
| 1798 | continue; |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1799 | case rewrite_one_error: |
| 1800 | return -1; |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1801 | } |
| 1802 | pp = &parent->next; |
| 1803 | } |
| Junio C Hamano | 11d6596 | 2007-07-09 02:03:19 | [diff] [blame] | 1804 | remove_duplicate_parents(commit); |
| Alex Riesen | cc0e6c5 | 2007-05-04 21:54:57 | [diff] [blame] | 1805 | return 0; |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1806 | } |
| Linus Torvalds | a4a88b2 | 2006-02-28 19:24:00 | [diff] [blame] | 1807 | |
| Junio C Hamano | 8ecae9b | 2006-09-17 22:43:40 | [diff] [blame] | 1808 | static int commit_match(struct commit *commit, struct rev_info *opt) |
| 1809 | { |
| Junio C Hamano | 80235ba | 2010-01-18 04:09:06 | [diff] [blame] | 1810 | if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list) |
| Junio C Hamano | 8ecae9b | 2006-09-17 22:43:40 | [diff] [blame] | 1811 | return 1; |
| Jeff King | 0843acf | 2008-08-25 06:15:05 | [diff] [blame] | 1812 | return grep_buffer(&opt->grep_filter, |
| Junio C Hamano | 2d10c55 | 2006-09-20 20:21:56 | [diff] [blame] | 1813 | NULL, /* we say nothing, not even filename */ |
| 1814 | commit->buffer, strlen(commit->buffer)); |
| Junio C Hamano | 8ecae9b | 2006-09-17 22:43:40 | [diff] [blame] | 1815 | } |
| 1816 | |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 1817 | static inline int want_ancestry(struct rev_info *revs) |
| 1818 | { |
| Junio C Hamano | 8bb6588 | 2008-07-08 22:25:44 | [diff] [blame] | 1819 | return (revs->rewrite_parents || revs->children.name); |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 1820 | } |
| 1821 | |
| Adam Simpkins | beb5af4 | 2009-08-19 02:34:33 | [diff] [blame] | 1822 | enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit) |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1823 | { |
| 1824 | if (commit->object.flags & SHOWN) |
| 1825 | return commit_ignore; |
| Brandon Casey | 4d6acb7 | 2009-03-20 03:47:54 | [diff] [blame] | 1826 | if (revs->unpacked && has_sha1_pack(commit->object.sha1)) |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1827 | return commit_ignore; |
| Linus Torvalds | 3131b71 | 2008-02-09 22:02:07 | [diff] [blame] | 1828 | if (revs->show_all) |
| 1829 | return commit_show; |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1830 | if (commit->object.flags & UNINTERESTING) |
| 1831 | return commit_ignore; |
| 1832 | if (revs->min_age != -1 && (commit->date > revs->min_age)) |
| 1833 | return commit_ignore; |
| 1834 | if (revs->no_merges && commit->parents && commit->parents->next) |
| 1835 | return commit_ignore; |
| Linus Torvalds | b8e8db2 | 2009-06-29 17:28:25 | [diff] [blame] | 1836 | if (revs->merges_only && !(commit->parents && commit->parents->next)) |
| 1837 | return commit_ignore; |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1838 | if (!commit_match(commit, revs)) |
| 1839 | return commit_ignore; |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 1840 | if (revs->prune && revs->dense) { |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1841 | /* Commit without changes? */ |
| Linus Torvalds | 7dc0fe3 | 2007-11-13 07:16:08 | [diff] [blame] | 1842 | if (commit->object.flags & TREESAME) { |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1843 | /* drop merges unless we want parenthood */ |
| Junio C Hamano | f35f560 | 2008-04-03 09:12:06 | [diff] [blame] | 1844 | if (!want_ancestry(revs)) |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1845 | return commit_ignore; |
| 1846 | /* non-merge - always ignore it */ |
| 1847 | if (!commit->parents || !commit->parents->next) |
| 1848 | return commit_ignore; |
| 1849 | } |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1850 | } |
| 1851 | return commit_show; |
| 1852 | } |
| 1853 | |
| Adam Simpkins | beb5af4 | 2009-08-19 02:34:33 | [diff] [blame] | 1854 | enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) |
| 1855 | { |
| 1856 | enum commit_action action = get_commit_action(revs, commit); |
| 1857 | |
| 1858 | if (action == commit_show && |
| 1859 | !revs->show_all && |
| 1860 | revs->prune && revs->dense && want_ancestry(revs)) { |
| 1861 | if (rewrite_parents(revs, commit) < 0) |
| 1862 | return commit_error; |
| 1863 | } |
| 1864 | return action; |
| 1865 | } |
| 1866 | |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 1867 | static struct commit *get_revision_1(struct rev_info *revs) |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1868 | { |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 1869 | if (!revs->commits) |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1870 | return NULL; |
| 1871 | |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1872 | do { |
| Linus Torvalds | cb11574 | 2006-06-18 01:47:58 | [diff] [blame] | 1873 | struct commit_list *entry = revs->commits; |
| 1874 | struct commit *commit = entry->item; |
| Linus Torvalds | ea5ed3a | 2006-03-05 17:53:52 | [diff] [blame] | 1875 | |
| Linus Torvalds | cb11574 | 2006-06-18 01:47:58 | [diff] [blame] | 1876 | revs->commits = entry->next; |
| 1877 | free(entry); |
| Linus Torvalds | 2a0925b | 2006-03-31 01:05:25 | [diff] [blame] | 1878 | |
| Johannes Schindelin | 8860fd4 | 2007-01-11 10:47:48 | [diff] [blame] | 1879 | if (revs->reflog_info) |
| 1880 | fake_reflog_parent(revs->reflog_info, commit); |
| 1881 | |
| Linus Torvalds | 2a0925b | 2006-03-31 01:05:25 | [diff] [blame] | 1882 | /* |
| 1883 | * If we haven't done the list limiting, we need to look at |
| Linus Torvalds | be7db6e | 2006-04-02 00:35:06 | [diff] [blame] | 1884 | * the parents here. We also need to do the date-based limiting |
| 1885 | * that we'd otherwise have done in limit_list(). |
| Linus Torvalds | 2a0925b | 2006-03-31 01:05:25 | [diff] [blame] | 1886 | */ |
| Linus Torvalds | be7db6e | 2006-04-02 00:35:06 | [diff] [blame] | 1887 | if (!revs->limited) { |
| Jan Harkes | 744f498 | 2006-10-31 01:37:49 | [diff] [blame] | 1888 | if (revs->max_age != -1 && |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 1889 | (commit->date < revs->max_age)) |
| 1890 | continue; |
| Alexander N. Gavrilov | fce87ae | 2008-07-12 18:00:57 | [diff] [blame] | 1891 | if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) |
| Junio C Hamano | ed62089 | 2009-02-11 09:27:43 | [diff] [blame] | 1892 | die("Failed to traverse parents of commit %s", |
| 1893 | sha1_to_hex(commit->object.sha1)); |
| Linus Torvalds | be7db6e | 2006-04-02 00:35:06 | [diff] [blame] | 1894 | } |
| Junio C Hamano | 1b65a5a | 2006-04-17 01:12:49 | [diff] [blame] | 1895 | |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1896 | switch (simplify_commit(revs, commit)) { |
| 1897 | case commit_ignore: |
| Linus Torvalds | 2a0925b | 2006-03-31 01:05:25 | [diff] [blame] | 1898 | continue; |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1899 | case commit_error: |
| Junio C Hamano | ed62089 | 2009-02-11 09:27:43 | [diff] [blame] | 1900 | die("Failed to simplify parents of commit %s", |
| 1901 | sha1_to_hex(commit->object.sha1)); |
| Linus Torvalds | 252a7c0 | 2007-11-04 20:12:05 | [diff] [blame] | 1902 | default: |
| 1903 | return commit; |
| Junio C Hamano | 384e99a | 2006-03-28 07:58:34 | [diff] [blame] | 1904 | } |
| Linus Torvalds | 765ac8e | 2006-02-28 23:07:20 | [diff] [blame] | 1905 | } while (revs->commits); |
| 1906 | return NULL; |
| 1907 | } |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 1908 | |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 1909 | static void gc_boundary(struct object_array *array) |
| 1910 | { |
| 1911 | unsigned nr = array->nr; |
| 1912 | unsigned alloc = array->alloc; |
| 1913 | struct object_array_entry *objects = array->objects; |
| 1914 | |
| 1915 | if (alloc <= nr) { |
| 1916 | unsigned i, j; |
| 1917 | for (i = j = 0; i < nr; i++) { |
| 1918 | if (objects[i].item->flags & SHOWN) |
| 1919 | continue; |
| 1920 | if (i != j) |
| 1921 | objects[j] = objects[i]; |
| 1922 | j++; |
| 1923 | } |
| Junio C Hamano | 892ae6b | 2007-03-06 11:00:18 | [diff] [blame] | 1924 | for (i = j; i < nr; i++) |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 1925 | objects[i].item = NULL; |
| 1926 | array->nr = j; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| Adam Simpkins | 4603ec0 | 2008-05-24 23:02:05 | [diff] [blame] | 1930 | static void create_boundary_commit_list(struct rev_info *revs) |
| 1931 | { |
| 1932 | unsigned i; |
| 1933 | struct commit *c; |
| 1934 | struct object_array *array = &revs->boundary_commits; |
| 1935 | struct object_array_entry *objects = array->objects; |
| 1936 | |
| 1937 | /* |
| 1938 | * If revs->commits is non-NULL at this point, an error occurred in |
| 1939 | * get_revision_1(). Ignore the error and continue printing the |
| 1940 | * boundary commits anyway. (This is what the code has always |
| 1941 | * done.) |
| 1942 | */ |
| 1943 | if (revs->commits) { |
| 1944 | free_commit_list(revs->commits); |
| 1945 | revs->commits = NULL; |
| 1946 | } |
| 1947 | |
| 1948 | /* |
| 1949 | * Put all of the actual boundary commits from revs->boundary_commits |
| 1950 | * into revs->commits |
| 1951 | */ |
| 1952 | for (i = 0; i < array->nr; i++) { |
| 1953 | c = (struct commit *)(objects[i].item); |
| 1954 | if (!c) |
| 1955 | continue; |
| 1956 | if (!(c->object.flags & CHILD_SHOWN)) |
| 1957 | continue; |
| 1958 | if (c->object.flags & (SHOWN | BOUNDARY)) |
| 1959 | continue; |
| 1960 | c->object.flags |= BOUNDARY; |
| 1961 | commit_list_insert(c, &revs->commits); |
| 1962 | } |
| 1963 | |
| 1964 | /* |
| 1965 | * If revs->topo_order is set, sort the boundary commits |
| 1966 | * in topological order |
| 1967 | */ |
| 1968 | sort_in_topological_order(&revs->commits, revs->lifo); |
| 1969 | } |
| 1970 | |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 1971 | static struct commit *get_revision_internal(struct rev_info *revs) |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 1972 | { |
| 1973 | struct commit *c = NULL; |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 1974 | struct commit_list *l; |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 1975 | |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 1976 | if (revs->boundary == 2) { |
| Adam Simpkins | 4603ec0 | 2008-05-24 23:02:05 | [diff] [blame] | 1977 | /* |
| 1978 | * All of the normal commits have already been returned, |
| 1979 | * and we are now returning boundary commits. |
| 1980 | * create_boundary_commit_list() has populated |
| 1981 | * revs->commits with the remaining commits to return. |
| 1982 | */ |
| 1983 | c = pop_commit(&revs->commits); |
| 1984 | if (c) |
| 1985 | c->object.flags |= SHOWN; |
| Johannes Schindelin | 9c5e66e | 2007-01-20 22:04:02 | [diff] [blame] | 1986 | return c; |
| 1987 | } |
| 1988 | |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 1989 | /* |
| 1990 | * Now pick up what they want to give us |
| 1991 | */ |
| Junio C Hamano | 8839ac9 | 2007-03-06 11:20:55 | [diff] [blame] | 1992 | c = get_revision_1(revs); |
| 1993 | if (c) { |
| 1994 | while (0 < revs->skip_count) { |
| 1995 | revs->skip_count--; |
| 1996 | c = get_revision_1(revs); |
| 1997 | if (!c) |
| 1998 | break; |
| 1999 | } |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | /* |
| 2003 | * Check the max_count. |
| 2004 | */ |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 2005 | switch (revs->max_count) { |
| 2006 | case -1: |
| 2007 | break; |
| 2008 | case 0: |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 2009 | c = NULL; |
| 2010 | break; |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 2011 | default: |
| 2012 | revs->max_count--; |
| 2013 | } |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 2014 | |
| Junio C Hamano | c33d859 | 2007-03-06 02:23:57 | [diff] [blame] | 2015 | if (c) |
| 2016 | c->object.flags |= SHOWN; |
| 2017 | |
| 2018 | if (!revs->boundary) { |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 2019 | return c; |
| Junio C Hamano | c33d859 | 2007-03-06 02:23:57 | [diff] [blame] | 2020 | } |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 2021 | |
| 2022 | if (!c) { |
| 2023 | /* |
| 2024 | * get_revision_1() runs out the commits, and |
| 2025 | * we are done computing the boundaries. |
| 2026 | * switch to boundary commits output mode. |
| 2027 | */ |
| 2028 | revs->boundary = 2; |
| Adam Simpkins | 4603ec0 | 2008-05-24 23:02:05 | [diff] [blame] | 2029 | |
| 2030 | /* |
| 2031 | * Update revs->commits to contain the list of |
| 2032 | * boundary commits. |
| 2033 | */ |
| 2034 | create_boundary_commit_list(revs); |
| 2035 | |
| Adam Simpkins | 3c68d67 | 2008-05-24 23:02:04 | [diff] [blame] | 2036 | return get_revision_internal(revs); |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | /* |
| 2040 | * boundary commits are the commits that are parents of the |
| 2041 | * ones we got from get_revision_1() but they themselves are |
| 2042 | * not returned from get_revision_1(). Before returning |
| 2043 | * 'c', we need to mark its parents that they could be boundaries. |
| 2044 | */ |
| 2045 | |
| 2046 | for (l = c->parents; l; l = l->next) { |
| 2047 | struct object *p; |
| 2048 | p = &(l->item->object); |
| Junio C Hamano | c33d859 | 2007-03-06 02:23:57 | [diff] [blame] | 2049 | if (p->flags & (CHILD_SHOWN | SHOWN)) |
| Junio C Hamano | 86ab490 | 2007-03-05 21:10:06 | [diff] [blame] | 2050 | continue; |
| 2051 | p->flags |= CHILD_SHOWN; |
| 2052 | gc_boundary(&revs->boundary_commits); |
| 2053 | add_object_array(p, NULL, &revs->boundary_commits); |
| 2054 | } |
| 2055 | |
| 2056 | return c; |
| Junio C Hamano | d5db6c9 | 2006-12-20 02:25:32 | [diff] [blame] | 2057 | } |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 2058 | |
| 2059 | struct commit *get_revision(struct rev_info *revs) |
| 2060 | { |
| Thomas Rast | 498bcd3 | 2008-08-29 19:18:38 | [diff] [blame] | 2061 | struct commit *c; |
| 2062 | struct commit_list *reversed; |
| 2063 | |
| 2064 | if (revs->reverse) { |
| 2065 | reversed = NULL; |
| 2066 | while ((c = get_revision_internal(revs))) { |
| 2067 | commit_list_insert(c, &reversed); |
| 2068 | } |
| 2069 | revs->commits = reversed; |
| 2070 | revs->reverse = 0; |
| 2071 | revs->reverse_output_stage = 1; |
| 2072 | } |
| 2073 | |
| 2074 | if (revs->reverse_output_stage) |
| 2075 | return pop_commit(&revs->commits); |
| 2076 | |
| 2077 | c = get_revision_internal(revs); |
| Adam Simpkins | 7fefda5 | 2008-05-04 10:36:54 | [diff] [blame] | 2078 | if (c && revs->graph) |
| 2079 | graph_update(revs->graph, c); |
| 2080 | return c; |
| 2081 | } |