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