]>
Commit | Line | Data |
---|---|---|
ae563542 | 1 | #include "cache.h" |
cbd53a21 | 2 | #include "object-store.h" |
ae563542 LT |
3 | #include "tag.h" |
4 | #include "blob.h" | |
5 | #include "tree.h" | |
6 | #include "commit.h" | |
a4a88b2b | 7 | #include "diff.h" |
a37eec63 | 8 | #include "diff-merges.h" |
ae563542 LT |
9 | #include "refs.h" |
10 | #include "revision.h" | |
23a3f0cb | 11 | #include "repository.h" |
7fefda5c | 12 | #include "graph.h" |
8ecae9b0 | 13 | #include "grep.h" |
8860fd42 | 14 | #include "reflog-walk.h" |
d7a17cad | 15 | #include "patch-ids.h" |
f35f5603 | 16 | #include "decorate.h" |
78892e32 | 17 | #include "log-tree.h" |
894a9d33 | 18 | #include "string-list.h" |
12da1d1f | 19 | #include "line-log.h" |
d72fbe81 | 20 | #include "mailmap.h" |
53d00b39 | 21 | #include "commit-slab.h" |
429bb40a | 22 | #include "dir.h" |
4fe10219 | 23 | #include "cache-tree.h" |
cb46d630 | 24 | #include "bisect.h" |
150e3001 | 25 | #include "packfile.h" |
be489d02 | 26 | #include "worktree.h" |
dbbcd44f | 27 | #include "strvec.h" |
64043556 | 28 | #include "commit-reach.h" |
f0d9cc41 | 29 | #include "commit-graph.h" |
b4542418 | 30 | #include "prio-queue.h" |
d5d2e935 | 31 | #include "hashmap.h" |
44570188 | 32 | #include "utf8.h" |
a56b9464 | 33 | #include "bloom.h" |
42e50e78 | 34 | #include "json-writer.h" |
c4ea513f | 35 | #include "list-objects-filter-options.h" |
5a5ea141 | 36 | #include "resolve-undo.h" |
ae563542 | 37 | |
cdcefbc9 LT |
38 | volatile show_early_output_fn_t show_early_output; |
39 | ||
cb46d630 AD |
40 | static const char *term_bad; |
41 | static const char *term_good; | |
42 | ||
87be2523 NTND |
43 | implement_shared_commit_slab(revision_sources, char *); |
44 | ||
3cb9d2b6 SG |
45 | static inline int want_ancestry(const struct rev_info *revs); |
46 | ||
de1e67d0 | 47 | void show_object_with_name(FILE *out, struct object *obj, const char *name) |
ae563542 | 48 | { |
f2fd0760 | 49 | fprintf(out, "%s ", oid_to_hex(&obj->oid)); |
44ba10d6 | 50 | for (const char *p = name; *p && *p != '\n'; p++) |
f9fb9d0e | 51 | fputc(*p, out); |
beba25ab | 52 | fputc('\n', out); |
91f17516 JH |
53 | } |
54 | ||
ae563542 LT |
55 | static void mark_blob_uninteresting(struct blob *blob) |
56 | { | |
c1ee9013 MK |
57 | if (!blob) |
58 | return; | |
ae563542 LT |
59 | if (blob->object.flags & UNINTERESTING) |
60 | return; | |
61 | blob->object.flags |= UNINTERESTING; | |
62 | } | |
63 | ||
b3c7eef9 NTND |
64 | static void mark_tree_contents_uninteresting(struct repository *r, |
65 | struct tree *tree) | |
ae563542 | 66 | { |
f75e53ed | 67 | struct tree_desc desc; |
4c068a98 | 68 | struct name_entry entry; |
ae563542 | 69 | |
a5411df0 | 70 | if (parse_tree_gently(tree, 1) < 0) |
ae563542 | 71 | return; |
f75e53ed | 72 | |
6fda5e51 | 73 | init_tree_desc(&desc, tree->buffer, tree->size); |
4c068a98 | 74 | while (tree_entry(&desc, &entry)) { |
4d1012c3 LT |
75 | switch (object_type(entry.mode)) { |
76 | case OBJ_TREE: | |
ea82b2a0 | 77 | mark_tree_uninteresting(r, lookup_tree(r, &entry.oid)); |
4d1012c3 LT |
78 | break; |
79 | case OBJ_BLOB: | |
ea82b2a0 | 80 | mark_blob_uninteresting(lookup_blob(r, &entry.oid)); |
4d1012c3 LT |
81 | break; |
82 | default: | |
83 | /* Subproject commit - not in this repository */ | |
84 | break; | |
85 | } | |
ae563542 | 86 | } |
f75e53ed LT |
87 | |
88 | /* | |
89 | * We don't care about the tree any more | |
90 | * after it has been marked uninteresting. | |
91 | */ | |
6e454b9a | 92 | free_tree_buffer(tree); |
ae563542 LT |
93 | } |
94 | ||
b3c7eef9 | 95 | void mark_tree_uninteresting(struct repository *r, struct tree *tree) |
2ac5e447 | 96 | { |
a2678df3 | 97 | struct object *obj; |
2ac5e447 JH |
98 | |
99 | if (!tree) | |
100 | return; | |
a2678df3 SN |
101 | |
102 | obj = &tree->object; | |
2ac5e447 JH |
103 | if (obj->flags & UNINTERESTING) |
104 | return; | |
105 | obj->flags |= UNINTERESTING; | |
b3c7eef9 | 106 | mark_tree_contents_uninteresting(r, tree); |
ae563542 LT |
107 | } |
108 | ||
d5d2e935 DS |
109 | struct path_and_oids_entry { |
110 | struct hashmap_entry ent; | |
111 | char *path; | |
112 | struct oidset trees; | |
113 | }; | |
114 | ||
5cf88fd8 | 115 | static int path_and_oids_cmp(const void *hashmap_cmp_fn_data UNUSED, |
939af16e EW |
116 | const struct hashmap_entry *eptr, |
117 | const struct hashmap_entry *entry_or_key, | |
5cf88fd8 | 118 | const void *keydata UNUSED) |
d5d2e935 | 119 | { |
939af16e EW |
120 | const struct path_and_oids_entry *e1, *e2; |
121 | ||
122 | e1 = container_of(eptr, const struct path_and_oids_entry, ent); | |
123 | e2 = container_of(entry_or_key, const struct path_and_oids_entry, ent); | |
124 | ||
d5d2e935 DS |
125 | return strcmp(e1->path, e2->path); |
126 | } | |
127 | ||
d5d2e935 DS |
128 | static void paths_and_oids_clear(struct hashmap *map) |
129 | { | |
130 | struct hashmap_iter iter; | |
131 | struct path_and_oids_entry *entry; | |
d5d2e935 | 132 | |
23dee69f | 133 | hashmap_for_each_entry(map, &iter, entry, ent /* member name */) { |
d5d2e935 DS |
134 | oidset_clear(&entry->trees); |
135 | free(entry->path); | |
136 | } | |
137 | ||
6da1a258 | 138 | hashmap_clear_and_free(map, struct path_and_oids_entry, ent); |
d5d2e935 DS |
139 | } |
140 | ||
141 | static void paths_and_oids_insert(struct hashmap *map, | |
142 | const char *path, | |
143 | const struct object_id *oid) | |
144 | { | |
145 | int hash = strhash(path); | |
146 | struct path_and_oids_entry key; | |
147 | struct path_and_oids_entry *entry; | |
148 | ||
d22245a2 | 149 | hashmap_entry_init(&key.ent, hash); |
d5d2e935 DS |
150 | |
151 | /* use a shallow copy for the lookup */ | |
152 | key.path = (char *)path; | |
153 | oidset_init(&key.trees, 0); | |
154 | ||
404ab78e | 155 | entry = hashmap_get_entry(map, &key, ent, NULL); |
b6c52416 | 156 | if (!entry) { |
ca56dadb | 157 | CALLOC_ARRAY(entry, 1); |
d22245a2 | 158 | hashmap_entry_init(&entry->ent, hash); |
d5d2e935 DS |
159 | entry->path = xstrdup(key.path); |
160 | oidset_init(&entry->trees, 16); | |
26b455f2 | 161 | hashmap_put(map, &entry->ent); |
d5d2e935 DS |
162 | } |
163 | ||
164 | oidset_insert(&entry->trees, oid); | |
165 | } | |
166 | ||
167 | static void add_children_by_path(struct repository *r, | |
168 | struct tree *tree, | |
169 | struct hashmap *map) | |
170 | { | |
171 | struct tree_desc desc; | |
172 | struct name_entry entry; | |
173 | ||
174 | if (!tree) | |
175 | return; | |
176 | ||
177 | if (parse_tree_gently(tree, 1) < 0) | |
178 | return; | |
179 | ||
180 | init_tree_desc(&desc, tree->buffer, tree->size); | |
181 | while (tree_entry(&desc, &entry)) { | |
182 | switch (object_type(entry.mode)) { | |
183 | case OBJ_TREE: | |
5fda3433 | 184 | paths_and_oids_insert(map, entry.path, &entry.oid); |
d5d2e935 DS |
185 | |
186 | if (tree->object.flags & UNINTERESTING) { | |
5fda3433 | 187 | struct tree *child = lookup_tree(r, &entry.oid); |
d5d2e935 DS |
188 | if (child) |
189 | child->object.flags |= UNINTERESTING; | |
190 | } | |
191 | break; | |
192 | case OBJ_BLOB: | |
193 | if (tree->object.flags & UNINTERESTING) { | |
5fda3433 | 194 | struct blob *child = lookup_blob(r, &entry.oid); |
d5d2e935 DS |
195 | if (child) |
196 | child->object.flags |= UNINTERESTING; | |
197 | } | |
198 | break; | |
199 | default: | |
200 | /* Subproject commit - not in this repository */ | |
201 | break; | |
202 | } | |
203 | } | |
204 | ||
205 | free_tree_buffer(tree); | |
206 | } | |
207 | ||
f1f5de44 DS |
208 | void mark_trees_uninteresting_sparse(struct repository *r, |
209 | struct oidset *trees) | |
210 | { | |
d5d2e935 | 211 | unsigned has_interesting = 0, has_uninteresting = 0; |
b19315d8 | 212 | struct hashmap map = HASHMAP_INIT(path_and_oids_cmp, NULL); |
d5d2e935 DS |
213 | struct hashmap_iter map_iter; |
214 | struct path_and_oids_entry *entry; | |
f1f5de44 DS |
215 | struct object_id *oid; |
216 | struct oidset_iter iter; | |
217 | ||
218 | oidset_iter_init(trees, &iter); | |
d5d2e935 DS |
219 | while ((!has_interesting || !has_uninteresting) && |
220 | (oid = oidset_iter_next(&iter))) { | |
f1f5de44 DS |
221 | struct tree *tree = lookup_tree(r, oid); |
222 | ||
223 | if (!tree) | |
224 | continue; | |
225 | ||
d5d2e935 DS |
226 | if (tree->object.flags & UNINTERESTING) |
227 | has_uninteresting = 1; | |
228 | else | |
229 | has_interesting = 1; | |
f1f5de44 | 230 | } |
d5d2e935 DS |
231 | |
232 | /* Do not walk unless we have both types of trees. */ | |
233 | if (!has_uninteresting || !has_interesting) | |
234 | return; | |
235 | ||
d5d2e935 DS |
236 | oidset_iter_init(trees, &iter); |
237 | while ((oid = oidset_iter_next(&iter))) { | |
238 | struct tree *tree = lookup_tree(r, oid); | |
239 | add_children_by_path(r, tree, &map); | |
240 | } | |
241 | ||
23dee69f | 242 | hashmap_for_each_entry(&map, &map_iter, entry, ent /* member name */) |
d5d2e935 DS |
243 | mark_trees_uninteresting_sparse(r, &entry->trees); |
244 | ||
245 | paths_and_oids_clear(&map); | |
f1f5de44 DS |
246 | } |
247 | ||
43fc643b JK |
248 | struct commit_stack { |
249 | struct commit **items; | |
250 | size_t nr, alloc; | |
251 | }; | |
9865b6e6 | 252 | #define COMMIT_STACK_INIT { 0 } |
43fc643b JK |
253 | |
254 | static void commit_stack_push(struct commit_stack *stack, struct commit *commit) | |
255 | { | |
256 | ALLOC_GROW(stack->items, stack->nr + 1, stack->alloc); | |
257 | stack->items[stack->nr++] = commit; | |
258 | } | |
259 | ||
260 | static struct commit *commit_stack_pop(struct commit_stack *stack) | |
261 | { | |
262 | return stack->nr ? stack->items[--stack->nr] : NULL; | |
263 | } | |
264 | ||
265 | static void commit_stack_clear(struct commit_stack *stack) | |
266 | { | |
267 | FREE_AND_NULL(stack->items); | |
268 | stack->nr = stack->alloc = 0; | |
269 | } | |
270 | ||
9d505b7b | 271 | static void mark_one_parent_uninteresting(struct rev_info *revs, struct commit *commit, |
8702b30f JK |
272 | struct commit_stack *pending) |
273 | { | |
274 | struct commit_list *l; | |
275 | ||
276 | if (commit->object.flags & UNINTERESTING) | |
277 | return; | |
278 | commit->object.flags |= UNINTERESTING; | |
279 | ||
280 | /* | |
281 | * Normally we haven't parsed the parent | |
282 | * yet, so we won't have a parent of a parent | |
283 | * here. However, it may turn out that we've | |
284 | * reached this commit some other way (where it | |
285 | * wasn't uninteresting), in which case we need | |
286 | * to mark its parents recursively too.. | |
287 | */ | |
9d505b7b | 288 | for (l = commit->parents; l; l = l->next) { |
8702b30f | 289 | commit_stack_push(pending, l->item); |
9d505b7b JZ |
290 | if (revs && revs->exclude_first_parent_only) |
291 | break; | |
292 | } | |
8702b30f JK |
293 | } |
294 | ||
9d505b7b | 295 | void mark_parents_uninteresting(struct rev_info *revs, struct commit *commit) |
ae563542 | 296 | { |
43fc643b JK |
297 | struct commit_stack pending = COMMIT_STACK_INIT; |
298 | struct commit_list *l; | |
941ba8db | 299 | |
9d505b7b JZ |
300 | for (l = commit->parents; l; l = l->next) { |
301 | mark_one_parent_uninteresting(revs, l->item, &pending); | |
302 | if (revs && revs->exclude_first_parent_only) | |
303 | break; | |
304 | } | |
8702b30f JK |
305 | |
306 | while (pending.nr > 0) | |
9d505b7b | 307 | mark_one_parent_uninteresting(revs, commit_stack_pop(&pending), |
8702b30f | 308 | &pending); |
43fc643b JK |
309 | |
310 | commit_stack_clear(&pending); | |
ae563542 LT |
311 | } |
312 | ||
20739490 | 313 | static void add_pending_object_with_path(struct rev_info *revs, |
ff5f5f26 | 314 | struct object *obj, |
20739490 JK |
315 | const char *name, unsigned mode, |
316 | const char *path) | |
ae563542 | 317 | { |
a4f66a78 | 318 | struct interpret_branch_name_options options = { 0 }; |
cc243c3c JH |
319 | if (!obj) |
320 | return; | |
aa27e461 | 321 | if (revs->no_walk && (obj->flags & UNINTERESTING)) |
f222abde | 322 | revs->no_walk = 0; |
105e4733 JH |
323 | if (revs->reflog_info && obj->type == OBJ_COMMIT) { |
324 | struct strbuf buf = STRBUF_INIT; | |
1d72b604 JK |
325 | size_t namelen = strlen(name); |
326 | int len = interpret_branch_name(name, namelen, &buf, &options); | |
105e4733 | 327 | |
1d72b604 | 328 | if (0 < len && len < namelen && buf.len) |
105e4733 | 329 | strbuf_addstr(&buf, name + len); |
d08565bf JK |
330 | add_reflog_for_walk(revs->reflog_info, |
331 | (struct commit *)obj, | |
332 | buf.buf[0] ? buf.buf: name); | |
105e4733 | 333 | strbuf_release(&buf); |
d08565bf | 334 | return; /* do not add the commit itself */ |
105e4733 | 335 | } |
20739490 JK |
336 | add_object_array_with_path(obj, name, &revs->pending, mode, path); |
337 | } | |
338 | ||
339 | static void add_pending_object_with_mode(struct rev_info *revs, | |
340 | struct object *obj, | |
341 | const char *name, unsigned mode) | |
342 | { | |
343 | add_pending_object_with_path(revs, obj, name, mode, NULL); | |
ae563542 LT |
344 | } |
345 | ||
ff5f5f26 MH |
346 | void add_pending_object(struct rev_info *revs, |
347 | struct object *obj, const char *name) | |
2d93b9fa JH |
348 | { |
349 | add_pending_object_with_mode(revs, obj, name, S_IFINVALID); | |
350 | } | |
351 | ||
3384a2df JH |
352 | void add_head_to_pending(struct rev_info *revs) |
353 | { | |
654b9a90 | 354 | struct object_id oid; |
3384a2df | 355 | struct object *obj; |
654b9a90 | 356 | if (get_oid("HEAD", &oid)) |
3384a2df | 357 | return; |
b3c7eef9 | 358 | obj = parse_object(revs->repo, &oid); |
3384a2df JH |
359 | if (!obj) |
360 | return; | |
361 | add_pending_object(revs, obj, "HEAD"); | |
362 | } | |
363 | ||
ff5f5f26 | 364 | static struct object *get_reference(struct rev_info *revs, const char *name, |
654b9a90 | 365 | const struct object_id *oid, |
ff5f5f26 | 366 | unsigned int flags) |
ae563542 LT |
367 | { |
368 | struct object *object; | |
369 | ||
9a8c3c4a JK |
370 | object = parse_object_with_flags(revs->repo, oid, |
371 | revs->verify_objects ? 0 : | |
372 | PARSE_OBJECT_SKIP_HASH_CHECK); | |
ec0c5798 | 373 | |
cc243c3c JH |
374 | if (!object) { |
375 | if (revs->ignore_missing) | |
376 | return object; | |
df11e196 JT |
377 | if (revs->exclude_promisor_objects && is_promisor_object(oid)) |
378 | return NULL; | |
ae563542 | 379 | die("bad object %s", name); |
cc243c3c | 380 | } |
cd2bdc53 LT |
381 | object->flags |= flags; |
382 | return object; | |
383 | } | |
384 | ||
a58a1b01 | 385 | void add_pending_oid(struct rev_info *revs, const char *name, |
386 | const struct object_id *oid, unsigned int flags) | |
26c3177e | 387 | { |
654b9a90 | 388 | struct object *object = get_reference(revs, name, oid, flags); |
26c3177e RS |
389 | add_pending_object(revs, object, name); |
390 | } | |
391 | ||
ff5f5f26 | 392 | static struct commit *handle_commit(struct rev_info *revs, |
20739490 | 393 | struct object_array_entry *entry) |
cd2bdc53 | 394 | { |
20739490 JK |
395 | struct object *object = entry->item; |
396 | const char *name = entry->name; | |
397 | const char *path = entry->path; | |
398 | unsigned int mode = entry->mode; | |
cd2bdc53 | 399 | unsigned long flags = object->flags; |
ae563542 LT |
400 | |
401 | /* | |
402 | * Tag object? Look what it points to.. | |
403 | */ | |
1974632c | 404 | while (object->type == OBJ_TAG) { |
ae563542 | 405 | struct tag *tag = (struct tag *) object; |
cd2bdc53 | 406 | if (revs->tag_objects && !(flags & UNINTERESTING)) |
ae563542 | 407 | add_pending_object(revs, object, tag->tag); |
dad3f060 | 408 | object = parse_object(revs->repo, get_tagged_oid(tag)); |
aeeae1b7 | 409 | if (!object) { |
a3ba6bf1 | 410 | if (revs->ignore_missing_links || (flags & UNINTERESTING)) |
aeeae1b7 | 411 | return NULL; |
dc0a13f6 JT |
412 | if (revs->exclude_promisor_objects && |
413 | is_promisor_object(&tag->tagged->oid)) | |
414 | return NULL; | |
f2fd0760 | 415 | die("bad object %s", oid_to_hex(&tag->tagged->oid)); |
aeeae1b7 | 416 | } |
a7435286 | 417 | object->flags |= flags; |
20739490 JK |
418 | /* |
419 | * We'll handle the tagged object by looping or dropping | |
420 | * through to the non-tag handlers below. Do not | |
728350b7 | 421 | * propagate path data from the tag's pending entry. |
20739490 | 422 | */ |
20739490 JK |
423 | path = NULL; |
424 | mode = 0; | |
ae563542 LT |
425 | } |
426 | ||
427 | /* | |
428 | * Commit object? Just return it, we'll do all the complex | |
429 | * reachability crud. | |
430 | */ | |
1974632c | 431 | if (object->type == OBJ_COMMIT) { |
ae563542 | 432 | struct commit *commit = (struct commit *)object; |
87be2523 | 433 | |
ea3f7e59 | 434 | if (repo_parse_commit(revs->repo, commit) < 0) |
ae563542 | 435 | die("unable to parse commit %s", name); |
d9a83684 | 436 | if (flags & UNINTERESTING) { |
9d505b7b | 437 | mark_parents_uninteresting(revs, commit); |
1b4d8827 DS |
438 | |
439 | if (!revs->topo_order || !generation_numbers_enabled(the_repository)) | |
440 | revs->limited = 1; | |
d9a83684 | 441 | } |
87be2523 NTND |
442 | if (revs->sources) { |
443 | char **slot = revision_sources_at(revs->sources, commit); | |
444 | ||
445 | if (!*slot) | |
446 | *slot = xstrdup(name); | |
447 | } | |
ae563542 LT |
448 | return commit; |
449 | } | |
450 | ||
451 | /* | |
3ea3c215 | 452 | * Tree object? Either mark it uninteresting, or add it |
ae563542 LT |
453 | * to the list of objects to look at later.. |
454 | */ | |
1974632c | 455 | if (object->type == OBJ_TREE) { |
ae563542 LT |
456 | struct tree *tree = (struct tree *)object; |
457 | if (!revs->tree_objects) | |
458 | return NULL; | |
459 | if (flags & UNINTERESTING) { | |
b3c7eef9 | 460 | mark_tree_contents_uninteresting(revs->repo, tree); |
ae563542 LT |
461 | return NULL; |
462 | } | |
20739490 | 463 | add_pending_object_with_path(revs, object, name, mode, path); |
ae563542 LT |
464 | return NULL; |
465 | } | |
466 | ||
467 | /* | |
468 | * Blob object? You know the drill by now.. | |
469 | */ | |
1974632c | 470 | if (object->type == OBJ_BLOB) { |
ae563542 LT |
471 | if (!revs->blob_objects) |
472 | return NULL; | |
a7435286 | 473 | if (flags & UNINTERESTING) |
ae563542 | 474 | return NULL; |
20739490 | 475 | add_pending_object_with_path(revs, object, name, mode, path); |
ae563542 LT |
476 | return NULL; |
477 | } | |
478 | die("%s is unknown object", name); | |
479 | } | |
480 | ||
b6e8a3b5 JK |
481 | static int everybody_uninteresting(struct commit_list *orig, |
482 | struct commit **interesting_cache) | |
a4a88b2b LT |
483 | { |
484 | struct commit_list *list = orig; | |
b6e8a3b5 JK |
485 | |
486 | if (*interesting_cache) { | |
487 | struct commit *commit = *interesting_cache; | |
488 | if (!(commit->object.flags & UNINTERESTING)) | |
489 | return 0; | |
490 | } | |
491 | ||
a4a88b2b LT |
492 | while (list) { |
493 | struct commit *commit = list->item; | |
494 | list = list->next; | |
495 | if (commit->object.flags & UNINTERESTING) | |
496 | continue; | |
ae40ebda SB |
497 | |
498 | *interesting_cache = commit; | |
a4a88b2b LT |
499 | return 0; |
500 | } | |
501 | return 1; | |
502 | } | |
503 | ||
4d826608 KB |
504 | /* |
505 | * A definition of "relevant" commit that we can use to simplify limited graphs | |
506 | * by eliminating side branches. | |
507 | * | |
508 | * A "relevant" commit is one that is !UNINTERESTING (ie we are including it | |
509 | * in our list), or that is a specified BOTTOM commit. Then after computing | |
510 | * a limited list, during processing we can generally ignore boundary merges | |
511 | * coming from outside the graph, (ie from irrelevant parents), and treat | |
512 | * those merges as if they were single-parent. TREESAME is defined to consider | |
513 | * only relevant parents, if any. If we are TREESAME to our on-graph parents, | |
514 | * we don't care if we were !TREESAME to non-graph parents. | |
515 | * | |
516 | * Treating bottom commits as relevant ensures that a limited graph's | |
517 | * connection to the actual bottom commit is not viewed as a side branch, but | |
518 | * treated as part of the graph. For example: | |
519 | * | |
520 | * ....Z...A---X---o---o---B | |
521 | * . / | |
522 | * W---Y | |
523 | * | |
524 | * When computing "A..B", the A-X connection is at least as important as | |
525 | * Y-X, despite A being flagged UNINTERESTING. | |
526 | * | |
527 | * And when computing --ancestry-path "A..B", the A-X connection is more | |
528 | * important than Y-X, despite both A and Y being flagged UNINTERESTING. | |
529 | */ | |
530 | static inline int relevant_commit(struct commit *commit) | |
531 | { | |
532 | return (commit->object.flags & (UNINTERESTING | BOTTOM)) != UNINTERESTING; | |
533 | } | |
534 | ||
535 | /* | |
536 | * Return a single relevant commit from a parent list. If we are a TREESAME | |
537 | * commit, and this selects one of our parents, then we can safely simplify to | |
538 | * that parent. | |
539 | */ | |
540 | static struct commit *one_relevant_parent(const struct rev_info *revs, | |
541 | struct commit_list *orig) | |
542 | { | |
543 | struct commit_list *list = orig; | |
544 | struct commit *relevant = NULL; | |
545 | ||
546 | if (!orig) | |
547 | return NULL; | |
548 | ||
549 | /* | |
550 | * For 1-parent commits, or if first-parent-only, then return that | |
551 | * first parent (even if not "relevant" by the above definition). | |
552 | * TREESAME will have been set purely on that parent. | |
553 | */ | |
554 | if (revs->first_parent_only || !orig->next) | |
555 | return orig->item; | |
556 | ||
557 | /* | |
558 | * For multi-parent commits, identify a sole relevant parent, if any. | |
559 | * If we have only one relevant parent, then TREESAME will be set purely | |
560 | * with regard to that parent, and we can simplify accordingly. | |
561 | * | |
562 | * If we have more than one relevant parent, or no relevant parents | |
563 | * (and multiple irrelevant ones), then we can't select a parent here | |
564 | * and return NULL. | |
565 | */ | |
566 | while (list) { | |
567 | struct commit *commit = list->item; | |
568 | list = list->next; | |
569 | if (relevant_commit(commit)) { | |
570 | if (relevant) | |
571 | return NULL; | |
572 | relevant = commit; | |
573 | } | |
574 | } | |
575 | return relevant; | |
576 | } | |
577 | ||
0a4ba7f8 JH |
578 | /* |
579 | * The goal is to get REV_TREE_NEW as the result only if the | |
ceff8e7a LT |
580 | * diff consists of all '+' (and no other changes), REV_TREE_OLD |
581 | * if the whole diff is removal of old data, and otherwise | |
582 | * REV_TREE_DIFFERENT (of course if the trees are the same we | |
583 | * want REV_TREE_SAME). | |
a937b37e JK |
584 | * |
585 | * The only time we care about the distinction is when | |
586 | * remove_empty_trees is in effect, in which case we care only about | |
587 | * whether the whole change is REV_TREE_NEW, or if there's another type | |
588 | * of change. Which means we can stop the diff early in either of these | |
589 | * cases: | |
590 | * | |
591 | * 1. We're not using remove_empty_trees at all. | |
592 | * | |
593 | * 2. We saw anything except REV_TREE_NEW. | |
0a4ba7f8 | 594 | */ |
296a1438 ÆAB |
595 | #define REV_TREE_SAME 0 |
596 | #define REV_TREE_NEW 1 /* Only new files */ | |
597 | #define REV_TREE_OLD 2 /* Only files removed */ | |
598 | #define REV_TREE_DIFFERENT 3 /* Mixed changes */ | |
8efdc326 | 599 | static int tree_difference = REV_TREE_SAME; |
a4a88b2b LT |
600 | |
601 | static void file_add_remove(struct diff_options *options, | |
602 | int addremove, unsigned mode, | |
c26022ea BW |
603 | const struct object_id *oid, |
604 | int oid_valid, | |
e3d42c47 | 605 | const char *fullpath, unsigned dirty_submodule) |
a4a88b2b | 606 | { |
ceff8e7a | 607 | int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD; |
a937b37e | 608 | struct rev_info *revs = options->change_fn_data; |
a4a88b2b | 609 | |
ceff8e7a | 610 | tree_difference |= diff; |
a937b37e | 611 | if (!revs->remove_empty_trees || tree_difference != REV_TREE_NEW) |
0d1e0e78 | 612 | options->flags.has_changes = 1; |
a4a88b2b LT |
613 | } |
614 | ||
615 | static void file_change(struct diff_options *options, | |
616 | unsigned old_mode, unsigned new_mode, | |
94a0097a BW |
617 | const struct object_id *old_oid, |
618 | const struct object_id *new_oid, | |
619 | int old_oid_valid, int new_oid_valid, | |
e3d42c47 JL |
620 | const char *fullpath, |
621 | unsigned old_dirty_submodule, unsigned new_dirty_submodule) | |
a4a88b2b | 622 | { |
8efdc326 | 623 | tree_difference = REV_TREE_DIFFERENT; |
0d1e0e78 | 624 | options->flags.has_changes = 1; |
a4a88b2b LT |
625 | } |
626 | ||
42e50e78 GS |
627 | static int bloom_filter_atexit_registered; |
628 | static unsigned int count_bloom_filter_maybe; | |
629 | static unsigned int count_bloom_filter_definitely_not; | |
630 | static unsigned int count_bloom_filter_false_positive; | |
631 | static unsigned int count_bloom_filter_not_present; | |
42e50e78 GS |
632 | |
633 | static void trace2_bloom_filter_statistics_atexit(void) | |
634 | { | |
635 | struct json_writer jw = JSON_WRITER_INIT; | |
636 | ||
637 | jw_object_begin(&jw, 0); | |
638 | jw_object_intmax(&jw, "filter_not_present", count_bloom_filter_not_present); | |
42e50e78 GS |
639 | jw_object_intmax(&jw, "maybe", count_bloom_filter_maybe); |
640 | jw_object_intmax(&jw, "definitely_not", count_bloom_filter_definitely_not); | |
641 | jw_object_intmax(&jw, "false_positive", count_bloom_filter_false_positive); | |
642 | jw_end(&jw); | |
643 | ||
644 | trace2_data_json("bloom", the_repository, "statistics", &jw); | |
645 | ||
646 | jw_release(&jw); | |
647 | } | |
648 | ||
8918e379 DS |
649 | static int forbid_bloom_filters(struct pathspec *spec) |
650 | { | |
651 | if (spec->has_wildcard) | |
652 | return 1; | |
653 | if (spec->nr > 1) | |
654 | return 1; | |
655 | if (spec->magic & ~PATHSPEC_LITERAL) | |
656 | return 1; | |
657 | if (spec->nr && (spec->items[0].magic & ~PATHSPEC_LITERAL)) | |
658 | return 1; | |
659 | ||
660 | return 0; | |
661 | } | |
662 | ||
a56b9464 GS |
663 | static void prepare_to_use_bloom_filter(struct rev_info *revs) |
664 | { | |
665 | struct pathspec_item *pi; | |
666 | char *path_alloc = NULL; | |
c525ce95 | 667 | const char *path, *p; |
c525ce95 SG |
668 | size_t len; |
669 | int path_component_nr = 1; | |
a56b9464 GS |
670 | |
671 | if (!revs->commits) | |
8918e379 DS |
672 | return; |
673 | ||
674 | if (forbid_bloom_filters(&revs->prune_data)) | |
675 | return; | |
a56b9464 GS |
676 | |
677 | repo_parse_commit(revs->repo, revs->commits->item); | |
678 | ||
4f364405 | 679 | revs->bloom_filter_settings = get_bloom_filter_settings(revs->repo); |
a56b9464 GS |
680 | if (!revs->bloom_filter_settings) |
681 | return; | |
682 | ||
f32dde8c DS |
683 | if (!revs->pruning.pathspec.nr) |
684 | return; | |
685 | ||
a56b9464 | 686 | pi = &revs->pruning.pathspec.items[0]; |
a56b9464 GS |
687 | |
688 | /* remove single trailing slash from path, if needed */ | |
fd9a631c JK |
689 | if (pi->len > 0 && pi->match[pi->len - 1] == '/') { |
690 | path_alloc = xmemdupz(pi->match, pi->len - 1); | |
dc8e95ba | 691 | path = path_alloc; |
a56b9464 | 692 | } else |
dc8e95ba | 693 | path = pi->match; |
a56b9464 GS |
694 | |
695 | len = strlen(path); | |
f3c2a368 TB |
696 | if (!len) { |
697 | revs->bloom_filter_settings = NULL; | |
398e659e | 698 | free(path_alloc); |
f3c2a368 TB |
699 | return; |
700 | } | |
a56b9464 | 701 | |
c525ce95 SG |
702 | p = path; |
703 | while (*p) { | |
704 | /* | |
705 | * At this point, the path is normalized to use Unix-style | |
706 | * path separators. This is required due to how the | |
707 | * changed-path Bloom filters store the paths. | |
708 | */ | |
709 | if (*p == '/') | |
710 | path_component_nr++; | |
711 | p++; | |
712 | } | |
713 | ||
714 | revs->bloom_keys_nr = path_component_nr; | |
715 | ALLOC_ARRAY(revs->bloom_keys, revs->bloom_keys_nr); | |
a56b9464 | 716 | |
c525ce95 SG |
717 | fill_bloom_key(path, len, &revs->bloom_keys[0], |
718 | revs->bloom_filter_settings); | |
719 | path_component_nr = 1; | |
720 | ||
721 | p = path + len - 1; | |
722 | while (p > path) { | |
723 | if (*p == '/') | |
724 | fill_bloom_key(path, p - path, | |
725 | &revs->bloom_keys[path_component_nr++], | |
726 | revs->bloom_filter_settings); | |
727 | p--; | |
728 | } | |
a56b9464 | 729 | |
42e50e78 GS |
730 | if (trace2_is_enabled() && !bloom_filter_atexit_registered) { |
731 | atexit(trace2_bloom_filter_statistics_atexit); | |
732 | bloom_filter_atexit_registered = 1; | |
733 | } | |
734 | ||
a56b9464 GS |
735 | free(path_alloc); |
736 | } | |
737 | ||
738 | static int check_maybe_different_in_bloom_filter(struct rev_info *revs, | |
739 | struct commit *commit) | |
740 | { | |
741 | struct bloom_filter *filter; | |
c525ce95 | 742 | int result = 1, j; |
a56b9464 GS |
743 | |
744 | if (!revs->repo->objects->commit_graph) | |
745 | return -1; | |
746 | ||
c49c82aa | 747 | if (commit_graph_generation(commit) == GENERATION_NUMBER_INFINITY) |
a56b9464 GS |
748 | return -1; |
749 | ||
312cff52 | 750 | filter = get_bloom_filter(revs->repo, commit); |
a56b9464 GS |
751 | |
752 | if (!filter) { | |
42e50e78 | 753 | count_bloom_filter_not_present++; |
a56b9464 GS |
754 | return -1; |
755 | } | |
756 | ||
c525ce95 SG |
757 | for (j = 0; result && j < revs->bloom_keys_nr; j++) { |
758 | result = bloom_filter_contains(filter, | |
759 | &revs->bloom_keys[j], | |
760 | revs->bloom_filter_settings); | |
a56b9464 GS |
761 | } |
762 | ||
42e50e78 GS |
763 | if (result) |
764 | count_bloom_filter_maybe++; | |
765 | else | |
766 | count_bloom_filter_definitely_not++; | |
767 | ||
a56b9464 GS |
768 | return result; |
769 | } | |
770 | ||
ff5f5f26 | 771 | static int rev_compare_tree(struct rev_info *revs, |
a56b9464 | 772 | struct commit *parent, struct commit *commit, int nth_parent) |
a4a88b2b | 773 | { |
2e27bd77 DS |
774 | struct tree *t1 = get_commit_tree(parent); |
775 | struct tree *t2 = get_commit_tree(commit); | |
a56b9464 | 776 | int bloom_ret = 1; |
3a5e8608 | 777 | |
a4a88b2b | 778 | if (!t1) |
8efdc326 | 779 | return REV_TREE_NEW; |
ceff8e7a LT |
780 | if (!t2) |
781 | return REV_TREE_OLD; | |
78892e32 LT |
782 | |
783 | if (revs->simplify_by_decoration) { | |
784 | /* | |
785 | * If we are simplifying by decoration, then the commit | |
786 | * is worth showing if it has a tag pointing at it. | |
787 | */ | |
2608c249 | 788 | if (get_name_decoration(&commit->object)) |
78892e32 LT |
789 | return REV_TREE_DIFFERENT; |
790 | /* | |
791 | * A commit that is not pointed by a tag is uninteresting | |
792 | * if we are not limited by path. This means that you will | |
793 | * see the usual "commits that touch the paths" plus any | |
794 | * tagged commit by specifying both --simplify-by-decoration | |
795 | * and pathspec. | |
796 | */ | |
afe069d1 | 797 | if (!revs->prune_data.nr) |
78892e32 LT |
798 | return REV_TREE_SAME; |
799 | } | |
ceff8e7a | 800 | |
c525ce95 | 801 | if (revs->bloom_keys_nr && !nth_parent) { |
a56b9464 GS |
802 | bloom_ret = check_maybe_different_in_bloom_filter(revs, commit); |
803 | ||
804 | if (bloom_ret == 0) | |
805 | return REV_TREE_SAME; | |
806 | } | |
807 | ||
8efdc326 | 808 | tree_difference = REV_TREE_SAME; |
0d1e0e78 | 809 | revs->pruning.flags.has_changes = 0; |
0ee3cb88 | 810 | diff_tree_oid(&t1->object.oid, &t2->object.oid, "", &revs->pruning); |
a56b9464 | 811 | |
42e50e78 GS |
812 | if (!nth_parent) |
813 | if (bloom_ret == 1 && tree_difference == REV_TREE_SAME) | |
814 | count_bloom_filter_false_positive++; | |
815 | ||
a4a88b2b LT |
816 | return tree_difference; |
817 | } | |
818 | ||
3a5e8608 | 819 | static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit) |
a4a88b2b | 820 | { |
2e27bd77 | 821 | struct tree *t1 = get_commit_tree(commit); |
a4a88b2b LT |
822 | |
823 | if (!t1) | |
824 | return 0; | |
825 | ||
0a4ba7f8 | 826 | tree_difference = REV_TREE_SAME; |
0d1e0e78 | 827 | revs->pruning.flags.has_changes = 0; |
0ee3cb88 | 828 | diff_tree_oid(NULL, &t1->object.oid, "", &revs->pruning); |
a4a88b2b | 829 | |
0ee3cb88 | 830 | return tree_difference == REV_TREE_SAME; |
a4a88b2b LT |
831 | } |
832 | ||
d0af663e KB |
833 | struct treesame_state { |
834 | unsigned int nparents; | |
835 | unsigned char treesame[FLEX_ARRAY]; | |
836 | }; | |
837 | ||
838 | static struct treesame_state *initialise_treesame(struct rev_info *revs, struct commit *commit) | |
839 | { | |
840 | unsigned n = commit_list_count(commit->parents); | |
50a6c8ef | 841 | struct treesame_state *st = xcalloc(1, st_add(sizeof(*st), n)); |
d0af663e KB |
842 | st->nparents = n; |
843 | add_decoration(&revs->treesame, &commit->object, st); | |
844 | return st; | |
845 | } | |
846 | ||
847 | /* | |
848 | * Must be called immediately after removing the nth_parent from a commit's | |
849 | * parent list, if we are maintaining the per-parent treesame[] decoration. | |
850 | * This does not recalculate the master TREESAME flag - update_treesame() | |
851 | * should be called to update it after a sequence of treesame[] modifications | |
852 | * that may have affected it. | |
853 | */ | |
854 | static int compact_treesame(struct rev_info *revs, struct commit *commit, unsigned nth_parent) | |
855 | { | |
856 | struct treesame_state *st; | |
857 | int old_same; | |
858 | ||
859 | if (!commit->parents) { | |
860 | /* | |
861 | * Have just removed the only parent from a non-merge. | |
862 | * Different handling, as we lack decoration. | |
863 | */ | |
864 | if (nth_parent != 0) | |
865 | die("compact_treesame %u", nth_parent); | |
866 | old_same = !!(commit->object.flags & TREESAME); | |
867 | if (rev_same_tree_as_empty(revs, commit)) | |
868 | commit->object.flags |= TREESAME; | |
869 | else | |
870 | commit->object.flags &= ~TREESAME; | |
871 | return old_same; | |
872 | } | |
873 | ||
874 | st = lookup_decoration(&revs->treesame, &commit->object); | |
875 | if (!st || nth_parent >= st->nparents) | |
876 | die("compact_treesame %u", nth_parent); | |
877 | ||
878 | old_same = st->treesame[nth_parent]; | |
879 | memmove(st->treesame + nth_parent, | |
880 | st->treesame + nth_parent + 1, | |
881 | st->nparents - nth_parent - 1); | |
882 | ||
883 | /* | |
884 | * If we've just become a non-merge commit, update TREESAME | |
885 | * immediately, and remove the no-longer-needed decoration. | |
886 | * If still a merge, defer update until update_treesame(). | |
887 | */ | |
888 | if (--st->nparents == 1) { | |
889 | if (commit->parents->next) | |
890 | die("compact_treesame parents mismatch"); | |
891 | if (st->treesame[0] && revs->dense) | |
892 | commit->object.flags |= TREESAME; | |
893 | else | |
894 | commit->object.flags &= ~TREESAME; | |
895 | free(add_decoration(&revs->treesame, &commit->object, NULL)); | |
896 | } | |
897 | ||
898 | return old_same; | |
899 | } | |
900 | ||
901 | static unsigned update_treesame(struct rev_info *revs, struct commit *commit) | |
902 | { | |
903 | if (commit->parents && commit->parents->next) { | |
904 | unsigned n; | |
905 | struct treesame_state *st; | |
4d826608 KB |
906 | struct commit_list *p; |
907 | unsigned relevant_parents; | |
908 | unsigned relevant_change, irrelevant_change; | |
d0af663e KB |
909 | |
910 | st = lookup_decoration(&revs->treesame, &commit->object); | |
911 | if (!st) | |
f2fd0760 | 912 | die("update_treesame %s", oid_to_hex(&commit->object.oid)); |
4d826608 KB |
913 | relevant_parents = 0; |
914 | relevant_change = irrelevant_change = 0; | |
915 | for (p = commit->parents, n = 0; p; n++, p = p->next) { | |
916 | if (relevant_commit(p->item)) { | |
917 | relevant_change |= !st->treesame[n]; | |
918 | relevant_parents++; | |
919 | } else | |
920 | irrelevant_change |= !st->treesame[n]; | |
d0af663e | 921 | } |
4d826608 KB |
922 | if (relevant_parents ? relevant_change : irrelevant_change) |
923 | commit->object.flags &= ~TREESAME; | |
924 | else | |
925 | commit->object.flags |= TREESAME; | |
d0af663e KB |
926 | } |
927 | ||
928 | return commit->object.flags & TREESAME; | |
929 | } | |
930 | ||
4d826608 KB |
931 | static inline int limiting_can_increase_treesame(const struct rev_info *revs) |
932 | { | |
933 | /* | |
934 | * TREESAME is irrelevant unless prune && dense; | |
935 | * if simplify_history is set, we can't have a mixture of TREESAME and | |
936 | * !TREESAME INTERESTING parents (and we don't have treesame[] | |
937 | * decoration anyway); | |
938 | * if first_parent_only is set, then the TREESAME flag is locked | |
939 | * against the first parent (and again we lack treesame[] decoration). | |
940 | */ | |
941 | return revs->prune && revs->dense && | |
942 | !revs->simplify_history && | |
943 | !revs->first_parent_only; | |
944 | } | |
945 | ||
a4a88b2b LT |
946 | static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) |
947 | { | |
948 | struct commit_list **pp, *parent; | |
d0af663e | 949 | struct treesame_state *ts = NULL; |
4d826608 KB |
950 | int relevant_change = 0, irrelevant_change = 0; |
951 | int relevant_parents, nth_parent; | |
a4a88b2b | 952 | |
53b2c823 LT |
953 | /* |
954 | * If we don't do pruning, everything is interesting | |
955 | */ | |
7dc0fe3b | 956 | if (!revs->prune) |
53b2c823 | 957 | return; |
53b2c823 | 958 | |
2e27bd77 | 959 | if (!get_commit_tree(commit)) |
a4a88b2b LT |
960 | return; |
961 | ||
962 | if (!commit->parents) { | |
3a5e8608 | 963 | if (rev_same_tree_as_empty(revs, commit)) |
7dc0fe3b | 964 | commit->object.flags |= TREESAME; |
a4a88b2b LT |
965 | return; |
966 | } | |
967 | ||
53b2c823 LT |
968 | /* |
969 | * Normal non-merge commit? If we don't want to make the | |
970 | * history dense, we consider it always to be a change.. | |
971 | */ | |
7dc0fe3b | 972 | if (!revs->dense && !commit->parents->next) |
53b2c823 | 973 | return; |
53b2c823 | 974 | |
4d826608 | 975 | for (pp = &commit->parents, nth_parent = 0, relevant_parents = 0; |
d0af663e KB |
976 | (parent = *pp) != NULL; |
977 | pp = &parent->next, nth_parent++) { | |
a4a88b2b | 978 | struct commit *p = parent->item; |
4d826608 KB |
979 | if (relevant_commit(p)) |
980 | relevant_parents++; | |
a4a88b2b | 981 | |
d0af663e KB |
982 | if (nth_parent == 1) { |
983 | /* | |
984 | * This our second loop iteration - so we now know | |
985 | * we're dealing with a merge. | |
986 | * | |
987 | * Do not compare with later parents when we care only about | |
988 | * the first parent chain, in order to avoid derailing the | |
989 | * traversal to follow a side branch that brought everything | |
990 | * in the path we are limited to by the pathspec. | |
991 | */ | |
992 | if (revs->first_parent_only) | |
993 | break; | |
994 | /* | |
995 | * If this will remain a potentially-simplifiable | |
996 | * merge, remember per-parent treesame if needed. | |
997 | * Initialise the array with the comparison from our | |
998 | * first iteration. | |
999 | */ | |
1000 | if (revs->treesame.name && | |
1001 | !revs->simplify_history && | |
1002 | !(commit->object.flags & UNINTERESTING)) { | |
1003 | ts = initialise_treesame(revs, commit); | |
4d826608 | 1004 | if (!(irrelevant_change || relevant_change)) |
d0af663e KB |
1005 | ts->treesame[0] = 1; |
1006 | } | |
1007 | } | |
ea3f7e59 | 1008 | if (repo_parse_commit(revs->repo, p) < 0) |
cc0e6c5a | 1009 | die("cannot simplify commit %s (because of %s)", |
f2fd0760 | 1010 | oid_to_hex(&commit->object.oid), |
1011 | oid_to_hex(&p->object.oid)); | |
a56b9464 | 1012 | switch (rev_compare_tree(revs, p, commit, nth_parent)) { |
8efdc326 | 1013 | case REV_TREE_SAME: |
141efdba | 1014 | if (!revs->simplify_history || !relevant_commit(p)) { |
f3219fbb JH |
1015 | /* Even if a merge with an uninteresting |
1016 | * side branch brought the entire change | |
1017 | * we are interested in, we do not want | |
1018 | * to lose the other branches of this | |
1019 | * merge, so we just keep going. | |
1020 | */ | |
d0af663e KB |
1021 | if (ts) |
1022 | ts->treesame[nth_parent] = 1; | |
f3219fbb JH |
1023 | continue; |
1024 | } | |
a4a88b2b LT |
1025 | parent->next = NULL; |
1026 | commit->parents = parent; | |
8d049e18 DS |
1027 | |
1028 | /* | |
1029 | * A merge commit is a "diversion" if it is not | |
1030 | * TREESAME to its first parent but is TREESAME | |
1031 | * to a later parent. In the simplified history, | |
1032 | * we "divert" the history walk to the later | |
1033 | * parent. These commits are shown when "show_pulls" | |
1034 | * is enabled, so do not mark the object as | |
1035 | * TREESAME here. | |
1036 | */ | |
1037 | if (!revs->show_pulls || !nth_parent) | |
1038 | commit->object.flags |= TREESAME; | |
1039 | ||
a4a88b2b LT |
1040 | return; |
1041 | ||
8efdc326 FK |
1042 | case REV_TREE_NEW: |
1043 | if (revs->remove_empty_trees && | |
3a5e8608 | 1044 | rev_same_tree_as_empty(revs, p)) { |
c348f31a JH |
1045 | /* We are adding all the specified |
1046 | * paths from this parent, so the | |
1047 | * history beyond this parent is not | |
1048 | * interesting. Remove its parents | |
1049 | * (they are grandparents for us). | |
1050 | * IOW, we pretend this parent is a | |
1051 | * "root" commit. | |
a41e109c | 1052 | */ |
ea3f7e59 | 1053 | if (repo_parse_commit(revs->repo, p) < 0) |
cc0e6c5a | 1054 | die("cannot simplify commit %s (invalid %s)", |
f2fd0760 | 1055 | oid_to_hex(&commit->object.oid), |
1056 | oid_to_hex(&p->object.oid)); | |
c348f31a | 1057 | p->parents = NULL; |
a4a88b2b LT |
1058 | } |
1059 | /* fallthrough */ | |
ceff8e7a | 1060 | case REV_TREE_OLD: |
8efdc326 | 1061 | case REV_TREE_DIFFERENT: |
4d826608 KB |
1062 | if (relevant_commit(p)) |
1063 | relevant_change = 1; | |
1064 | else | |
1065 | irrelevant_change = 1; | |
8d049e18 DS |
1066 | |
1067 | if (!nth_parent) | |
1068 | commit->object.flags |= PULL_MERGE; | |
1069 | ||
a4a88b2b LT |
1070 | continue; |
1071 | } | |
f2fd0760 | 1072 | die("bad tree compare for commit %s", oid_to_hex(&commit->object.oid)); |
a4a88b2b | 1073 | } |
4d826608 KB |
1074 | |
1075 | /* | |
1076 | * TREESAME is straightforward for single-parent commits. For merge | |
1077 | * commits, it is most useful to define it so that "irrelevant" | |
1078 | * parents cannot make us !TREESAME - if we have any relevant | |
1079 | * parents, then we only consider TREESAMEness with respect to them, | |
1080 | * allowing irrelevant merges from uninteresting branches to be | |
1081 | * simplified away. Only if we have only irrelevant parents do we | |
1082 | * base TREESAME on them. Note that this logic is replicated in | |
1083 | * update_treesame, which should be kept in sync. | |
1084 | */ | |
1085 | if (relevant_parents ? !relevant_change : !irrelevant_change) | |
1086 | commit->object.flags |= TREESAME; | |
a4a88b2b LT |
1087 | } |
1088 | ||
5284fc5c | 1089 | static int process_parents(struct rev_info *revs, struct commit *commit, |
8320b1db | 1090 | struct commit_list **list, struct prio_queue *queue) |
a4a88b2b LT |
1091 | { |
1092 | struct commit_list *parent = commit->parents; | |
257418c5 | 1093 | unsigned pass_flags; |
a4a88b2b | 1094 | |
3381c790 | 1095 | if (commit->object.flags & ADDED) |
cc0e6c5a | 1096 | return 0; |
3381c790 LT |
1097 | commit->object.flags |= ADDED; |
1098 | ||
a330de31 VM |
1099 | if (revs->include_check && |
1100 | !revs->include_check(commit, revs->include_check_data)) | |
1101 | return 0; | |
1102 | ||
a4a88b2b LT |
1103 | /* |
1104 | * If the commit is uninteresting, don't try to | |
1105 | * prune parents - we want the maximal uninteresting | |
1106 | * set. | |
1107 | * | |
1108 | * Normally we haven't parsed the parent | |
1109 | * yet, so we won't have a parent of a parent | |
1110 | * here. However, it may turn out that we've | |
1111 | * reached this commit some other way (where it | |
1112 | * wasn't uninteresting), in which case we need | |
1113 | * to mark its parents recursively too.. | |
1114 | */ | |
1115 | if (commit->object.flags & UNINTERESTING) { | |
1116 | while (parent) { | |
1117 | struct commit *p = parent->item; | |
1118 | parent = parent->next; | |
aeeae1b7 JH |
1119 | if (p) |
1120 | p->object.flags |= UNINTERESTING; | |
ea3f7e59 | 1121 | if (repo_parse_commit_gently(revs->repo, p, 1) < 0) |
aeeae1b7 | 1122 | continue; |
a4a88b2b | 1123 | if (p->parents) |
9d505b7b | 1124 | mark_parents_uninteresting(revs, p); |
a4a88b2b LT |
1125 | if (p->object.flags & SEEN) |
1126 | continue; | |
b2025da3 | 1127 | p->object.flags |= (SEEN | NOT_USER_GIVEN); |
5284fc5c | 1128 | if (list) |
8320b1db JK |
1129 | commit_list_insert_by_date(p, list); |
1130 | if (queue) | |
1131 | prio_queue_put(queue, p); | |
9d505b7b JZ |
1132 | if (revs->exclude_first_parent_only) |
1133 | break; | |
a4a88b2b | 1134 | } |
cc0e6c5a | 1135 | return 0; |
a4a88b2b LT |
1136 | } |
1137 | ||
1138 | /* | |
1139 | * Ok, the commit wasn't uninteresting. Try to | |
1140 | * simplify the commit history and find the parent | |
1141 | * that has no differences in the path set if one exists. | |
1142 | */ | |
53b2c823 | 1143 | try_to_simplify_commit(revs, commit); |
a4a88b2b | 1144 | |
ba1d4505 | 1145 | if (revs->no_walk) |
cc0e6c5a | 1146 | return 0; |
ba1d4505 | 1147 | |
257418c5 | 1148 | pass_flags = (commit->object.flags & (SYMMETRIC_LEFT | ANCESTRY_PATH)); |
0053e902 | 1149 | |
d9c292e8 | 1150 | for (parent = commit->parents; parent; parent = parent->next) { |
a4a88b2b | 1151 | struct commit *p = parent->item; |
df11e196 JT |
1152 | int gently = revs->ignore_missing_links || |
1153 | revs->exclude_promisor_objects; | |
ea3f7e59 | 1154 | if (repo_parse_commit_gently(revs->repo, p, gently) < 0) { |
df11e196 JT |
1155 | if (revs->exclude_promisor_objects && |
1156 | is_promisor_object(&p->object.oid)) { | |
1157 | if (revs->first_parent_only) | |
1158 | break; | |
1159 | continue; | |
1160 | } | |
cc0e6c5a | 1161 | return -1; |
df11e196 | 1162 | } |
87be2523 NTND |
1163 | if (revs->sources) { |
1164 | char **slot = revision_sources_at(revs->sources, p); | |
1165 | ||
1166 | if (!*slot) | |
1167 | *slot = *revision_sources_at(revs->sources, commit); | |
1168 | } | |
257418c5 | 1169 | p->object.flags |= pass_flags; |
ad1012eb | 1170 | if (!(p->object.flags & SEEN)) { |
b2025da3 | 1171 | p->object.flags |= (SEEN | NOT_USER_GIVEN); |
5284fc5c | 1172 | if (list) |
8320b1db JK |
1173 | commit_list_insert_by_date(p, list); |
1174 | if (queue) | |
1175 | prio_queue_put(queue, p); | |
ad1012eb | 1176 | } |
60d30b02 | 1177 | if (revs->first_parent_only) |
d9c292e8 | 1178 | break; |
a4a88b2b | 1179 | } |
cc0e6c5a | 1180 | return 0; |
a4a88b2b LT |
1181 | } |
1182 | ||
36d56de6 | 1183 | static void cherry_pick_list(struct commit_list *list, struct rev_info *revs) |
d7a17cad JH |
1184 | { |
1185 | struct commit_list *p; | |
1186 | int left_count = 0, right_count = 0; | |
1187 | int left_first; | |
1188 | struct patch_ids ids; | |
adbbb31e | 1189 | unsigned cherry_flag; |
d7a17cad JH |
1190 | |
1191 | /* First count the commits on the left and on the right */ | |
1192 | for (p = list; p; p = p->next) { | |
1193 | struct commit *commit = p->item; | |
1194 | unsigned flags = commit->object.flags; | |
1195 | if (flags & BOUNDARY) | |
1196 | ; | |
1197 | else if (flags & SYMMETRIC_LEFT) | |
1198 | left_count++; | |
1199 | else | |
1200 | right_count++; | |
1201 | } | |
1202 | ||
36c07975 TR |
1203 | if (!left_count || !right_count) |
1204 | return; | |
1205 | ||
d7a17cad | 1206 | left_first = left_count < right_count; |
2abf3503 | 1207 | init_patch_ids(revs->repo, &ids); |
66f13625 | 1208 | ids.diffopts.pathspec = revs->diffopt.pathspec; |
d7a17cad JH |
1209 | |
1210 | /* Compute patch-ids for one side */ | |
1211 | for (p = list; p; p = p->next) { | |
1212 | struct commit *commit = p->item; | |
1213 | unsigned flags = commit->object.flags; | |
1214 | ||
1215 | if (flags & BOUNDARY) | |
1216 | continue; | |
1217 | /* | |
1218 | * If we have fewer left, left_first is set and we omit | |
1219 | * commits on the right branch in this loop. If we have | |
1220 | * fewer right, we skip the left ones. | |
1221 | */ | |
1222 | if (left_first != !!(flags & SYMMETRIC_LEFT)) | |
1223 | continue; | |
683f17ec | 1224 | add_commit_patch_id(commit, &ids); |
d7a17cad JH |
1225 | } |
1226 | ||
adbbb31e MG |
1227 | /* either cherry_mark or cherry_pick are true */ |
1228 | cherry_flag = revs->cherry_mark ? PATCHSAME : SHOWN; | |
1229 | ||
d7a17cad JH |
1230 | /* Check the other side */ |
1231 | for (p = list; p; p = p->next) { | |
1232 | struct commit *commit = p->item; | |
1233 | struct patch_id *id; | |
1234 | unsigned flags = commit->object.flags; | |
1235 | ||
1236 | if (flags & BOUNDARY) | |
1237 | continue; | |
1238 | /* | |
1239 | * If we have fewer left, left_first is set and we omit | |
1240 | * commits on the left branch in this loop. | |
1241 | */ | |
1242 | if (left_first == !!(flags & SYMMETRIC_LEFT)) | |
1243 | continue; | |
1244 | ||
1245 | /* | |
1246 | * Have we seen the same patch id? | |
1247 | */ | |
c9e3a4e7 | 1248 | id = patch_id_iter_first(commit, &ids); |
d7a17cad JH |
1249 | if (!id) |
1250 | continue; | |
d7a17cad | 1251 | |
683f17ec | 1252 | commit->object.flags |= cherry_flag; |
c9e3a4e7 JK |
1253 | do { |
1254 | id->commit->object.flags |= cherry_flag; | |
1255 | } while ((id = patch_id_iter_next(id, &ids))); | |
d7a17cad JH |
1256 | } |
1257 | ||
1258 | free_patch_ids(&ids); | |
1259 | } | |
1260 | ||
7d004199 LT |
1261 | /* How many extra uninteresting commits we want to see.. */ |
1262 | #define SLOP 5 | |
1263 | ||
dddbad72 | 1264 | static int still_interesting(struct commit_list *src, timestamp_t date, int slop, |
b6e8a3b5 | 1265 | struct commit **interesting_cache) |
3131b713 | 1266 | { |
7d004199 LT |
1267 | /* |
1268 | * No source list at all? We're definitely done.. | |
1269 | */ | |
1270 | if (!src) | |
1271 | return 0; | |
1272 | ||
1273 | /* | |
1274 | * Does the destination list contain entries with a date | |
1275 | * before the source list? Definitely _not_ done. | |
1276 | */ | |
c19d1b4e | 1277 | if (date <= src->item->date) |
7d004199 LT |
1278 | return SLOP; |
1279 | ||
1280 | /* | |
1281 | * Does the source list still have interesting commits in | |
1282 | * it? Definitely not done.. | |
1283 | */ | |
b6e8a3b5 | 1284 | if (!everybody_uninteresting(src, interesting_cache)) |
7d004199 LT |
1285 | return SLOP; |
1286 | ||
1287 | /* Ok, we're closing in.. */ | |
1288 | return slop-1; | |
3131b713 LT |
1289 | } |
1290 | ||
ebdc94f3 | 1291 | /* |
257418c5 EN |
1292 | * "rev-list --ancestry-path=C_0 [--ancestry-path=C_1 ...] A..B" |
1293 | * computes commits that are ancestors of B but not ancestors of A but | |
1294 | * further limits the result to those that have any of C in their | |
1295 | * ancestry path (i.e. are either ancestors of any of C, descendants | |
1296 | * of any of C, or are any of C). If --ancestry-path is specified with | |
1297 | * no commit, we use all bottom commits for C. | |
1298 | * | |
1299 | * Before this function is called, ancestors of C will have already | |
1300 | * been marked with ANCESTRY_PATH previously. | |
1301 | * | |
1302 | * This takes the list of bottom commits and the result of "A..B" | |
1303 | * without --ancestry-path, and limits the latter further to the ones | |
1304 | * that have any of C in their ancestry path. Since the ancestors of C | |
1305 | * have already been marked (a prerequisite of this function), we just | |
1306 | * need to mark the descendants, then exclude any commit that does not | |
1307 | * have any of these marks. | |
ebdc94f3 | 1308 | */ |
257418c5 | 1309 | static void limit_to_ancestry(struct commit_list *bottoms, struct commit_list *list) |
ebdc94f3 JH |
1310 | { |
1311 | struct commit_list *p; | |
1312 | struct commit_list *rlist = NULL; | |
1313 | int made_progress; | |
1314 | ||
1315 | /* | |
1316 | * Reverse the list so that it will be likely that we would | |
1317 | * process parents before children. | |
1318 | */ | |
1319 | for (p = list; p; p = p->next) | |
1320 | commit_list_insert(p->item, &rlist); | |
1321 | ||
257418c5 | 1322 | for (p = bottoms; p; p = p->next) |
ebdc94f3 JH |
1323 | p->item->object.flags |= TMP_MARK; |
1324 | ||
1325 | /* | |
1326 | * Mark the ones that can reach bottom commits in "list", | |
1327 | * in a bottom-up fashion. | |
1328 | */ | |
1329 | do { | |
1330 | made_progress = 0; | |
1331 | for (p = rlist; p; p = p->next) { | |
1332 | struct commit *c = p->item; | |
1333 | struct commit_list *parents; | |
1334 | if (c->object.flags & (TMP_MARK | UNINTERESTING)) | |
1335 | continue; | |
1336 | for (parents = c->parents; | |
1337 | parents; | |
1338 | parents = parents->next) { | |
1339 | if (!(parents->item->object.flags & TMP_MARK)) | |
1340 | continue; | |
1341 | c->object.flags |= TMP_MARK; | |
1342 | made_progress = 1; | |
1343 | break; | |
1344 | } | |
1345 | } | |
1346 | } while (made_progress); | |
1347 | ||
1348 | /* | |
1349 | * NEEDSWORK: decide if we want to remove parents that are | |
1350 | * not marked with TMP_MARK from commit->parents for commits | |
1351 | * in the resulting list. We may not want to do that, though. | |
1352 | */ | |
1353 | ||
1354 | /* | |
257418c5 EN |
1355 | * The ones that are not marked with either TMP_MARK or |
1356 | * ANCESTRY_PATH are uninteresting | |
ebdc94f3 JH |
1357 | */ |
1358 | for (p = list; p; p = p->next) { | |
1359 | struct commit *c = p->item; | |
257418c5 | 1360 | if (c->object.flags & (TMP_MARK | ANCESTRY_PATH)) |
ebdc94f3 JH |
1361 | continue; |
1362 | c->object.flags |= UNINTERESTING; | |
1363 | } | |
1364 | ||
257418c5 | 1365 | /* We are done with TMP_MARK and ANCESTRY_PATH */ |
ebdc94f3 | 1366 | for (p = list; p; p = p->next) |
257418c5 EN |
1367 | p->item->object.flags &= ~(TMP_MARK | ANCESTRY_PATH); |
1368 | for (p = bottoms; p; p = p->next) | |
1369 | p->item->object.flags &= ~(TMP_MARK | ANCESTRY_PATH); | |
ebdc94f3 JH |
1370 | free_commit_list(rlist); |
1371 | } | |
1372 | ||
1373 | /* | |
257418c5 EN |
1374 | * Before walking the history, add the set of "negative" refs the |
1375 | * caller has asked to exclude to the bottom list. | |
ebdc94f3 JH |
1376 | * |
1377 | * This is used to compute "rev-list --ancestry-path A..B", as we need | |
1378 | * to filter the result of "A..B" further to the ones that can actually | |
1379 | * reach A. | |
1380 | */ | |
257418c5 EN |
1381 | static void collect_bottom_commits(struct commit_list *list, |
1382 | struct commit_list **bottom) | |
ebdc94f3 | 1383 | { |
257418c5 | 1384 | struct commit_list *elem; |
7f34a46f KB |
1385 | for (elem = list; elem; elem = elem->next) |
1386 | if (elem->item->object.flags & BOTTOM) | |
257418c5 | 1387 | commit_list_insert(elem->item, bottom); |
ebdc94f3 JH |
1388 | } |
1389 | ||
60adf7d7 MG |
1390 | /* Assumes either left_only or right_only is set */ |
1391 | static void limit_left_right(struct commit_list *list, struct rev_info *revs) | |
1392 | { | |
1393 | struct commit_list *p; | |
1394 | ||
1395 | for (p = list; p; p = p->next) { | |
1396 | struct commit *commit = p->item; | |
1397 | ||
1398 | if (revs->right_only) { | |
1399 | if (commit->object.flags & SYMMETRIC_LEFT) | |
1400 | commit->object.flags |= SHOWN; | |
1401 | } else /* revs->left_only is set */ | |
1402 | if (!(commit->object.flags & SYMMETRIC_LEFT)) | |
1403 | commit->object.flags |= SHOWN; | |
1404 | } | |
1405 | } | |
1406 | ||
cc0e6c5a | 1407 | static int limit_list(struct rev_info *revs) |
a4a88b2b | 1408 | { |
7d004199 | 1409 | int slop = SLOP; |
dddbad72 | 1410 | timestamp_t date = TIME_MAX; |
db69bf60 | 1411 | struct commit_list *original_list = revs->commits; |
a4a88b2b LT |
1412 | struct commit_list *newlist = NULL; |
1413 | struct commit_list **p = &newlist; | |
b6e8a3b5 | 1414 | struct commit *interesting_cache = NULL; |
ebdc94f3 | 1415 | |
257418c5 EN |
1416 | if (revs->ancestry_path_implicit_bottoms) { |
1417 | collect_bottom_commits(original_list, | |
1418 | &revs->ancestry_path_bottoms); | |
1419 | if (!revs->ancestry_path_bottoms) | |
97b03c35 | 1420 | die("--ancestry-path given but there are no bottom commits"); |
ebdc94f3 | 1421 | } |
a4a88b2b | 1422 | |
db69bf60 AH |
1423 | while (original_list) { |
1424 | struct commit *commit = pop_commit(&original_list); | |
a4a88b2b | 1425 | struct object *obj = &commit->object; |
cdcefbc9 | 1426 | show_early_output_fn_t show; |
a4a88b2b | 1427 | |
b6e8a3b5 JK |
1428 | if (commit == interesting_cache) |
1429 | interesting_cache = NULL; | |
1430 | ||
a4a88b2b LT |
1431 | if (revs->max_age != -1 && (commit->date < revs->max_age)) |
1432 | obj->flags |= UNINTERESTING; | |
db69bf60 | 1433 | if (process_parents(revs, commit, &original_list, NULL) < 0) |
cc0e6c5a | 1434 | return -1; |
a4a88b2b | 1435 | if (obj->flags & UNINTERESTING) { |
9d505b7b | 1436 | mark_parents_uninteresting(revs, commit); |
db69bf60 | 1437 | slop = still_interesting(original_list, date, slop, &interesting_cache); |
7d004199 | 1438 | if (slop) |
3131b713 | 1439 | continue; |
7d004199 | 1440 | break; |
a4a88b2b | 1441 | } |
01faa91c RS |
1442 | if (revs->min_age != -1 && (commit->date > revs->min_age) && |
1443 | !revs->line_level_traverse) | |
a4a88b2b | 1444 | continue; |
96697781 MV |
1445 | if (revs->max_age_as_filter != -1 && |
1446 | (commit->date < revs->max_age_as_filter) && !revs->line_level_traverse) | |
1447 | continue; | |
7d004199 | 1448 | date = commit->date; |
a4a88b2b | 1449 | p = &commit_list_insert(commit, p)->next; |
cdcefbc9 LT |
1450 | |
1451 | show = show_early_output; | |
1452 | if (!show) | |
1453 | continue; | |
1454 | ||
1455 | show(revs, newlist); | |
1456 | show_early_output = NULL; | |
a4a88b2b | 1457 | } |
adbbb31e | 1458 | if (revs->cherry_pick || revs->cherry_mark) |
36d56de6 | 1459 | cherry_pick_list(newlist, revs); |
d7a17cad | 1460 | |
60adf7d7 MG |
1461 | if (revs->left_only || revs->right_only) |
1462 | limit_left_right(newlist, revs); | |
1463 | ||
257418c5 EN |
1464 | if (revs->ancestry_path) |
1465 | limit_to_ancestry(revs->ancestry_path_bottoms, newlist); | |
ebdc94f3 | 1466 | |
4d826608 KB |
1467 | /* |
1468 | * Check if any commits have become TREESAME by some of their parents | |
1469 | * becoming UNINTERESTING. | |
1470 | */ | |
db69bf60 AH |
1471 | if (limiting_can_increase_treesame(revs)) { |
1472 | struct commit_list *list = NULL; | |
4d826608 KB |
1473 | for (list = newlist; list; list = list->next) { |
1474 | struct commit *c = list->item; | |
1475 | if (c->object.flags & (UNINTERESTING | TREESAME)) | |
1476 | continue; | |
1477 | update_treesame(revs, c); | |
1478 | } | |
db69bf60 | 1479 | } |
4d826608 | 1480 | |
db69bf60 | 1481 | free_commit_list(original_list); |
a4a88b2b | 1482 | revs->commits = newlist; |
cc0e6c5a | 1483 | return 0; |
a4a88b2b LT |
1484 | } |
1485 | ||
df835d3a MH |
1486 | /* |
1487 | * Add an entry to refs->cmdline with the specified information. | |
1488 | * *name is copied. | |
1489 | */ | |
281eee47 JH |
1490 | static void add_rev_cmdline(struct rev_info *revs, |
1491 | struct object *item, | |
1492 | const char *name, | |
1493 | int whence, | |
1494 | unsigned flags) | |
1495 | { | |
1496 | struct rev_cmdline_info *info = &revs->cmdline; | |
071bcaab | 1497 | unsigned int nr = info->nr; |
281eee47 JH |
1498 | |
1499 | ALLOC_GROW(info->rev, nr + 1, info->alloc); | |
1500 | info->rev[nr].item = item; | |
df835d3a | 1501 | info->rev[nr].name = xstrdup(name); |
281eee47 JH |
1502 | info->rev[nr].whence = whence; |
1503 | info->rev[nr].flags = flags; | |
1504 | info->nr++; | |
1505 | } | |
1506 | ||
a765499a KB |
1507 | static void add_rev_cmdline_list(struct rev_info *revs, |
1508 | struct commit_list *commit_list, | |
1509 | int whence, | |
1510 | unsigned flags) | |
1511 | { | |
1512 | while (commit_list) { | |
1513 | struct object *object = &commit_list->item->object; | |
f2fd0760 | 1514 | add_rev_cmdline(revs, object, oid_to_hex(&object->oid), |
a765499a KB |
1515 | whence, flags); |
1516 | commit_list = commit_list->next; | |
1517 | } | |
1518 | } | |
1519 | ||
63049292 JH |
1520 | struct all_refs_cb { |
1521 | int all_flags; | |
71b03b42 | 1522 | int warned_bad_reflog; |
63049292 JH |
1523 | struct rev_info *all_revs; |
1524 | const char *name_for_errormsg; | |
ab3e1f78 | 1525 | struct worktree *wt; |
63049292 | 1526 | }; |
ae563542 | 1527 | |
ff32d342 | 1528 | int ref_excluded(struct string_list *ref_excludes, const char *path) |
e7b432c5 JH |
1529 | { |
1530 | struct string_list_item *item; | |
1531 | ||
ff32d342 | 1532 | if (!ref_excludes) |
e7b432c5 | 1533 | return 0; |
ff32d342 | 1534 | for_each_string_list_item(item, ref_excludes) { |
55d34269 | 1535 | if (!wildmatch(item->string, path, 0)) |
e7b432c5 JH |
1536 | return 1; |
1537 | } | |
1538 | return 0; | |
1539 | } | |
1540 | ||
a217dcbd | 1541 | static int handle_one_ref(const char *path, const struct object_id *oid, |
5cf88fd8 | 1542 | int flag UNUSED, |
63e14ee2 | 1543 | void *cb_data) |
ae563542 | 1544 | { |
63049292 | 1545 | struct all_refs_cb *cb = cb_data; |
e7b432c5 JH |
1546 | struct object *object; |
1547 | ||
ff32d342 | 1548 | if (ref_excluded(cb->all_revs->ref_excludes, path)) |
e7b432c5 JH |
1549 | return 0; |
1550 | ||
654b9a90 | 1551 | object = get_reference(cb->all_revs, path, oid, cb->all_flags); |
281eee47 | 1552 | add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags); |
bf9c0cbd | 1553 | add_pending_object(cb->all_revs, object, path); |
ae563542 LT |
1554 | return 0; |
1555 | } | |
1556 | ||
d08bae7e IL |
1557 | static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs, |
1558 | unsigned flags) | |
1559 | { | |
1560 | cb->all_revs = revs; | |
1561 | cb->all_flags = flags; | |
7ba82629 | 1562 | revs->rev_input_given = 1; |
ab3e1f78 | 1563 | cb->wt = NULL; |
d08bae7e IL |
1564 | } |
1565 | ||
ff32d342 | 1566 | void clear_ref_exclusion(struct string_list **ref_excludes_p) |
e7b432c5 | 1567 | { |
ff32d342 JH |
1568 | if (*ref_excludes_p) { |
1569 | string_list_clear(*ref_excludes_p, 0); | |
1570 | free(*ref_excludes_p); | |
e7b432c5 | 1571 | } |
ff32d342 | 1572 | *ref_excludes_p = NULL; |
e7b432c5 JH |
1573 | } |
1574 | ||
ff32d342 | 1575 | void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude) |
e7b432c5 | 1576 | { |
ff32d342 | 1577 | if (!*ref_excludes_p) { |
ca56dadb | 1578 | CALLOC_ARRAY(*ref_excludes_p, 1); |
ff32d342 | 1579 | (*ref_excludes_p)->strdup_strings = 1; |
e7b432c5 | 1580 | } |
ff32d342 | 1581 | string_list_append(*ref_excludes_p, exclude); |
e7b432c5 JH |
1582 | } |
1583 | ||
073cf63c NTND |
1584 | static void handle_refs(struct ref_store *refs, |
1585 | struct rev_info *revs, unsigned flags, | |
1586 | int (*for_each)(struct ref_store *, each_ref_fn, void *)) | |
ae563542 | 1587 | { |
63049292 | 1588 | struct all_refs_cb cb; |
073cf63c NTND |
1589 | |
1590 | if (!refs) { | |
1591 | /* this could happen with uninitialized submodules */ | |
1592 | return; | |
1593 | } | |
1594 | ||
d08bae7e | 1595 | init_all_refs_cb(&cb, revs, flags); |
073cf63c | 1596 | for_each(refs, handle_one_ref, &cb); |
63049292 JH |
1597 | } |
1598 | ||
9461d272 | 1599 | static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) |
63049292 JH |
1600 | { |
1601 | struct all_refs_cb *cb = cb_data; | |
9461d272 | 1602 | if (!is_null_oid(oid)) { |
b3c7eef9 | 1603 | struct object *o = parse_object(cb->all_revs->repo, oid); |
71b03b42 SP |
1604 | if (o) { |
1605 | o->flags |= cb->all_flags; | |
281eee47 | 1606 | /* ??? CMDLINEFLAGS ??? */ |
71b03b42 SP |
1607 | add_pending_object(cb->all_revs, o, ""); |
1608 | } | |
1609 | else if (!cb->warned_bad_reflog) { | |
46efd2d9 | 1610 | warning("reflog of '%s' references pruned commits", |
71b03b42 SP |
1611 | cb->name_for_errormsg); |
1612 | cb->warned_bad_reflog = 1; | |
1613 | } | |
63049292 | 1614 | } |
71b03b42 SP |
1615 | } |
1616 | ||
9461d272 | 1617 | static int handle_one_reflog_ent(struct object_id *ooid, struct object_id *noid, |
5cf88fd8 ÆAB |
1618 | const char *email UNUSED, |
1619 | timestamp_t timestamp UNUSED, | |
1620 | int tz UNUSED, | |
1621 | const char *message UNUSED, | |
c006e9fa | 1622 | void *cb_data) |
71b03b42 | 1623 | { |
9461d272 | 1624 | handle_one_reflog_commit(ooid, cb_data); |
1625 | handle_one_reflog_commit(noid, cb_data); | |
63049292 JH |
1626 | return 0; |
1627 | } | |
1628 | ||
ab3e1f78 | 1629 | static int handle_one_reflog(const char *refname_in_wt, |
5cf88fd8 ÆAB |
1630 | const struct object_id *oid UNUSED, |
1631 | int flag UNUSED, void *cb_data) | |
63049292 JH |
1632 | { |
1633 | struct all_refs_cb *cb = cb_data; | |
ab3e1f78 NTND |
1634 | struct strbuf refname = STRBUF_INIT; |
1635 | ||
71b03b42 | 1636 | cb->warned_bad_reflog = 0; |
ab3e1f78 NTND |
1637 | strbuf_worktree_ref(cb->wt, &refname, refname_in_wt); |
1638 | cb->name_for_errormsg = refname.buf; | |
1639 | refs_for_each_reflog_ent(get_main_ref_store(the_repository), | |
1640 | refname.buf, | |
acd9544a | 1641 | handle_one_reflog_ent, cb_data); |
ab3e1f78 | 1642 | strbuf_release(&refname); |
63049292 JH |
1643 | return 0; |
1644 | } | |
1645 | ||
acd9544a NTND |
1646 | static void add_other_reflogs_to_pending(struct all_refs_cb *cb) |
1647 | { | |
1648 | struct worktree **worktrees, **p; | |
1649 | ||
03f2465b | 1650 | worktrees = get_worktrees(); |
acd9544a NTND |
1651 | for (p = worktrees; *p; p++) { |
1652 | struct worktree *wt = *p; | |
1653 | ||
1654 | if (wt->is_current) | |
1655 | continue; | |
1656 | ||
ab3e1f78 NTND |
1657 | cb->wt = wt; |
1658 | refs_for_each_reflog(get_worktree_ref_store(wt), | |
acd9544a NTND |
1659 | handle_one_reflog, |
1660 | cb); | |
1661 | } | |
1662 | free_worktrees(worktrees); | |
1663 | } | |
1664 | ||
718ccc97 | 1665 | void add_reflogs_to_pending(struct rev_info *revs, unsigned flags) |
63049292 JH |
1666 | { |
1667 | struct all_refs_cb cb; | |
2b2a5be3 | 1668 | |
63049292 JH |
1669 | cb.all_revs = revs; |
1670 | cb.all_flags = flags; | |
ab3e1f78 | 1671 | cb.wt = NULL; |
a89caf4b | 1672 | for_each_reflog(handle_one_reflog, &cb); |
acd9544a NTND |
1673 | |
1674 | if (!revs->single_worktree) | |
1675 | add_other_reflogs_to_pending(&cb); | |
ae563542 LT |
1676 | } |
1677 | ||
4fe10219 | 1678 | static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, |
b4cfcde4 | 1679 | struct strbuf *path, unsigned int flags) |
4fe10219 JK |
1680 | { |
1681 | size_t baselen = path->len; | |
1682 | int i; | |
1683 | ||
1684 | if (it->entry_count >= 0) { | |
b3c7eef9 | 1685 | struct tree *tree = lookup_tree(revs->repo, &it->oid); |
b4cfcde4 | 1686 | tree->object.flags |= flags; |
4fe10219 JK |
1687 | add_pending_object_with_path(revs, &tree->object, "", |
1688 | 040000, path->buf); | |
1689 | } | |
1690 | ||
1691 | for (i = 0; i < it->subtree_nr; i++) { | |
1692 | struct cache_tree_sub *sub = it->down[i]; | |
1693 | strbuf_addf(path, "%s%s", baselen ? "/" : "", sub->name); | |
b4cfcde4 | 1694 | add_cache_tree(sub->cache_tree, revs, path, flags); |
4fe10219 JK |
1695 | strbuf_setlen(path, baselen); |
1696 | } | |
1697 | ||
1698 | } | |
1699 | ||
5a5ea141 JH |
1700 | static void add_resolve_undo_to_pending(struct index_state *istate, struct rev_info *revs) |
1701 | { | |
1702 | struct string_list_item *item; | |
1703 | struct string_list *resolve_undo = istate->resolve_undo; | |
1704 | ||
1705 | if (!resolve_undo) | |
1706 | return; | |
1707 | ||
1708 | for_each_string_list_item(item, resolve_undo) { | |
1709 | const char *path = item->string; | |
1710 | struct resolve_undo_info *ru = item->util; | |
1711 | int i; | |
1712 | ||
1713 | if (!ru) | |
1714 | continue; | |
1715 | for (i = 0; i < 3; i++) { | |
1716 | struct blob *blob; | |
1717 | ||
1718 | if (!ru->mode[i] || !S_ISREG(ru->mode[i])) | |
1719 | continue; | |
1720 | ||
1721 | blob = lookup_blob(revs->repo, &ru->oid[i]); | |
1722 | if (!blob) { | |
1723 | warning(_("resolve-undo records `%s` which is missing"), | |
1724 | oid_to_hex(&ru->oid[i])); | |
1725 | continue; | |
1726 | } | |
1727 | add_pending_object_with_path(revs, &blob->object, "", | |
1728 | ru->mode[i], path); | |
1729 | } | |
1730 | } | |
1731 | } | |
1732 | ||
6c3d8181 | 1733 | static void do_add_index_objects_to_pending(struct rev_info *revs, |
b4cfcde4 JK |
1734 | struct index_state *istate, |
1735 | unsigned int flags) | |
4fe10219 JK |
1736 | { |
1737 | int i; | |
1738 | ||
f5fed74f DS |
1739 | /* TODO: audit for interaction with sparse-index. */ |
1740 | ensure_full_index(istate); | |
6c3d8181 NTND |
1741 | for (i = 0; i < istate->cache_nr; i++) { |
1742 | struct cache_entry *ce = istate->cache[i]; | |
4fe10219 JK |
1743 | struct blob *blob; |
1744 | ||
1745 | if (S_ISGITLINK(ce->ce_mode)) | |
1746 | continue; | |
1747 | ||
b3c7eef9 | 1748 | blob = lookup_blob(revs->repo, &ce->oid); |
4fe10219 JK |
1749 | if (!blob) |
1750 | die("unable to add index blob to traversal"); | |
b4cfcde4 | 1751 | blob->object.flags |= flags; |
4fe10219 JK |
1752 | add_pending_object_with_path(revs, &blob->object, "", |
1753 | ce->ce_mode, ce->name); | |
1754 | } | |
1755 | ||
6c3d8181 | 1756 | if (istate->cache_tree) { |
4fe10219 | 1757 | struct strbuf path = STRBUF_INIT; |
b4cfcde4 | 1758 | add_cache_tree(istate->cache_tree, revs, &path, flags); |
4fe10219 JK |
1759 | strbuf_release(&path); |
1760 | } | |
5a5ea141 JH |
1761 | |
1762 | add_resolve_undo_to_pending(istate, revs); | |
4fe10219 JK |
1763 | } |
1764 | ||
6c3d8181 NTND |
1765 | void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) |
1766 | { | |
be489d02 NTND |
1767 | struct worktree **worktrees, **p; |
1768 | ||
e1ff0a32 | 1769 | repo_read_index(revs->repo); |
b4cfcde4 | 1770 | do_add_index_objects_to_pending(revs, revs->repo->index, flags); |
be489d02 NTND |
1771 | |
1772 | if (revs->single_worktree) | |
1773 | return; | |
1774 | ||
03f2465b | 1775 | worktrees = get_worktrees(); |
be489d02 NTND |
1776 | for (p = worktrees; *p; p++) { |
1777 | struct worktree *wt = *p; | |
1778 | struct index_state istate = { NULL }; | |
1779 | ||
1780 | if (wt->is_current) | |
1781 | continue; /* current index already taken care of */ | |
1782 | ||
1783 | if (read_index_from(&istate, | |
a125a223 TG |
1784 | worktree_git_path(wt, "index"), |
1785 | get_worktree_git_dir(wt)) > 0) | |
b4cfcde4 | 1786 | do_add_index_objects_to_pending(revs, &istate, flags); |
be489d02 NTND |
1787 | discard_index(&istate); |
1788 | } | |
1789 | free_worktrees(worktrees); | |
6c3d8181 NTND |
1790 | } |
1791 | ||
39b44ba7 JK |
1792 | struct add_alternate_refs_data { |
1793 | struct rev_info *revs; | |
1794 | unsigned int flags; | |
1795 | }; | |
1796 | ||
1797 | static void add_one_alternate_ref(const struct object_id *oid, | |
1798 | void *vdata) | |
1799 | { | |
1800 | const char *name = ".alternate"; | |
1801 | struct add_alternate_refs_data *data = vdata; | |
1802 | struct object *obj; | |
1803 | ||
1804 | obj = get_reference(data->revs, name, oid, data->flags); | |
1805 | add_rev_cmdline(data->revs, obj, name, REV_CMD_REV, data->flags); | |
1806 | add_pending_object(data->revs, obj, name); | |
1807 | } | |
1808 | ||
1809 | static void add_alternate_refs_to_pending(struct rev_info *revs, | |
1810 | unsigned int flags) | |
1811 | { | |
1812 | struct add_alternate_refs_data data; | |
1813 | data.revs = revs; | |
1814 | data.flags = flags; | |
1815 | for_each_alternate_ref(add_one_alternate_ref, &data); | |
1816 | } | |
1817 | ||
8779351d VN |
1818 | static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, |
1819 | int exclude_parent) | |
ea4a19e1 | 1820 | { |
654b9a90 | 1821 | struct object_id oid; |
ea4a19e1 JH |
1822 | struct object *it; |
1823 | struct commit *commit; | |
1824 | struct commit_list *parents; | |
8779351d | 1825 | int parent_number; |
281eee47 | 1826 | const char *arg = arg_; |
ea4a19e1 JH |
1827 | |
1828 | if (*arg == '^') { | |
7f34a46f | 1829 | flags ^= UNINTERESTING | BOTTOM; |
ea4a19e1 JH |
1830 | arg++; |
1831 | } | |
e82caf38 | 1832 | if (get_oid_committish(arg, &oid)) |
ea4a19e1 JH |
1833 | return 0; |
1834 | while (1) { | |
654b9a90 | 1835 | it = get_reference(revs, arg, &oid, 0); |
cc243c3c JH |
1836 | if (!it && revs->ignore_missing) |
1837 | return 0; | |
1974632c | 1838 | if (it->type != OBJ_TAG) |
ea4a19e1 | 1839 | break; |
9684afd9 MK |
1840 | if (!((struct tag*)it)->tagged) |
1841 | return 0; | |
654b9a90 | 1842 | oidcpy(&oid, &((struct tag*)it)->tagged->oid); |
ea4a19e1 | 1843 | } |
1974632c | 1844 | if (it->type != OBJ_COMMIT) |
ea4a19e1 JH |
1845 | return 0; |
1846 | commit = (struct commit *)it; | |
8779351d VN |
1847 | if (exclude_parent && |
1848 | exclude_parent > commit_list_count(commit->parents)) | |
1849 | return 0; | |
1850 | for (parents = commit->parents, parent_number = 1; | |
1851 | parents; | |
1852 | parents = parents->next, parent_number++) { | |
1853 | if (exclude_parent && parent_number != exclude_parent) | |
1854 | continue; | |
1855 | ||
ea4a19e1 JH |
1856 | it = &parents->item->object; |
1857 | it->flags |= flags; | |
281eee47 | 1858 | add_rev_cmdline(revs, it, arg_, REV_CMD_PARENTS_ONLY, flags); |
ea4a19e1 JH |
1859 | add_pending_object(revs, it, arg); |
1860 | } | |
1861 | return 1; | |
1862 | } | |
1863 | ||
2abf3503 NTND |
1864 | void repo_init_revisions(struct repository *r, |
1865 | struct rev_info *revs, | |
1866 | const char *prefix) | |
8efdc326 FK |
1867 | { |
1868 | memset(revs, 0, sizeof(*revs)); | |
8e8f9987 | 1869 | |
2abf3503 | 1870 | revs->repo = r; |
6b9c58f4 | 1871 | revs->abbrev = DEFAULT_ABBREV; |
9202434c | 1872 | revs->simplify_history = 1; |
67022e02 | 1873 | revs->pruning.repo = r; |
0d1e0e78 BW |
1874 | revs->pruning.flags.recursive = 1; |
1875 | revs->pruning.flags.quick = 1; | |
cd2bdc53 LT |
1876 | revs->pruning.add_remove = file_add_remove; |
1877 | revs->pruning.change = file_change; | |
a937b37e | 1878 | revs->pruning.change_fn_data = revs; |
08f704f2 | 1879 | revs->sort_order = REV_SORT_IN_GRAPH_ORDER; |
8efdc326 | 1880 | revs->dense = 1; |
db6296a5 | 1881 | revs->prefix = prefix; |
8efdc326 | 1882 | revs->max_age = -1; |
96697781 | 1883 | revs->max_age_as_filter = -1; |
8efdc326 | 1884 | revs->min_age = -1; |
d5db6c9e | 1885 | revs->skip_count = -1; |
8efdc326 | 1886 | revs->max_count = -1; |
ad5aeede | 1887 | revs->max_parents = -1; |
0893eec8 | 1888 | revs->expand_tabs_in_log = -1; |
8efdc326 | 1889 | |
cd2bdc53 | 1890 | revs->commit_format = CMIT_FMT_DEFAULT; |
fe37a9c5 | 1891 | revs->expand_tabs_in_log_default = 8; |
cd2bdc53 | 1892 | |
9725c8dd | 1893 | grep_init(&revs->grep_filter, revs->repo); |
0843acfd | 1894 | revs->grep_filter.status_only = 1; |
0843acfd | 1895 | |
2abf3503 | 1896 | repo_diff_setup(revs->repo, &revs->diffopt); |
c0cb4a06 | 1897 | if (prefix && !revs->diffopt.prefix) { |
cd676a51 JH |
1898 | revs->diffopt.prefix = prefix; |
1899 | revs->diffopt.prefix_length = strlen(prefix); | |
1900 | } | |
3a03cf6b | 1901 | |
e6e230ee | 1902 | init_display_notes(&revs->notes_opt); |
2a01bded | 1903 | list_objects_filter_init(&revs->filter); |
8efdc326 FK |
1904 | } |
1905 | ||
0d2c9d67 | 1906 | static void add_pending_commit_list(struct rev_info *revs, |
ec36c42a NTND |
1907 | struct commit_list *commit_list, |
1908 | unsigned int flags) | |
0d2c9d67 RS |
1909 | { |
1910 | while (commit_list) { | |
1911 | struct object *object = &commit_list->item->object; | |
1912 | object->flags |= flags; | |
f2fd0760 | 1913 | add_pending_object(revs, object, oid_to_hex(&object->oid)); |
0d2c9d67 RS |
1914 | commit_list = commit_list->next; |
1915 | } | |
1916 | } | |
1917 | ||
ae3e5e1e JH |
1918 | static void prepare_show_merge(struct rev_info *revs) |
1919 | { | |
1920 | struct commit_list *bases; | |
1921 | struct commit *head, *other; | |
68ab61dd | 1922 | struct object_id oid; |
ae3e5e1e JH |
1923 | const char **prune = NULL; |
1924 | int i, prune_num = 1; /* counting terminating NULL */ | |
2abf3503 | 1925 | struct index_state *istate = revs->repo->index; |
ae3e5e1e | 1926 | |
68ab61dd | 1927 | if (get_oid("HEAD", &oid)) |
ae3e5e1e | 1928 | die("--merge without HEAD?"); |
bc83266a | 1929 | head = lookup_commit_or_die(&oid, "HEAD"); |
68ab61dd | 1930 | if (get_oid("MERGE_HEAD", &oid)) |
ae3e5e1e | 1931 | die("--merge without MERGE_HEAD?"); |
bc83266a | 1932 | other = lookup_commit_or_die(&oid, "MERGE_HEAD"); |
ae3e5e1e JH |
1933 | add_pending_object(revs, &head->object, "HEAD"); |
1934 | add_pending_object(revs, &other->object, "MERGE_HEAD"); | |
2ce406cc | 1935 | bases = get_merge_bases(head, other); |
7f34a46f KB |
1936 | add_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM); |
1937 | add_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM); | |
e82447b1 JH |
1938 | free_commit_list(bases); |
1939 | head->object.flags |= SYMMETRIC_LEFT; | |
ae3e5e1e | 1940 | |
2abf3503 | 1941 | if (!istate->cache_nr) |
e1ff0a32 | 1942 | repo_read_index(revs->repo); |
2abf3503 NTND |
1943 | for (i = 0; i < istate->cache_nr; i++) { |
1944 | const struct cache_entry *ce = istate->cache[i]; | |
ae3e5e1e JH |
1945 | if (!ce_stage(ce)) |
1946 | continue; | |
2abf3503 | 1947 | if (ce_path_match(istate, ce, &revs->prune_data, NULL)) { |
ae3e5e1e | 1948 | prune_num++; |
2756ca43 | 1949 | REALLOC_ARRAY(prune, prune_num); |
ae3e5e1e JH |
1950 | prune[prune_num-2] = ce->name; |
1951 | prune[prune_num-1] = NULL; | |
1952 | } | |
2abf3503 NTND |
1953 | while ((i+1 < istate->cache_nr) && |
1954 | ce_same_name(ce, istate->cache[i+1])) | |
ae3e5e1e JH |
1955 | i++; |
1956 | } | |
ed6e8038 | 1957 | clear_pathspec(&revs->prune_data); |
4a2d5ae2 | 1958 | parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL, |
c6f1b920 | 1959 | PATHSPEC_PREFER_FULL | PATHSPEC_LITERAL_PATH, "", prune); |
e82447b1 | 1960 | revs->limited = 1; |
ae3e5e1e JH |
1961 | } |
1962 | ||
62faad5a JK |
1963 | static int dotdot_missing(const char *arg, char *dotdot, |
1964 | struct rev_info *revs, int symmetric) | |
1965 | { | |
1966 | if (revs->ignore_missing) | |
1967 | return 0; | |
1968 | /* de-munge so we report the full argument */ | |
1969 | *dotdot = '.'; | |
1970 | die(symmetric | |
1971 | ? "Invalid symmetric difference expression %s" | |
1972 | : "Invalid revision range %s", arg); | |
1973 | } | |
1974 | ||
1975 | static int handle_dotdot_1(const char *arg, char *dotdot, | |
1976 | struct rev_info *revs, int flags, | |
18f1ad76 JK |
1977 | int cant_be_filename, |
1978 | struct object_context *a_oc, | |
1979 | struct object_context *b_oc) | |
62faad5a JK |
1980 | { |
1981 | const char *a_name, *b_name; | |
1982 | struct object_id a_oid, b_oid; | |
1983 | struct object *a_obj, *b_obj; | |
1984 | unsigned int a_flags, b_flags; | |
1985 | int symmetric = 0; | |
1986 | unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM); | |
321c89bf | 1987 | unsigned int oc_flags = GET_OID_COMMITTISH | GET_OID_RECORD_PATH; |
62faad5a JK |
1988 | |
1989 | a_name = arg; | |
1990 | if (!*a_name) | |
1991 | a_name = "HEAD"; | |
1992 | ||
1993 | b_name = dotdot + 2; | |
1994 | if (*b_name == '.') { | |
1995 | symmetric = 1; | |
1996 | b_name++; | |
1997 | } | |
1998 | if (!*b_name) | |
1999 | b_name = "HEAD"; | |
2000 | ||
3a7a698e NTND |
2001 | if (get_oid_with_context(revs->repo, a_name, oc_flags, &a_oid, a_oc) || |
2002 | get_oid_with_context(revs->repo, b_name, oc_flags, &b_oid, b_oc)) | |
62faad5a JK |
2003 | return -1; |
2004 | ||
2005 | if (!cant_be_filename) { | |
2006 | *dotdot = '.'; | |
2007 | verify_non_filename(revs->prefix, arg); | |
2008 | *dotdot = '\0'; | |
2009 | } | |
2010 | ||
b3c7eef9 NTND |
2011 | a_obj = parse_object(revs->repo, &a_oid); |
2012 | b_obj = parse_object(revs->repo, &b_oid); | |
62faad5a JK |
2013 | if (!a_obj || !b_obj) |
2014 | return dotdot_missing(arg, dotdot, revs, symmetric); | |
2015 | ||
2016 | if (!symmetric) { | |
2017 | /* just A..B */ | |
2018 | b_flags = flags; | |
2019 | a_flags = flags_exclude; | |
2020 | } else { | |
2021 | /* A...B -- find merge bases between the two */ | |
2022 | struct commit *a, *b; | |
2023 | struct commit_list *exclude; | |
2024 | ||
b3c7eef9 NTND |
2025 | a = lookup_commit_reference(revs->repo, &a_obj->oid); |
2026 | b = lookup_commit_reference(revs->repo, &b_obj->oid); | |
62faad5a JK |
2027 | if (!a || !b) |
2028 | return dotdot_missing(arg, dotdot, revs, symmetric); | |
2029 | ||
2030 | exclude = get_merge_bases(a, b); | |
2031 | add_rev_cmdline_list(revs, exclude, REV_CMD_MERGE_BASE, | |
2032 | flags_exclude); | |
2033 | add_pending_commit_list(revs, exclude, flags_exclude); | |
2034 | free_commit_list(exclude); | |
2035 | ||
2036 | b_flags = flags; | |
2037 | a_flags = flags | SYMMETRIC_LEFT; | |
2038 | } | |
2039 | ||
2040 | a_obj->flags |= a_flags; | |
2041 | b_obj->flags |= b_flags; | |
2042 | add_rev_cmdline(revs, a_obj, a_name, REV_CMD_LEFT, a_flags); | |
2043 | add_rev_cmdline(revs, b_obj, b_name, REV_CMD_RIGHT, b_flags); | |
18f1ad76 JK |
2044 | add_pending_object_with_path(revs, a_obj, a_name, a_oc->mode, a_oc->path); |
2045 | add_pending_object_with_path(revs, b_obj, b_name, b_oc->mode, b_oc->path); | |
62faad5a JK |
2046 | return 0; |
2047 | } | |
2048 | ||
2049 | static int handle_dotdot(const char *arg, | |
2050 | struct rev_info *revs, int flags, | |
2051 | int cant_be_filename) | |
2052 | { | |
18f1ad76 | 2053 | struct object_context a_oc, b_oc; |
62faad5a JK |
2054 | char *dotdot = strstr(arg, ".."); |
2055 | int ret; | |
2056 | ||
2057 | if (!dotdot) | |
2058 | return -1; | |
2059 | ||
18f1ad76 JK |
2060 | memset(&a_oc, 0, sizeof(a_oc)); |
2061 | memset(&b_oc, 0, sizeof(b_oc)); | |
2062 | ||
62faad5a | 2063 | *dotdot = '\0'; |
18f1ad76 JK |
2064 | ret = handle_dotdot_1(arg, dotdot, revs, flags, cant_be_filename, |
2065 | &a_oc, &b_oc); | |
62faad5a JK |
2066 | *dotdot = '.'; |
2067 | ||
18f1ad76 JK |
2068 | free(a_oc.path); |
2069 | free(b_oc.path); | |
2070 | ||
62faad5a JK |
2071 | return ret; |
2072 | } | |
2073 | ||
04a0e985 | 2074 | static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int flags, unsigned revarg_opt) |
5d6f0935 | 2075 | { |
249c8f4a | 2076 | struct object_context oc; |
f632dedd | 2077 | char *mark; |
5d6f0935 | 2078 | struct object *object; |
654b9a90 | 2079 | struct object_id oid; |
5d6f0935 | 2080 | int local_flags; |
281eee47 | 2081 | const char *arg = arg_; |
8e676e8b | 2082 | int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; |
321c89bf | 2083 | unsigned get_sha1_flags = GET_OID_RECORD_PATH; |
5d6f0935 | 2084 | |
7f34a46f KB |
2085 | flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM; |
2086 | ||
d89797fe JK |
2087 | if (!cant_be_filename && !strcmp(arg, "..")) { |
2088 | /* | |
2089 | * Just ".."? That is not a range but the | |
2090 | * pathspec for the parent directory. | |
2091 | */ | |
2092 | return -1; | |
5d6f0935 | 2093 | } |
8779351d | 2094 | |
62faad5a JK |
2095 | if (!handle_dotdot(arg, revs, flags, revarg_opt)) |
2096 | return 0; | |
8779351d | 2097 | |
f632dedd JK |
2098 | mark = strstr(arg, "^@"); |
2099 | if (mark && !mark[2]) { | |
2100 | *mark = 0; | |
8779351d | 2101 | if (add_parents_only(revs, arg, flags, 0)) |
5d6f0935 | 2102 | return 0; |
f632dedd | 2103 | *mark = '^'; |
5d6f0935 | 2104 | } |
f632dedd JK |
2105 | mark = strstr(arg, "^!"); |
2106 | if (mark && !mark[2]) { | |
2107 | *mark = 0; | |
8779351d | 2108 | if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), 0)) |
f632dedd | 2109 | *mark = '^'; |
8779351d | 2110 | } |
f632dedd JK |
2111 | mark = strstr(arg, "^-"); |
2112 | if (mark) { | |
8779351d VN |
2113 | int exclude_parent = 1; |
2114 | ||
f632dedd | 2115 | if (mark[2]) { |
8779351d | 2116 | char *end; |
f632dedd | 2117 | exclude_parent = strtoul(mark + 2, &end, 10); |
8779351d VN |
2118 | if (*end != '\0' || !exclude_parent) |
2119 | return -1; | |
2120 | } | |
2121 | ||
f632dedd | 2122 | *mark = 0; |
8779351d | 2123 | if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), exclude_parent)) |
f632dedd | 2124 | *mark = '^'; |
62476c8e JH |
2125 | } |
2126 | ||
5d6f0935 JH |
2127 | local_flags = 0; |
2128 | if (*arg == '^') { | |
7f34a46f | 2129 | local_flags = UNINTERESTING | BOTTOM; |
5d6f0935 JH |
2130 | arg++; |
2131 | } | |
d5f6b1d7 JH |
2132 | |
2133 | if (revarg_opt & REVARG_COMMITTISH) | |
321c89bf | 2134 | get_sha1_flags |= GET_OID_COMMITTISH; |
d5f6b1d7 | 2135 | |
3a7a698e | 2136 | if (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc)) |
cc243c3c | 2137 | return revs->ignore_missing ? 0 : -1; |
5d6f0935 JH |
2138 | if (!cant_be_filename) |
2139 | verify_non_filename(revs->prefix, arg); | |
654b9a90 | 2140 | object = get_reference(revs, arg, &oid, flags ^ local_flags); |
4cf67869 MD |
2141 | if (!object) |
2142 | return revs->ignore_missing ? 0 : -1; | |
281eee47 | 2143 | add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags); |
18f1ad76 JK |
2144 | add_pending_object_with_path(revs, object, arg, oc.mode, oc.path); |
2145 | free(oc.path); | |
5d6f0935 JH |
2146 | return 0; |
2147 | } | |
2148 | ||
04a0e985 JK |
2149 | int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt) |
2150 | { | |
2151 | int ret = handle_revision_arg_1(arg, revs, flags, revarg_opt); | |
2152 | if (!ret) | |
2153 | revs->rev_input_given = 1; | |
2154 | return ret; | |
2155 | } | |
2156 | ||
91633995 | 2157 | static void read_pathspec_from_stdin(struct strbuf *sb, |
c972bf4c | 2158 | struct strvec *prune) |
4da5af31 | 2159 | { |
7fa3c2ad | 2160 | while (strbuf_getline(sb, stdin) != EOF) |
c972bf4c | 2161 | strvec_push(prune, sb->buf); |
60da8b15 JH |
2162 | } |
2163 | ||
4da5af31 | 2164 | static void read_revisions_from_stdin(struct rev_info *revs, |
c972bf4c | 2165 | struct strvec *prune) |
1fc561d1 | 2166 | { |
63d564b3 | 2167 | struct strbuf sb; |
60da8b15 | 2168 | int seen_dashdash = 0; |
4c30d504 JK |
2169 | int save_warning; |
2170 | ||
2171 | save_warning = warn_on_object_refname_ambiguity; | |
2172 | warn_on_object_refname_ambiguity = 0; | |
1fc561d1 | 2173 | |
63d564b3 | 2174 | strbuf_init(&sb, 1000); |
6e8d46f9 | 2175 | while (strbuf_getline(&sb, stdin) != EOF) { |
63d564b3 | 2176 | int len = sb.len; |
1fc561d1 AB |
2177 | if (!len) |
2178 | break; | |
60da8b15 JH |
2179 | if (sb.buf[0] == '-') { |
2180 | if (len == 2 && sb.buf[1] == '-') { | |
2181 | seen_dashdash = 1; | |
2182 | break; | |
2183 | } | |
1fc561d1 | 2184 | die("options not supported in --stdin mode"); |
60da8b15 | 2185 | } |
31faeb20 | 2186 | if (handle_revision_arg(sb.buf, revs, 0, |
70d26c6e | 2187 | REVARG_CANNOT_BE_FILENAME)) |
63d564b3 | 2188 | die("bad revision '%s'", sb.buf); |
1fc561d1 | 2189 | } |
60da8b15 | 2190 | if (seen_dashdash) |
91633995 | 2191 | read_pathspec_from_stdin(&sb, prune); |
4c30d504 | 2192 | |
63d564b3 | 2193 | strbuf_release(&sb); |
4c30d504 | 2194 | warn_on_object_refname_ambiguity = save_warning; |
1fc561d1 AB |
2195 | } |
2196 | ||
2d10c555 | 2197 | static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what) |
bd95fcd3 | 2198 | { |
0843acfd | 2199 | append_grep_pattern(&revs->grep_filter, ptn, "command line", 0, what); |
2d10c555 JH |
2200 | } |
2201 | ||
a4d7d2c6 | 2202 | static void add_header_grep(struct rev_info *revs, enum grep_header_field field, const char *pattern) |
2d10c555 | 2203 | { |
a4d7d2c6 | 2204 | append_header_grep_pattern(&revs->grep_filter, field, pattern); |
bd95fcd3 JH |
2205 | } |
2206 | ||
2207 | static void add_message_grep(struct rev_info *revs, const char *pattern) | |
2208 | { | |
2d10c555 | 2209 | add_grep(revs, pattern, GREP_PATTERN_BODY); |
bd95fcd3 JH |
2210 | } |
2211 | ||
6b61ec05 | 2212 | static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv, |
bbcde41a MD |
2213 | int *unkc, const char **unkv, |
2214 | const struct setup_revision_opt* opt) | |
02e54220 PH |
2215 | { |
2216 | const char *arg = argv[0]; | |
257418c5 | 2217 | const char *optarg = NULL; |
7d7b86f7 | 2218 | int argcount; |
fd521245 | 2219 | const unsigned hexsz = the_hash_algo->hexsz; |
02e54220 PH |
2220 | |
2221 | /* pseudo revision arguments */ | |
2222 | if (!strcmp(arg, "--all") || !strcmp(arg, "--branches") || | |
2223 | !strcmp(arg, "--tags") || !strcmp(arg, "--remotes") || | |
2224 | !strcmp(arg, "--reflog") || !strcmp(arg, "--not") || | |
ad3f9a71 | 2225 | !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") || |
59556548 | 2226 | !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") || |
4fe10219 | 2227 | !strcmp(arg, "--indexed-objects") || |
39b44ba7 | 2228 | !strcmp(arg, "--alternate-refs") || |
07768e03 | 2229 | starts_with(arg, "--exclude=") || |
59556548 CC |
2230 | starts_with(arg, "--branches=") || starts_with(arg, "--tags=") || |
2231 | starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk=")) | |
02e54220 PH |
2232 | { |
2233 | unkv[(*unkc)++] = arg; | |
0fe8c138 | 2234 | return 1; |
02e54220 PH |
2235 | } |
2236 | ||
7d7b86f7 MM |
2237 | if ((argcount = parse_long_opt("max-count", argv, &optarg))) { |
2238 | revs->max_count = atoi(optarg); | |
5853caec | 2239 | revs->no_walk = 0; |
7d7b86f7 MM |
2240 | return argcount; |
2241 | } else if ((argcount = parse_long_opt("skip", argv, &optarg))) { | |
2242 | revs->skip_count = atoi(optarg); | |
2243 | return argcount; | |
02e54220 | 2244 | } else if ((*arg == '-') && isdigit(arg[1])) { |
e3fa568c JH |
2245 | /* accept -<digit>, like traditional "head" */ |
2246 | if (strtol_i(arg + 1, 10, &revs->max_count) < 0 || | |
2247 | revs->max_count < 0) | |
2248 | die("'%s': not a non-negative integer", arg + 1); | |
5853caec | 2249 | revs->no_walk = 0; |
02e54220 PH |
2250 | } else if (!strcmp(arg, "-n")) { |
2251 | if (argc <= 1) | |
2252 | return error("-n requires an argument"); | |
2253 | revs->max_count = atoi(argv[1]); | |
5853caec | 2254 | revs->no_walk = 0; |
02e54220 | 2255 | return 2; |
479b3d97 SG |
2256 | } else if (skip_prefix(arg, "-n", &optarg)) { |
2257 | revs->max_count = atoi(optarg); | |
5853caec | 2258 | revs->no_walk = 0; |
7d7b86f7 MM |
2259 | } else if ((argcount = parse_long_opt("max-age", argv, &optarg))) { |
2260 | revs->max_age = atoi(optarg); | |
2261 | return argcount; | |
2262 | } else if ((argcount = parse_long_opt("since", argv, &optarg))) { | |
2263 | revs->max_age = approxidate(optarg); | |
2264 | return argcount; | |
96697781 MV |
2265 | } else if ((argcount = parse_long_opt("since-as-filter", argv, &optarg))) { |
2266 | revs->max_age_as_filter = approxidate(optarg); | |
2267 | return argcount; | |
7d7b86f7 MM |
2268 | } else if ((argcount = parse_long_opt("after", argv, &optarg))) { |
2269 | revs->max_age = approxidate(optarg); | |
2270 | return argcount; | |
2271 | } else if ((argcount = parse_long_opt("min-age", argv, &optarg))) { | |
2272 | revs->min_age = atoi(optarg); | |
2273 | return argcount; | |
2274 | } else if ((argcount = parse_long_opt("before", argv, &optarg))) { | |
2275 | revs->min_age = approxidate(optarg); | |
2276 | return argcount; | |
2277 | } else if ((argcount = parse_long_opt("until", argv, &optarg))) { | |
2278 | revs->min_age = approxidate(optarg); | |
2279 | return argcount; | |
02e54220 PH |
2280 | } else if (!strcmp(arg, "--first-parent")) { |
2281 | revs->first_parent_only = 1; | |
9d505b7b JZ |
2282 | } else if (!strcmp(arg, "--exclude-first-parent-only")) { |
2283 | revs->exclude_first_parent_only = 1; | |
ebdc94f3 JH |
2284 | } else if (!strcmp(arg, "--ancestry-path")) { |
2285 | revs->ancestry_path = 1; | |
cb7529e1 | 2286 | revs->simplify_history = 0; |
ebdc94f3 | 2287 | revs->limited = 1; |
257418c5 EN |
2288 | revs->ancestry_path_implicit_bottoms = 1; |
2289 | } else if (skip_prefix(arg, "--ancestry-path=", &optarg)) { | |
2290 | struct commit *c; | |
2291 | struct object_id oid; | |
2292 | const char *msg = _("could not get commit for ancestry-path argument %s"); | |
2293 | ||
2294 | revs->ancestry_path = 1; | |
2295 | revs->simplify_history = 0; | |
2296 | revs->limited = 1; | |
2297 | ||
2298 | if (repo_get_oid_committish(revs->repo, optarg, &oid)) | |
2299 | return error(msg, optarg); | |
2300 | get_reference(revs, optarg, &oid, ANCESTRY_PATH); | |
2301 | c = lookup_commit_reference(revs->repo, &oid); | |
2302 | if (!c) | |
2303 | return error(msg, optarg); | |
2304 | commit_list_insert(c, &revs->ancestry_path_bottoms); | |
02e54220 PH |
2305 | } else if (!strcmp(arg, "-g") || !strcmp(arg, "--walk-reflogs")) { |
2306 | init_reflog_walk(&revs->reflog_info); | |
2307 | } else if (!strcmp(arg, "--default")) { | |
2308 | if (argc <= 1) | |
2309 | return error("bad --default argument"); | |
2310 | revs->def = argv[1]; | |
2311 | return 2; | |
2312 | } else if (!strcmp(arg, "--merge")) { | |
2313 | revs->show_merge = 1; | |
2314 | } else if (!strcmp(arg, "--topo-order")) { | |
08f704f2 | 2315 | revs->sort_order = REV_SORT_IN_GRAPH_ORDER; |
02e54220 | 2316 | revs->topo_order = 1; |
6546b593 JH |
2317 | } else if (!strcmp(arg, "--simplify-merges")) { |
2318 | revs->simplify_merges = 1; | |
a52f0071 | 2319 | revs->topo_order = 1; |
6546b593 JH |
2320 | revs->rewrite_parents = 1; |
2321 | revs->simplify_history = 0; | |
2322 | revs->limited = 1; | |
78892e32 LT |
2323 | } else if (!strcmp(arg, "--simplify-by-decoration")) { |
2324 | revs->simplify_merges = 1; | |
a52f0071 | 2325 | revs->topo_order = 1; |
78892e32 LT |
2326 | revs->rewrite_parents = 1; |
2327 | revs->simplify_history = 0; | |
2328 | revs->simplify_by_decoration = 1; | |
2329 | revs->limited = 1; | |
2330 | revs->prune = 1; | |
02e54220 | 2331 | } else if (!strcmp(arg, "--date-order")) { |
08f704f2 | 2332 | revs->sort_order = REV_SORT_BY_COMMIT_DATE; |
02e54220 | 2333 | revs->topo_order = 1; |
81c6b38b JH |
2334 | } else if (!strcmp(arg, "--author-date-order")) { |
2335 | revs->sort_order = REV_SORT_BY_AUTHOR_DATE; | |
02e54220 | 2336 | revs->topo_order = 1; |
dffc651e SG |
2337 | } else if (!strcmp(arg, "--early-output")) { |
2338 | revs->early_output = 100; | |
2339 | revs->topo_order = 1; | |
2340 | } else if (skip_prefix(arg, "--early-output=", &optarg)) { | |
2341 | if (strtoul_ui(optarg, 10, &revs->early_output) < 0) | |
2342 | die("'%s': not a non-negative integer", optarg); | |
2343 | revs->topo_order = 1; | |
02e54220 PH |
2344 | } else if (!strcmp(arg, "--parents")) { |
2345 | revs->rewrite_parents = 1; | |
2346 | revs->print_parents = 1; | |
2347 | } else if (!strcmp(arg, "--dense")) { | |
2348 | revs->dense = 1; | |
2349 | } else if (!strcmp(arg, "--sparse")) { | |
2350 | revs->dense = 0; | |
ce5b6f9b SB |
2351 | } else if (!strcmp(arg, "--in-commit-order")) { |
2352 | revs->tree_blobs_in_commit_order = 1; | |
02e54220 PH |
2353 | } else if (!strcmp(arg, "--remove-empty")) { |
2354 | revs->remove_empty_trees = 1; | |
b8e8db28 | 2355 | } else if (!strcmp(arg, "--merges")) { |
ad5aeede | 2356 | revs->min_parents = 2; |
02e54220 | 2357 | } else if (!strcmp(arg, "--no-merges")) { |
ad5aeede | 2358 | revs->max_parents = 1; |
479b3d97 SG |
2359 | } else if (skip_prefix(arg, "--min-parents=", &optarg)) { |
2360 | revs->min_parents = atoi(optarg); | |
9ada7aee | 2361 | } else if (!strcmp(arg, "--no-min-parents")) { |
ad5aeede | 2362 | revs->min_parents = 0; |
479b3d97 SG |
2363 | } else if (skip_prefix(arg, "--max-parents=", &optarg)) { |
2364 | revs->max_parents = atoi(optarg); | |
9ada7aee | 2365 | } else if (!strcmp(arg, "--no-max-parents")) { |
ad5aeede | 2366 | revs->max_parents = -1; |
02e54220 PH |
2367 | } else if (!strcmp(arg, "--boundary")) { |
2368 | revs->boundary = 1; | |
2369 | } else if (!strcmp(arg, "--left-right")) { | |
2370 | revs->left_right = 1; | |
60adf7d7 | 2371 | } else if (!strcmp(arg, "--left-only")) { |
24852d91 | 2372 | if (revs->right_only) |
94f605ec MG |
2373 | die("--left-only is incompatible with --right-only" |
2374 | " or --cherry"); | |
60adf7d7 MG |
2375 | revs->left_only = 1; |
2376 | } else if (!strcmp(arg, "--right-only")) { | |
24852d91 | 2377 | if (revs->left_only) |
12909b6b | 2378 | die(_("options '%s' and '%s' cannot be used together"), "--right-only", "--left-only"); |
60adf7d7 | 2379 | revs->right_only = 1; |
94f605ec MG |
2380 | } else if (!strcmp(arg, "--cherry")) { |
2381 | if (revs->left_only) | |
12909b6b | 2382 | die(_("options '%s' and '%s' cannot be used together"), "--cherry", "--left-only"); |
94f605ec MG |
2383 | revs->cherry_mark = 1; |
2384 | revs->right_only = 1; | |
ad5aeede | 2385 | revs->max_parents = 1; |
94f605ec | 2386 | revs->limited = 1; |
f69c5018 TR |
2387 | } else if (!strcmp(arg, "--count")) { |
2388 | revs->count = 1; | |
adbbb31e MG |
2389 | } else if (!strcmp(arg, "--cherry-mark")) { |
2390 | if (revs->cherry_pick) | |
12909b6b | 2391 | die(_("options '%s' and '%s' cannot be used together"), "--cherry-mark", "--cherry-pick"); |
adbbb31e MG |
2392 | revs->cherry_mark = 1; |
2393 | revs->limited = 1; /* needs limit_list() */ | |
02e54220 | 2394 | } else if (!strcmp(arg, "--cherry-pick")) { |
adbbb31e | 2395 | if (revs->cherry_mark) |
12909b6b | 2396 | die(_("options '%s' and '%s' cannot be used together"), "--cherry-pick", "--cherry-mark"); |
02e54220 PH |
2397 | revs->cherry_pick = 1; |
2398 | revs->limited = 1; | |
2399 | } else if (!strcmp(arg, "--objects")) { | |
2400 | revs->tag_objects = 1; | |
2401 | revs->tree_objects = 1; | |
2402 | revs->blob_objects = 1; | |
2403 | } else if (!strcmp(arg, "--objects-edge")) { | |
2404 | revs->tag_objects = 1; | |
2405 | revs->tree_objects = 1; | |
2406 | revs->blob_objects = 1; | |
2407 | revs->edge_hint = 1; | |
1684c1b2 | 2408 | } else if (!strcmp(arg, "--objects-edge-aggressive")) { |
2409 | revs->tag_objects = 1; | |
2410 | revs->tree_objects = 1; | |
2411 | revs->blob_objects = 1; | |
2412 | revs->edge_hint = 1; | |
2413 | revs->edge_hint_aggressive = 1; | |
5a48d240 JH |
2414 | } else if (!strcmp(arg, "--verify-objects")) { |
2415 | revs->tag_objects = 1; | |
2416 | revs->tree_objects = 1; | |
2417 | revs->blob_objects = 1; | |
2418 | revs->verify_objects = 1; | |
b27ccae3 | 2419 | disable_commit_graph(revs->repo); |
02e54220 PH |
2420 | } else if (!strcmp(arg, "--unpacked")) { |
2421 | revs->unpacked = 1; | |
59556548 | 2422 | } else if (starts_with(arg, "--unpacked=")) { |
f649aaaf | 2423 | die(_("--unpacked=<packfile> no longer supported")); |
c9fff000 TB |
2424 | } else if (!strcmp(arg, "--no-kept-objects")) { |
2425 | revs->no_kept_objects = 1; | |
2426 | revs->keep_pack_cache_flags |= IN_CORE_KEEP_PACKS; | |
2427 | revs->keep_pack_cache_flags |= ON_DISK_KEEP_PACKS; | |
2428 | } else if (skip_prefix(arg, "--no-kept-objects=", &optarg)) { | |
2429 | revs->no_kept_objects = 1; | |
2430 | if (!strcmp(optarg, "in-core")) | |
2431 | revs->keep_pack_cache_flags |= IN_CORE_KEEP_PACKS; | |
2432 | if (!strcmp(optarg, "on-disk")) | |
2433 | revs->keep_pack_cache_flags |= ON_DISK_KEEP_PACKS; | |
02e54220 PH |
2434 | } else if (!strcmp(arg, "-r")) { |
2435 | revs->diff = 1; | |
0d1e0e78 | 2436 | revs->diffopt.flags.recursive = 1; |
02e54220 PH |
2437 | } else if (!strcmp(arg, "-t")) { |
2438 | revs->diff = 1; | |
0d1e0e78 BW |
2439 | revs->diffopt.flags.recursive = 1; |
2440 | revs->diffopt.flags.tree_in_recursive = 1; | |
18f09473 | 2441 | } else if ((argcount = diff_merges_parse_opts(revs, argv))) { |
6501580f | 2442 | return argcount; |
02e54220 PH |
2443 | } else if (!strcmp(arg, "-v")) { |
2444 | revs->verbose_header = 1; | |
2445 | } else if (!strcmp(arg, "--pretty")) { | |
2446 | revs->verbose_header = 1; | |
66b2ed09 | 2447 | revs->pretty_given = 1; |
ae18165f | 2448 | get_commit_format(NULL, revs); |
479b3d97 SG |
2449 | } else if (skip_prefix(arg, "--pretty=", &optarg) || |
2450 | skip_prefix(arg, "--format=", &optarg)) { | |
7d7b86f7 MM |
2451 | /* |
2452 | * Detached form ("--pretty X" as opposed to "--pretty=X") | |
2453 | * not allowed, since the argument is optional. | |
2454 | */ | |
02e54220 | 2455 | revs->verbose_header = 1; |
66b2ed09 | 2456 | revs->pretty_given = 1; |
479b3d97 | 2457 | get_commit_format(optarg, revs); |
7cc13c71 | 2458 | } else if (!strcmp(arg, "--expand-tabs")) { |
fe37a9c5 | 2459 | revs->expand_tabs_in_log = 8; |
0893eec8 JH |
2460 | } else if (!strcmp(arg, "--no-expand-tabs")) { |
2461 | revs->expand_tabs_in_log = 0; | |
fe37a9c5 JH |
2462 | } else if (skip_prefix(arg, "--expand-tabs=", &arg)) { |
2463 | int val; | |
2464 | if (strtol_i(arg, 10, &val) < 0 || val < 0) | |
2465 | die("'%s': not a non-negative integer", arg); | |
2466 | revs->expand_tabs_in_log = val; | |
7249e912 | 2467 | } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { |
1d729751 | 2468 | enable_default_display_notes(&revs->notes_opt, &revs->show_notes); |
66b2ed09 | 2469 | revs->show_notes_given = 1; |
0c37f1fc JH |
2470 | } else if (!strcmp(arg, "--show-signature")) { |
2471 | revs->show_signature = 1; | |
aa379999 MJ |
2472 | } else if (!strcmp(arg, "--no-show-signature")) { |
2473 | revs->show_signature = 0; | |
479b3d97 SG |
2474 | } else if (!strcmp(arg, "--show-linear-break")) { |
2475 | revs->break_bar = " .........."; | |
1b32dece NTND |
2476 | revs->track_linear = 1; |
2477 | revs->track_first_time = 1; | |
479b3d97 SG |
2478 | } else if (skip_prefix(arg, "--show-linear-break=", &optarg)) { |
2479 | revs->break_bar = xstrdup(optarg); | |
1b32dece NTND |
2480 | revs->track_linear = 1; |
2481 | revs->track_first_time = 1; | |
479b3d97 SG |
2482 | } else if (skip_prefix(arg, "--show-notes=", &optarg) || |
2483 | skip_prefix(arg, "--notes=", &optarg)) { | |
479b3d97 SG |
2484 | if (starts_with(arg, "--show-notes=") && |
2485 | revs->notes_opt.use_default_notes < 0) | |
2486 | revs->notes_opt.use_default_notes = 1; | |
1d729751 | 2487 | enable_ref_display_notes(&revs->notes_opt, &revs->show_notes, optarg); |
452538c3 | 2488 | revs->show_notes_given = 1; |
66b2ed09 | 2489 | } else if (!strcmp(arg, "--no-notes")) { |
1d729751 | 2490 | disable_display_notes(&revs->notes_opt, &revs->show_notes); |
66b2ed09 | 2491 | revs->show_notes_given = 1; |
894a9d33 TR |
2492 | } else if (!strcmp(arg, "--standard-notes")) { |
2493 | revs->show_notes_given = 1; | |
3a03cf6b | 2494 | revs->notes_opt.use_default_notes = 1; |
894a9d33 | 2495 | } else if (!strcmp(arg, "--no-standard-notes")) { |
3a03cf6b | 2496 | revs->notes_opt.use_default_notes = 0; |
de84accc NS |
2497 | } else if (!strcmp(arg, "--oneline")) { |
2498 | revs->verbose_header = 1; | |
2499 | get_commit_format("oneline", revs); | |
7dccadf3 | 2500 | revs->pretty_given = 1; |
de84accc | 2501 | revs->abbrev_commit = 1; |
02e54220 | 2502 | } else if (!strcmp(arg, "--graph")) { |
dccf6c16 | 2503 | graph_clear(revs->graph); |
02e54220 | 2504 | revs->graph = graph_init(revs); |
087c7458 AH |
2505 | } else if (!strcmp(arg, "--no-graph")) { |
2506 | graph_clear(revs->graph); | |
2507 | revs->graph = NULL; | |
19d097e3 EB |
2508 | } else if (!strcmp(arg, "--encode-email-headers")) { |
2509 | revs->encode_email_headers = 1; | |
2510 | } else if (!strcmp(arg, "--no-encode-email-headers")) { | |
2511 | revs->encode_email_headers = 0; | |
02e54220 PH |
2512 | } else if (!strcmp(arg, "--root")) { |
2513 | revs->show_root_diff = 1; | |
2514 | } else if (!strcmp(arg, "--no-commit-id")) { | |
2515 | revs->no_commit_id = 1; | |
2516 | } else if (!strcmp(arg, "--always")) { | |
2517 | revs->always_show_header = 1; | |
2518 | } else if (!strcmp(arg, "--no-abbrev")) { | |
2519 | revs->abbrev = 0; | |
2520 | } else if (!strcmp(arg, "--abbrev")) { | |
2521 | revs->abbrev = DEFAULT_ABBREV; | |
479b3d97 SG |
2522 | } else if (skip_prefix(arg, "--abbrev=", &optarg)) { |
2523 | revs->abbrev = strtoul(optarg, NULL, 10); | |
02e54220 PH |
2524 | if (revs->abbrev < MINIMUM_ABBREV) |
2525 | revs->abbrev = MINIMUM_ABBREV; | |
fd521245 | 2526 | else if (revs->abbrev > hexsz) |
2527 | revs->abbrev = hexsz; | |
02e54220 PH |
2528 | } else if (!strcmp(arg, "--abbrev-commit")) { |
2529 | revs->abbrev_commit = 1; | |
0c47695a JS |
2530 | revs->abbrev_commit_given = 1; |
2531 | } else if (!strcmp(arg, "--no-abbrev-commit")) { | |
2532 | revs->abbrev_commit = 0; | |
02e54220 PH |
2533 | } else if (!strcmp(arg, "--full-diff")) { |
2534 | revs->diff = 1; | |
2535 | revs->full_diff = 1; | |
8d049e18 DS |
2536 | } else if (!strcmp(arg, "--show-pulls")) { |
2537 | revs->show_pulls = 1; | |
02e54220 PH |
2538 | } else if (!strcmp(arg, "--full-history")) { |
2539 | revs->simplify_history = 0; | |
2540 | } else if (!strcmp(arg, "--relative-date")) { | |
a5481a6c | 2541 | revs->date_mode.type = DATE_RELATIVE; |
f4ea32f0 | 2542 | revs->date_mode_explicit = 1; |
7d7b86f7 | 2543 | } else if ((argcount = parse_long_opt("date", argv, &optarg))) { |
a5481a6c | 2544 | parse_date_format(optarg, &revs->date_mode); |
f4ea32f0 | 2545 | revs->date_mode_explicit = 1; |
7d7b86f7 | 2546 | return argcount; |
02e54220 PH |
2547 | } else if (!strcmp(arg, "--log-size")) { |
2548 | revs->show_log_size = 1; | |
2549 | } | |
2550 | /* | |
2551 | * Grepping the commit log | |
2552 | */ | |
7d7b86f7 MM |
2553 | else if ((argcount = parse_long_opt("author", argv, &optarg))) { |
2554 | add_header_grep(revs, GREP_HEADER_AUTHOR, optarg); | |
2555 | return argcount; | |
2556 | } else if ((argcount = parse_long_opt("committer", argv, &optarg))) { | |
2557 | add_header_grep(revs, GREP_HEADER_COMMITTER, optarg); | |
2558 | return argcount; | |
72fd13f7 NTND |
2559 | } else if ((argcount = parse_long_opt("grep-reflog", argv, &optarg))) { |
2560 | add_header_grep(revs, GREP_HEADER_REFLOG, optarg); | |
2561 | return argcount; | |
7d7b86f7 MM |
2562 | } else if ((argcount = parse_long_opt("grep", argv, &optarg))) { |
2563 | add_message_grep(revs, optarg); | |
2564 | return argcount; | |
727b6fc3 | 2565 | } else if (!strcmp(arg, "--basic-regexp")) { |
8465541e | 2566 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_BRE; |
02e54220 | 2567 | } else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) { |
8465541e | 2568 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_ERE; |
02e54220 | 2569 | } else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) { |
9e3cbc59 | 2570 | revs->grep_filter.ignore_case = 1; |
c1ddc461 | 2571 | revs->diffopt.pickaxe_opts |= DIFF_PICKAXE_IGNORE_CASE; |
02e54220 | 2572 | } else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) { |
8465541e | 2573 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED; |
7531a2dd | 2574 | } else if (!strcmp(arg, "--perl-regexp") || !strcmp(arg, "-P")) { |
8465541e | 2575 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE; |
02e54220 | 2576 | } else if (!strcmp(arg, "--all-match")) { |
0843acfd | 2577 | revs->grep_filter.all_match = 1; |
22dfa8a2 | 2578 | } else if (!strcmp(arg, "--invert-grep")) { |
794c0002 | 2579 | revs->grep_filter.no_body_match = 1; |
7d7b86f7 MM |
2580 | } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) { |
2581 | if (strcmp(optarg, "none")) | |
2582 | git_log_output_encoding = xstrdup(optarg); | |
02e54220 PH |
2583 | else |
2584 | git_log_output_encoding = ""; | |
7d7b86f7 | 2585 | return argcount; |
02e54220 PH |
2586 | } else if (!strcmp(arg, "--reverse")) { |
2587 | revs->reverse ^= 1; | |
2588 | } else if (!strcmp(arg, "--children")) { | |
2589 | revs->children.name = "children"; | |
2590 | revs->limited = 1; | |
cc243c3c JH |
2591 | } else if (!strcmp(arg, "--ignore-missing")) { |
2592 | revs->ignore_missing = 1; | |
bbcde41a | 2593 | } else if (opt && opt->allow_exclude_promisor_objects && |
669b1d2a | 2594 | !strcmp(arg, "--exclude-promisor-objects")) { |
df11e196 | 2595 | if (fetch_if_missing) |
033abf97 | 2596 | BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0"); |
df11e196 | 2597 | revs->exclude_promisor_objects = 1; |
02e54220 | 2598 | } else { |
a97262c6 | 2599 | int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix); |
02e54220 PH |
2600 | if (!opts) |
2601 | unkv[(*unkc)++] = arg; | |
2602 | return opts; | |
2603 | } | |
2604 | ||
2605 | return 1; | |
2606 | } | |
2607 | ||
6b61ec05 PH |
2608 | void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, |
2609 | const struct option *options, | |
2610 | const char * const usagestr[]) | |
2611 | { | |
2612 | int n = handle_revision_opt(revs, ctx->argc, ctx->argv, | |
bbcde41a | 2613 | &ctx->cpidx, ctx->out, NULL); |
6b61ec05 PH |
2614 | if (n <= 0) { |
2615 | error("unknown option `%s'", ctx->argv[0]); | |
2616 | usage_with_options(usagestr, options); | |
2617 | } | |
2618 | ctx->argv += n; | |
2619 | ctx->argc -= n; | |
2620 | } | |
2621 | ||
087c7458 AH |
2622 | void revision_opts_finish(struct rev_info *revs) |
2623 | { | |
2624 | if (revs->graph && revs->track_linear) | |
2625 | die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph"); | |
2626 | ||
2627 | if (revs->graph) { | |
2628 | revs->topo_order = 1; | |
2629 | revs->rewrite_parents = 1; | |
2630 | } | |
2631 | } | |
2632 | ||
073cf63c NTND |
2633 | static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn, |
2634 | void *cb_data, const char *term) | |
2635 | { | |
cb46d630 AD |
2636 | struct strbuf bisect_refs = STRBUF_INIT; |
2637 | int status; | |
2638 | strbuf_addf(&bisect_refs, "refs/bisect/%s", term); | |
67985e4e | 2639 | status = refs_for_each_fullref_in(refs, bisect_refs.buf, fn, cb_data); |
cb46d630 AD |
2640 | strbuf_release(&bisect_refs); |
2641 | return status; | |
2642 | } | |
2643 | ||
073cf63c | 2644 | static int for_each_bad_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) |
ad3f9a71 | 2645 | { |
073cf63c | 2646 | return for_each_bisect_ref(refs, fn, cb_data, term_bad); |
ad3f9a71 LT |
2647 | } |
2648 | ||
073cf63c | 2649 | static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) |
ad3f9a71 | 2650 | { |
073cf63c | 2651 | return for_each_bisect_ref(refs, fn, cb_data, term_good); |
ad3f9a71 LT |
2652 | } |
2653 | ||
10a0d6ae | 2654 | static int handle_revision_pseudo_opt(struct rev_info *revs, |
e885a84f | 2655 | const char **argv, int *flags) |
f6aca0dc JN |
2656 | { |
2657 | const char *arg = argv[0]; | |
2658 | const char *optarg; | |
073cf63c | 2659 | struct ref_store *refs; |
f6aca0dc JN |
2660 | int argcount; |
2661 | ||
10a0d6ae | 2662 | if (revs->repo != the_repository) { |
d0c39a49 NTND |
2663 | /* |
2664 | * We need some something like get_submodule_worktrees() | |
2665 | * before we can go through all worktrees of a submodule, | |
2666 | * .e.g with adding all HEADs from --all, which is not | |
2667 | * supported right now, so stick to single worktree. | |
2668 | */ | |
2669 | if (!revs->single_worktree) | |
033abf97 | 2670 | BUG("--single-worktree cannot be used together with submodule"); |
10a0d6ae JT |
2671 | } |
2672 | refs = get_main_ref_store(revs->repo); | |
073cf63c | 2673 | |
0fc63ec4 JN |
2674 | /* |
2675 | * NOTE! | |
2676 | * | |
2677 | * Commands like "git shortlog" will not accept the options below | |
2678 | * unless parse_revision_opt queues them (as opposed to erroring | |
2679 | * out). | |
2680 | * | |
2681 | * When implementing your new pseudo-option, remember to | |
2682 | * register it in the list at the top of handle_revision_opt. | |
2683 | */ | |
f6aca0dc | 2684 | if (!strcmp(arg, "--all")) { |
073cf63c NTND |
2685 | handle_refs(refs, revs, *flags, refs_for_each_ref); |
2686 | handle_refs(refs, revs, *flags, refs_head_ref); | |
d0c39a49 NTND |
2687 | if (!revs->single_worktree) { |
2688 | struct all_refs_cb cb; | |
2689 | ||
2690 | init_all_refs_cb(&cb, revs, *flags); | |
2691 | other_head_refs(handle_one_ref, &cb); | |
2692 | } | |
ff32d342 | 2693 | clear_ref_exclusion(&revs->ref_excludes); |
f6aca0dc | 2694 | } else if (!strcmp(arg, "--branches")) { |
073cf63c | 2695 | handle_refs(refs, revs, *flags, refs_for_each_branch_ref); |
ff32d342 | 2696 | clear_ref_exclusion(&revs->ref_excludes); |
f6aca0dc | 2697 | } else if (!strcmp(arg, "--bisect")) { |
cb46d630 | 2698 | read_bisect_terms(&term_bad, &term_good); |
073cf63c NTND |
2699 | handle_refs(refs, revs, *flags, for_each_bad_bisect_ref); |
2700 | handle_refs(refs, revs, *flags ^ (UNINTERESTING | BOTTOM), | |
2701 | for_each_good_bisect_ref); | |
f6aca0dc JN |
2702 | revs->bisect = 1; |
2703 | } else if (!strcmp(arg, "--tags")) { | |
073cf63c | 2704 | handle_refs(refs, revs, *flags, refs_for_each_tag_ref); |
ff32d342 | 2705 | clear_ref_exclusion(&revs->ref_excludes); |
f6aca0dc | 2706 | } else if (!strcmp(arg, "--remotes")) { |
073cf63c | 2707 | handle_refs(refs, revs, *flags, refs_for_each_remote_ref); |
ff32d342 | 2708 | clear_ref_exclusion(&revs->ref_excludes); |
f6aca0dc JN |
2709 | } else if ((argcount = parse_long_opt("glob", argv, &optarg))) { |
2710 | struct all_refs_cb cb; | |
2711 | init_all_refs_cb(&cb, revs, *flags); | |
a217dcbd | 2712 | for_each_glob_ref(handle_one_ref, optarg, &cb); |
ff32d342 | 2713 | clear_ref_exclusion(&revs->ref_excludes); |
e7b432c5 JH |
2714 | return argcount; |
2715 | } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) { | |
ff32d342 | 2716 | add_ref_exclusion(&revs->ref_excludes, optarg); |
f6aca0dc | 2717 | return argcount; |
8b1d9136 | 2718 | } else if (skip_prefix(arg, "--branches=", &optarg)) { |
f6aca0dc JN |
2719 | struct all_refs_cb cb; |
2720 | init_all_refs_cb(&cb, revs, *flags); | |
8b1d9136 | 2721 | for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb); |
ff32d342 | 2722 | clear_ref_exclusion(&revs->ref_excludes); |
8b1d9136 | 2723 | } else if (skip_prefix(arg, "--tags=", &optarg)) { |
f6aca0dc JN |
2724 | struct all_refs_cb cb; |
2725 | init_all_refs_cb(&cb, revs, *flags); | |
8b1d9136 | 2726 | for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb); |
ff32d342 | 2727 | clear_ref_exclusion(&revs->ref_excludes); |
8b1d9136 | 2728 | } else if (skip_prefix(arg, "--remotes=", &optarg)) { |
f6aca0dc JN |
2729 | struct all_refs_cb cb; |
2730 | init_all_refs_cb(&cb, revs, *flags); | |
8b1d9136 | 2731 | for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb); |
ff32d342 | 2732 | clear_ref_exclusion(&revs->ref_excludes); |
f6aca0dc | 2733 | } else if (!strcmp(arg, "--reflog")) { |
718ccc97 | 2734 | add_reflogs_to_pending(revs, *flags); |
4fe10219 JK |
2735 | } else if (!strcmp(arg, "--indexed-objects")) { |
2736 | add_index_objects_to_pending(revs, *flags); | |
39b44ba7 JK |
2737 | } else if (!strcmp(arg, "--alternate-refs")) { |
2738 | add_alternate_refs_to_pending(revs, *flags); | |
f6aca0dc | 2739 | } else if (!strcmp(arg, "--not")) { |
7f34a46f | 2740 | *flags ^= UNINTERESTING | BOTTOM; |
f6aca0dc | 2741 | } else if (!strcmp(arg, "--no-walk")) { |
29ef1f27 | 2742 | revs->no_walk = 1; |
8b1d9136 | 2743 | } else if (skip_prefix(arg, "--no-walk=", &optarg)) { |
ca92e59e MZ |
2744 | /* |
2745 | * Detached form ("--no-walk X" as opposed to "--no-walk=X") | |
2746 | * not allowed, since the argument is optional. | |
2747 | */ | |
29ef1f27 | 2748 | revs->no_walk = 1; |
8b1d9136 | 2749 | if (!strcmp(optarg, "sorted")) |
29ef1f27 | 2750 | revs->unsorted_input = 0; |
8b1d9136 | 2751 | else if (!strcmp(optarg, "unsorted")) |
29ef1f27 | 2752 | revs->unsorted_input = 1; |
ca92e59e MZ |
2753 | else |
2754 | return error("invalid argument to --no-walk"); | |
f6aca0dc JN |
2755 | } else if (!strcmp(arg, "--do-walk")) { |
2756 | revs->no_walk = 0; | |
32619f99 NTND |
2757 | } else if (!strcmp(arg, "--single-worktree")) { |
2758 | revs->single_worktree = 1; | |
cc910442 | 2759 | } else if (skip_prefix(arg, ("--filter="), &arg)) { |
c4ea513f | 2760 | parse_list_objects_filter(&revs->filter, arg); |
cc910442 | 2761 | } else if (!strcmp(arg, ("--no-filter"))) { |
c4ea513f | 2762 | list_objects_filter_set_no_filter(&revs->filter); |
f6aca0dc JN |
2763 | } else { |
2764 | return 0; | |
2765 | } | |
2766 | ||
2767 | return 1; | |
2768 | } | |
2769 | ||
ce113604 JK |
2770 | static void NORETURN diagnose_missing_default(const char *def) |
2771 | { | |
ce113604 JK |
2772 | int flags; |
2773 | const char *refname; | |
2774 | ||
744c040b | 2775 | refname = resolve_ref_unsafe(def, 0, NULL, &flags); |
ce113604 JK |
2776 | if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN)) |
2777 | die(_("your current branch appears to be broken")); | |
2778 | ||
2779 | skip_prefix(refname, "refs/heads/", &refname); | |
2780 | die(_("your current branch '%s' does not have any commits yet"), | |
2781 | refname); | |
2782 | } | |
2783 | ||
ae563542 LT |
2784 | /* |
2785 | * Parse revision information, filling in the "rev_info" structure, | |
2786 | * and removing the used arguments from the argument list. | |
2787 | * | |
765ac8ec LT |
2788 | * Returns the number of arguments left that weren't recognized |
2789 | * (which are also moved to the head of the argument list) | |
ae563542 | 2790 | */ |
32962c9b | 2791 | int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt) |
ae563542 | 2792 | { |
04a0e985 | 2793 | int i, flags, left, seen_dashdash, revarg_opt; |
c972bf4c | 2794 | struct strvec prune_data = STRVEC_INIT; |
19e8789b | 2795 | int seen_end_of_options = 0; |
9ef6aeb0 | 2796 | |
ae563542 | 2797 | /* First, search for "--" */ |
6d5b93f2 | 2798 | if (opt && opt->assume_dashdash) { |
ae563542 | 2799 | seen_dashdash = 1; |
6d5b93f2 CB |
2800 | } else { |
2801 | seen_dashdash = 0; | |
2802 | for (i = 1; i < argc; i++) { | |
2803 | const char *arg = argv[i]; | |
2804 | if (strcmp(arg, "--")) | |
2805 | continue; | |
f92dbdbc ÆAB |
2806 | if (opt && opt->free_removed_argv_elements) |
2807 | free((char *)argv[i]); | |
6d5b93f2 CB |
2808 | argv[i] = NULL; |
2809 | argc = i; | |
2810 | if (argv[i + 1]) | |
c972bf4c | 2811 | strvec_pushv(&prune_data, argv + i + 1); |
6d5b93f2 CB |
2812 | seen_dashdash = 1; |
2813 | break; | |
2814 | } | |
ae563542 LT |
2815 | } |
2816 | ||
02e54220 PH |
2817 | /* Second, deal with arguments and options */ |
2818 | flags = 0; | |
d5f6b1d7 JH |
2819 | revarg_opt = opt ? opt->revarg_opt : 0; |
2820 | if (seen_dashdash) | |
2821 | revarg_opt |= REVARG_CANNOT_BE_FILENAME; | |
02e54220 | 2822 | for (left = i = 1; i < argc; i++) { |
ae563542 | 2823 | const char *arg = argv[i]; |
19e8789b | 2824 | if (!seen_end_of_options && *arg == '-') { |
cd2bdc53 | 2825 | int opts; |
02e54220 | 2826 | |
10a0d6ae | 2827 | opts = handle_revision_pseudo_opt( |
e885a84f | 2828 | revs, argv + i, |
f6aca0dc JN |
2829 | &flags); |
2830 | if (opts > 0) { | |
2831 | i += opts - 1; | |
8e64006e JS |
2832 | continue; |
2833 | } | |
f6aca0dc | 2834 | |
8b3dce56 JH |
2835 | if (!strcmp(arg, "--stdin")) { |
2836 | if (revs->disable_stdin) { | |
2837 | argv[left++] = arg; | |
2838 | continue; | |
2839 | } | |
a12cbe23 | 2840 | if (revs->read_from_stdin++) |
8b3dce56 | 2841 | die("--stdin given twice?"); |
60da8b15 | 2842 | read_revisions_from_stdin(revs, &prune_data); |
8b3dce56 JH |
2843 | continue; |
2844 | } | |
2d10c555 | 2845 | |
19e8789b JK |
2846 | if (!strcmp(arg, "--end-of-options")) { |
2847 | seen_end_of_options = 1; | |
2848 | continue; | |
2849 | } | |
2850 | ||
bbcde41a MD |
2851 | opts = handle_revision_opt(revs, argc - i, argv + i, |
2852 | &left, argv, opt); | |
cd2bdc53 | 2853 | if (opts > 0) { |
cd2bdc53 LT |
2854 | i += opts - 1; |
2855 | continue; | |
2856 | } | |
02e54220 PH |
2857 | if (opts < 0) |
2858 | exit(128); | |
ae563542 LT |
2859 | continue; |
2860 | } | |
ae563542 | 2861 | |
8e676e8b JH |
2862 | |
2863 | if (handle_revision_arg(arg, revs, flags, revarg_opt)) { | |
5d6f0935 JH |
2864 | int j; |
2865 | if (seen_dashdash || *arg == '^') | |
ae563542 LT |
2866 | die("bad revision '%s'", arg); |
2867 | ||
ea92f41f JH |
2868 | /* If we didn't have a "--": |
2869 | * (1) all filenames must exist; | |
2870 | * (2) all rev-args must not be interpretable | |
2871 | * as a valid filename. | |
2872 | * but the latter we have checked in the main loop. | |
2873 | */ | |
e23d0b4a | 2874 | for (j = i; j < argc; j++) |
023e37c3 | 2875 | verify_filename(revs->prefix, argv[j], j == i); |
e23d0b4a | 2876 | |
c972bf4c | 2877 | strvec_pushv(&prune_data, argv + i); |
ae563542 LT |
2878 | break; |
2879 | } | |
ae563542 | 2880 | } |
087c7458 | 2881 | revision_opts_finish(revs); |
5d6f0935 | 2882 | |
d70a9eb6 | 2883 | if (prune_data.nr) { |
93e7d672 JH |
2884 | /* |
2885 | * If we need to introduce the magic "a lone ':' means no | |
2886 | * pathspec whatsoever", here is the place to do so. | |
2887 | * | |
2888 | * if (prune_data.nr == 1 && !strcmp(prune_data[0], ":")) { | |
2889 | * prune_data.nr = 0; | |
2890 | * prune_data.alloc = 0; | |
2891 | * free(prune_data.path); | |
2892 | * prune_data.path = NULL; | |
2893 | * } else { | |
2894 | * terminate prune_data.alloc with NULL and | |
2895 | * call init_pathspec() to set revs->prune_data here. | |
2896 | * } | |
2897 | */ | |
0fdc2ae5 | 2898 | parse_pathspec(&revs->prune_data, 0, 0, |
d70a9eb6 | 2899 | revs->prefix, prune_data.v); |
4da5af31 | 2900 | } |
c972bf4c | 2901 | strvec_clear(&prune_data); |
5486ef0e | 2902 | |
afe8a907 | 2903 | if (!revs->def) |
32962c9b | 2904 | revs->def = opt ? opt->def : NULL; |
b4490059 JH |
2905 | if (opt && opt->tweak) |
2906 | opt->tweak(revs, opt); | |
02e54220 | 2907 | if (revs->show_merge) |
ae3e5e1e | 2908 | prepare_show_merge(revs); |
04a0e985 | 2909 | if (revs->def && !revs->pending.nr && !revs->rev_input_given) { |
654b9a90 | 2910 | struct object_id oid; |
cd2bdc53 | 2911 | struct object *object; |
249c8f4a | 2912 | struct object_context oc; |
3a7a698e | 2913 | if (get_oid_with_context(revs->repo, revs->def, 0, &oid, &oc)) |
ce113604 | 2914 | diagnose_missing_default(revs->def); |
654b9a90 | 2915 | object = get_reference(revs, revs->def, &oid, 0); |
249c8f4a | 2916 | add_pending_object_with_mode(revs, object, revs->def, oc.mode); |
ae563542 | 2917 | } |
8efdc326 | 2918 | |
b7bb760d LT |
2919 | /* Did the user ask for any diff output? Run the diff! */ |
2920 | if (revs->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) | |
2921 | revs->diff = 1; | |
2922 | ||
0faf2da7 | 2923 | /* Pickaxe, diff-filter and rename following need diffs */ |
cf63051a | 2924 | if ((revs->diffopt.pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) || |
0faf2da7 | 2925 | revs->diffopt.filter || |
0d1e0e78 | 2926 | revs->diffopt.flags.follow_renames) |
b7bb760d LT |
2927 | revs->diff = 1; |
2928 | ||
15af58c1 SB |
2929 | if (revs->diffopt.objfind) |
2930 | revs->simplify_history = 0; | |
2931 | ||
002933f3 SG |
2932 | if (revs->line_level_traverse) { |
2933 | if (want_ancestry(revs)) | |
2934 | revs->limited = 1; | |
2935 | revs->topo_order = 1; | |
2936 | } | |
2937 | ||
f0d9cc41 | 2938 | if (revs->topo_order && !generation_numbers_enabled(the_repository)) |
53069686 JH |
2939 | revs->limited = 1; |
2940 | ||
afe069d1 | 2941 | if (revs->prune_data.nr) { |
bd1928df | 2942 | copy_pathspec(&revs->pruning.pathspec, &revs->prune_data); |
750f7b66 | 2943 | /* Can't prune commits with rename following: the paths change.. */ |
0d1e0e78 | 2944 | if (!revs->diffopt.flags.follow_renames) |
53b2c823 | 2945 | revs->prune = 1; |
cd2bdc53 | 2946 | if (!revs->full_diff) |
bd1928df NTND |
2947 | copy_pathspec(&revs->diffopt.pathspec, |
2948 | &revs->prune_data); | |
8efdc326 | 2949 | } |
299a6634 | 2950 | |
18f09473 | 2951 | diff_merges_setup_revs(revs); |
d76ce4f7 | 2952 | |
cd2bdc53 | 2953 | revs->diffopt.abbrev = revs->abbrev; |
12da1d1f | 2954 | |
28452655 | 2955 | diff_setup_done(&revs->diffopt); |
8efdc326 | 2956 | |
44570188 ÆAB |
2957 | if (!is_encoding_utf8(get_log_output_encoding())) |
2958 | revs->grep_filter.ignore_locale = 1; | |
0843acfd | 2959 | compile_grep_patterns(&revs->grep_filter); |
bd95fcd3 | 2960 | |
d56651c0 | 2961 | if (revs->reverse && revs->reflog_info) |
12909b6b | 2962 | die(_("options '%s' and '%s' cannot be used together"), "--reverse", "--walk-reflogs"); |
82fd0f4a JK |
2963 | if (revs->reflog_info && revs->limited) |
2964 | die("cannot combine --walk-reflogs with history-limiting options"); | |
8bb65883 | 2965 | if (revs->rewrite_parents && revs->children.name) |
12909b6b | 2966 | die(_("options '%s' and '%s' cannot be used together"), "--parents", "--children"); |
c4ea513f DS |
2967 | if (revs->filter.choice && !revs->blob_objects) |
2968 | die(_("object filtering requires --objects")); | |
d56651c0 | 2969 | |
7fefda5c AS |
2970 | /* |
2971 | * Limitations on the graph functionality | |
2972 | */ | |
2973 | if (revs->reverse && revs->graph) | |
12909b6b | 2974 | die(_("options '%s' and '%s' cannot be used together"), "--reverse", "--graph"); |
7fefda5c AS |
2975 | |
2976 | if (revs->reflog_info && revs->graph) | |
12909b6b | 2977 | die(_("options '%s' and '%s' cannot be used together"), "--walk-reflogs", "--graph"); |
695985f4 | 2978 | if (revs->no_walk && revs->graph) |
12909b6b | 2979 | die(_("options '%s' and '%s' cannot be used together"), "--no-walk", "--graph"); |
baa6378f | 2980 | if (!revs->reflog_info && revs->grep_filter.use_reflog_filter) |
6fa00ee8 | 2981 | die(_("the option '%s' requires '%s'"), "--grep-reflog", "--walk-reflogs"); |
7fefda5c | 2982 | |
05314efa JK |
2983 | if (revs->line_level_traverse && |
2984 | (revs->diffopt.output_format & ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT))) | |
2985 | die(_("-L does not yet support diff formats besides -p and -s")); | |
2986 | ||
0893eec8 JH |
2987 | if (revs->expand_tabs_in_log < 0) |
2988 | revs->expand_tabs_in_log = revs->expand_tabs_in_log_default; | |
2989 | ||
ae563542 LT |
2990 | return left; |
2991 | } | |
a4a88b2b | 2992 | |
7a98d9ab ÆAB |
2993 | static void release_revisions_cmdline(struct rev_cmdline_info *cmdline) |
2994 | { | |
2995 | unsigned int i; | |
2996 | ||
2997 | for (i = 0; i < cmdline->nr; i++) | |
2998 | free((char *)cmdline->rev[i].name); | |
2999 | free(cmdline->rev); | |
3000 | } | |
3001 | ||
a52f07af ÆAB |
3002 | static void release_revisions_mailmap(struct string_list *mailmap) |
3003 | { | |
3004 | if (!mailmap) | |
3005 | return; | |
3006 | clear_mailmap(mailmap); | |
3007 | free(mailmap); | |
3008 | } | |
3009 | ||
ae1b383d ÆAB |
3010 | static void release_revisions_topo_walk_info(struct topo_walk_info *info); |
3011 | ||
1878b5ed ÆAB |
3012 | void release_revisions(struct rev_info *revs) |
3013 | { | |
e966fc5a | 3014 | free_commit_list(revs->commits); |
257418c5 | 3015 | free_commit_list(revs->ancestry_path_bottoms); |
1878b5ed | 3016 | object_array_clear(&revs->pending); |
ab1f6926 | 3017 | object_array_clear(&revs->boundary_commits); |
7a98d9ab | 3018 | release_revisions_cmdline(&revs->cmdline); |
e75d2f7f | 3019 | list_objects_filter_release(&revs->filter); |
689a8e80 | 3020 | clear_pathspec(&revs->prune_data); |
9d5a7df3 | 3021 | date_mode_release(&revs->date_mode); |
a52f07af | 3022 | release_revisions_mailmap(revs->mailmap); |
f41fb662 | 3023 | free_grep_patterns(&revs->grep_filter); |
54c8a7c3 | 3024 | /* TODO (need to handle "no_free"): diff_free(&revs->diffopt) */ |
6ab75ac8 | 3025 | diff_free(&revs->pruning); |
81ffbf83 | 3026 | reflog_walk_info_release(revs->reflog_info); |
ae1b383d | 3027 | release_revisions_topo_walk_info(revs->topo_walk_info); |
1878b5ed ÆAB |
3028 | } |
3029 | ||
f35f5603 JH |
3030 | static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child) |
3031 | { | |
3032 | struct commit_list *l = xcalloc(1, sizeof(*l)); | |
3033 | ||
3034 | l->item = child; | |
3035 | l->next = add_decoration(&revs->children, &parent->object, l); | |
3036 | } | |
3037 | ||
d0af663e | 3038 | static int remove_duplicate_parents(struct rev_info *revs, struct commit *commit) |
6546b593 | 3039 | { |
d0af663e | 3040 | struct treesame_state *ts = lookup_decoration(&revs->treesame, &commit->object); |
6546b593 JH |
3041 | struct commit_list **pp, *p; |
3042 | int surviving_parents; | |
3043 | ||
3044 | /* Examine existing parents while marking ones we have seen... */ | |
3045 | pp = &commit->parents; | |
d0af663e | 3046 | surviving_parents = 0; |
6546b593 JH |
3047 | while ((p = *pp) != NULL) { |
3048 | struct commit *parent = p->item; | |
3049 | if (parent->object.flags & TMP_MARK) { | |
3050 | *pp = p->next; | |
d0af663e KB |
3051 | if (ts) |
3052 | compact_treesame(revs, commit, surviving_parents); | |
6546b593 JH |
3053 | continue; |
3054 | } | |
3055 | parent->object.flags |= TMP_MARK; | |
d0af663e | 3056 | surviving_parents++; |
6546b593 JH |
3057 | pp = &p->next; |
3058 | } | |
d0af663e | 3059 | /* clear the temporary mark */ |
6546b593 JH |
3060 | for (p = commit->parents; p; p = p->next) { |
3061 | p->item->object.flags &= ~TMP_MARK; | |
6546b593 | 3062 | } |
d0af663e | 3063 | /* no update_treesame() - removing duplicates can't affect TREESAME */ |
6546b593 JH |
3064 | return surviving_parents; |
3065 | } | |
3066 | ||
faf0156b JH |
3067 | struct merge_simplify_state { |
3068 | struct commit *simplified; | |
3069 | }; | |
3070 | ||
3071 | static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs, struct commit *commit) | |
3072 | { | |
3073 | struct merge_simplify_state *st; | |
3074 | ||
3075 | st = lookup_decoration(&revs->merge_simplification, &commit->object); | |
3076 | if (!st) { | |
ca56dadb | 3077 | CALLOC_ARRAY(st, 1); |
faf0156b JH |
3078 | add_decoration(&revs->merge_simplification, &commit->object, st); |
3079 | } | |
3080 | return st; | |
3081 | } | |
3082 | ||
91633995 | 3083 | static int mark_redundant_parents(struct commit *commit) |
d0af663e KB |
3084 | { |
3085 | struct commit_list *h = reduce_heads(commit->parents); | |
3086 | int i = 0, marked = 0; | |
3087 | struct commit_list *po, *pn; | |
3088 | ||
3089 | /* Want these for sanity-checking only */ | |
3090 | int orig_cnt = commit_list_count(commit->parents); | |
3091 | int cnt = commit_list_count(h); | |
3092 | ||
3093 | /* | |
3094 | * Not ready to remove items yet, just mark them for now, based | |
3095 | * on the output of reduce_heads(). reduce_heads outputs the reduced | |
3096 | * set in its original order, so this isn't too hard. | |
3097 | */ | |
3098 | po = commit->parents; | |
3099 | pn = h; | |
3100 | while (po) { | |
3101 | if (pn && po->item == pn->item) { | |
3102 | pn = pn->next; | |
3103 | i++; | |
3104 | } else { | |
3105 | po->item->object.flags |= TMP_MARK; | |
3106 | marked++; | |
3107 | } | |
3108 | po=po->next; | |
3109 | } | |
3110 | ||
3111 | if (i != cnt || cnt+marked != orig_cnt) | |
3112 | die("mark_redundant_parents %d %d %d %d", orig_cnt, cnt, i, marked); | |
3113 | ||
3114 | free_commit_list(h); | |
3115 | ||
3116 | return marked; | |
3117 | } | |
3118 | ||
91633995 | 3119 | static int mark_treesame_root_parents(struct commit *commit) |
143f1eaf KB |
3120 | { |
3121 | struct commit_list *p; | |
3122 | int marked = 0; | |
3123 | ||
3124 | for (p = commit->parents; p; p = p->next) { | |
3125 | struct commit *parent = p->item; | |
3126 | if (!parent->parents && (parent->object.flags & TREESAME)) { | |
3127 | parent->object.flags |= TMP_MARK; | |
3128 | marked++; | |
3129 | } | |
3130 | } | |
3131 | ||
3132 | return marked; | |
3133 | } | |
3134 | ||
9c129eab KB |
3135 | /* |
3136 | * Awkward naming - this means one parent we are TREESAME to. | |
3137 | * cf mark_treesame_root_parents: root parents that are TREESAME (to an | |
3138 | * empty tree). Better name suggestions? | |
3139 | */ | |
3140 | static int leave_one_treesame_to_parent(struct rev_info *revs, struct commit *commit) | |
3141 | { | |
3142 | struct treesame_state *ts = lookup_decoration(&revs->treesame, &commit->object); | |
3143 | struct commit *unmarked = NULL, *marked = NULL; | |
3144 | struct commit_list *p; | |
3145 | unsigned n; | |
3146 | ||
3147 | for (p = commit->parents, n = 0; p; p = p->next, n++) { | |
3148 | if (ts->treesame[n]) { | |
3149 | if (p->item->object.flags & TMP_MARK) { | |
3150 | if (!marked) | |
3151 | marked = p->item; | |
3152 | } else { | |
3153 | if (!unmarked) { | |
3154 | unmarked = p->item; | |
3155 | break; | |
3156 | } | |
3157 | } | |
3158 | } | |
3159 | } | |
3160 | ||
3161 | /* | |
3162 | * If we are TREESAME to a marked-for-deletion parent, but not to any | |
3163 | * unmarked parents, unmark the first TREESAME parent. This is the | |
3164 | * parent that the default simplify_history==1 scan would have followed, | |
3165 | * and it doesn't make sense to omit that path when asking for a | |
3166 | * simplified full history. Retaining it improves the chances of | |
3167 | * understanding odd missed merges that took an old version of a file. | |
3168 | * | |
3169 | * Example: | |
3170 | * | |
3171 | * I--------*X A modified the file, but mainline merge X used | |
3172 | * \ / "-s ours", so took the version from I. X is | |
3173 | * `-*A--' TREESAME to I and !TREESAME to A. | |
3174 | * | |
3175 | * Default log from X would produce "I". Without this check, | |
3176 | * --full-history --simplify-merges would produce "I-A-X", showing | |
3177 | * the merge commit X and that it changed A, but not making clear that | |
3178 | * it had just taken the I version. With this check, the topology above | |
3179 | * is retained. | |
3180 | * | |
3181 | * Note that it is possible that the simplification chooses a different | |
3182 | * TREESAME parent from the default, in which case this test doesn't | |
3183 | * activate, and we _do_ drop the default parent. Example: | |
3184 | * | |
3185 | * I------X A modified the file, but it was reverted in B, | |
3186 | * \ / meaning mainline merge X is TREESAME to both | |
3187 | * *A-*B parents. | |
3188 | * | |
3189 | * Default log would produce "I" by following the first parent; | |
3190 | * --full-history --simplify-merges will produce "I-A-B". But this is a | |
3191 | * reasonable result - it presents a logical full history leading from | |
3192 | * I to X, and X is not an important merge. | |
3193 | */ | |
3194 | if (!unmarked && marked) { | |
3195 | marked->object.flags &= ~TMP_MARK; | |
3196 | return 1; | |
3197 | } | |
3198 | ||
3199 | return 0; | |
3200 | } | |
3201 | ||
d0af663e KB |
3202 | static int remove_marked_parents(struct rev_info *revs, struct commit *commit) |
3203 | { | |
3204 | struct commit_list **pp, *p; | |
3205 | int nth_parent, removed = 0; | |
3206 | ||
3207 | pp = &commit->parents; | |
3208 | nth_parent = 0; | |
3209 | while ((p = *pp) != NULL) { | |
3210 | struct commit *parent = p->item; | |
3211 | if (parent->object.flags & TMP_MARK) { | |
3212 | parent->object.flags &= ~TMP_MARK; | |
3213 | *pp = p->next; | |
3214 | free(p); | |
3215 | removed++; | |
3216 | compact_treesame(revs, commit, nth_parent); | |
3217 | continue; | |
3218 | } | |
3219 | pp = &p->next; | |
3220 | nth_parent++; | |
3221 | } | |
3222 | ||
3223 | /* Removing parents can only increase TREESAMEness */ | |
3224 | if (removed && !(commit->object.flags & TREESAME)) | |
3225 | update_treesame(revs, commit); | |
3226 | ||
3227 | return nth_parent; | |
3228 | } | |
3229 | ||
faf0156b | 3230 | static struct commit_list **simplify_one(struct rev_info *revs, struct commit *commit, struct commit_list **tail) |
6546b593 JH |
3231 | { |
3232 | struct commit_list *p; | |
4d826608 | 3233 | struct commit *parent; |
faf0156b | 3234 | struct merge_simplify_state *st, *pst; |
6546b593 JH |
3235 | int cnt; |
3236 | ||
faf0156b JH |
3237 | st = locate_simplify_state(revs, commit); |
3238 | ||
6546b593 | 3239 | /* |
6546b593 JH |
3240 | * Have we handled this one? |
3241 | */ | |
faf0156b | 3242 | if (st->simplified) |
6546b593 JH |
3243 | return tail; |
3244 | ||
3245 | /* | |
3246 | * An UNINTERESTING commit simplifies to itself, so does a | |
3247 | * root commit. We do not rewrite parents of such commit | |
3248 | * anyway. | |
3249 | */ | |
3250 | if ((commit->object.flags & UNINTERESTING) || !commit->parents) { | |
faf0156b | 3251 | st->simplified = commit; |
6546b593 JH |
3252 | return tail; |
3253 | } | |
3254 | ||
3255 | /* | |
6e513ba3 JH |
3256 | * Do we know what commit all of our parents that matter |
3257 | * should be rewritten to? Otherwise we are not ready to | |
3258 | * rewrite this one yet. | |
6546b593 JH |
3259 | */ |
3260 | for (cnt = 0, p = commit->parents; p; p = p->next) { | |
faf0156b JH |
3261 | pst = locate_simplify_state(revs, p->item); |
3262 | if (!pst->simplified) { | |
6546b593 JH |
3263 | tail = &commit_list_insert(p->item, tail)->next; |
3264 | cnt++; | |
3265 | } | |
6e513ba3 JH |
3266 | if (revs->first_parent_only) |
3267 | break; | |
6546b593 | 3268 | } |
53030f8d JH |
3269 | if (cnt) { |
3270 | tail = &commit_list_insert(commit, tail)->next; | |
6546b593 | 3271 | return tail; |
53030f8d | 3272 | } |
6546b593 JH |
3273 | |
3274 | /* | |
d0af663e KB |
3275 | * Rewrite our list of parents. Note that this cannot |
3276 | * affect our TREESAME flags in any way - a commit is | |
3277 | * always TREESAME to its simplification. | |
6546b593 | 3278 | */ |
faf0156b JH |
3279 | for (p = commit->parents; p; p = p->next) { |
3280 | pst = locate_simplify_state(revs, p->item); | |
3281 | p->item = pst->simplified; | |
6e513ba3 JH |
3282 | if (revs->first_parent_only) |
3283 | break; | |
faf0156b | 3284 | } |
4b7f53da | 3285 | |
0290bf12 | 3286 | if (revs->first_parent_only) |
6e513ba3 | 3287 | cnt = 1; |
0290bf12 | 3288 | else |
d0af663e | 3289 | cnt = remove_duplicate_parents(revs, commit); |
6546b593 JH |
3290 | |
3291 | /* | |
3292 | * It is possible that we are a merge and one side branch | |
3293 | * does not have any commit that touches the given paths; | |
d0af663e KB |
3294 | * in such a case, the immediate parent from that branch |
3295 | * will be rewritten to be the merge base. | |
6546b593 JH |
3296 | * |
3297 | * o----X X: the commit we are looking at; | |
3298 | * / / o: a commit that touches the paths; | |
3299 | * ---o----' | |
3300 | * | |
143f1eaf KB |
3301 | * Further, a merge of an independent branch that doesn't |
3302 | * touch the path will reduce to a treesame root parent: | |
3303 | * | |
3304 | * ----o----X X: the commit we are looking at; | |
3305 | * / o: a commit that touches the paths; | |
3306 | * r r: a root commit not touching the paths | |
3307 | * | |
3308 | * Detect and simplify both cases. | |
6546b593 JH |
3309 | */ |
3310 | if (1 < cnt) { | |
91633995 JK |
3311 | int marked = mark_redundant_parents(commit); |
3312 | marked += mark_treesame_root_parents(commit); | |
9c129eab KB |
3313 | if (marked) |
3314 | marked -= leave_one_treesame_to_parent(revs, commit); | |
d0af663e KB |
3315 | if (marked) |
3316 | cnt = remove_marked_parents(revs, commit); | |
6546b593 JH |
3317 | } |
3318 | ||
3319 | /* | |
3320 | * A commit simplifies to itself if it is a root, if it is | |
3321 | * UNINTERESTING, if it touches the given paths, or if it is a | |
4d826608 | 3322 | * merge and its parents don't simplify to one relevant commit |
6546b593 JH |
3323 | * (the first two cases are already handled at the beginning of |
3324 | * this function). | |
3325 | * | |
4d826608 KB |
3326 | * Otherwise, it simplifies to what its sole relevant parent |
3327 | * simplifies to. | |
6546b593 JH |
3328 | */ |
3329 | if (!cnt || | |
3330 | (commit->object.flags & UNINTERESTING) || | |
3331 | !(commit->object.flags & TREESAME) || | |
8d049e18 DS |
3332 | (parent = one_relevant_parent(revs, commit->parents)) == NULL || |
3333 | (revs->show_pulls && (commit->object.flags & PULL_MERGE))) | |
faf0156b JH |
3334 | st->simplified = commit; |
3335 | else { | |
4d826608 | 3336 | pst = locate_simplify_state(revs, parent); |
faf0156b JH |
3337 | st->simplified = pst->simplified; |
3338 | } | |
6546b593 JH |
3339 | return tail; |
3340 | } | |
3341 | ||
3342 | static void simplify_merges(struct rev_info *revs) | |
3343 | { | |
ab9d75a8 | 3344 | struct commit_list *list, *next; |
6546b593 | 3345 | struct commit_list *yet_to_do, **tail; |
ab9d75a8 | 3346 | struct commit *commit; |
6546b593 | 3347 | |
5eac739e JH |
3348 | if (!revs->prune) |
3349 | return; | |
65347030 | 3350 | |
6546b593 JH |
3351 | /* feed the list reversed */ |
3352 | yet_to_do = NULL; | |
ab9d75a8 JH |
3353 | for (list = revs->commits; list; list = next) { |
3354 | commit = list->item; | |
3355 | next = list->next; | |
3356 | /* | |
3357 | * Do not free(list) here yet; the original list | |
3358 | * is used later in this function. | |
3359 | */ | |
3360 | commit_list_insert(commit, &yet_to_do); | |
3361 | } | |
6546b593 JH |
3362 | while (yet_to_do) { |
3363 | list = yet_to_do; | |
3364 | yet_to_do = NULL; | |
3365 | tail = &yet_to_do; | |
3366 | while (list) { | |
e510ab89 | 3367 | commit = pop_commit(&list); |
faf0156b | 3368 | tail = simplify_one(revs, commit, tail); |
6546b593 JH |
3369 | } |
3370 | } | |
3371 | ||
3372 | /* clean up the result, removing the simplified ones */ | |
3373 | list = revs->commits; | |
3374 | revs->commits = NULL; | |
3375 | tail = &revs->commits; | |
3376 | while (list) { | |
faf0156b | 3377 | struct merge_simplify_state *st; |
ab9d75a8 | 3378 | |
e510ab89 | 3379 | commit = pop_commit(&list); |
faf0156b JH |
3380 | st = locate_simplify_state(revs, commit); |
3381 | if (st->simplified == commit) | |
6546b593 JH |
3382 | tail = &commit_list_insert(commit, tail)->next; |
3383 | } | |
6546b593 JH |
3384 | } |
3385 | ||
f35f5603 JH |
3386 | static void set_children(struct rev_info *revs) |
3387 | { | |
3388 | struct commit_list *l; | |
3389 | for (l = revs->commits; l; l = l->next) { | |
3390 | struct commit *commit = l->item; | |
3391 | struct commit_list *p; | |
3392 | ||
3393 | for (p = commit->parents; p; p = p->next) | |
3394 | add_child(revs, p->item, commit); | |
3395 | } | |
3396 | } | |
3397 | ||
bcc0a3ea HV |
3398 | void reset_revision_walk(void) |
3399 | { | |
ffa1f28f | 3400 | clear_object_flags(SEEN | ADDED | SHOWN | TOPO_WALK_EXPLORED | TOPO_WALK_INDEGREE); |
bcc0a3ea HV |
3401 | } |
3402 | ||
df11e196 JT |
3403 | static int mark_uninteresting(const struct object_id *oid, |
3404 | struct packed_git *pack, | |
3405 | uint32_t pos, | |
b3c7eef9 | 3406 | void *cb) |
df11e196 | 3407 | { |
b3c7eef9 | 3408 | struct rev_info *revs = cb; |
c1fa951d | 3409 | struct object *o = lookup_unknown_object(revs->repo, oid); |
df11e196 JT |
3410 | o->flags |= UNINTERESTING | SEEN; |
3411 | return 0; | |
3412 | } | |
3413 | ||
b4542418 DS |
3414 | define_commit_slab(indegree_slab, int); |
3415 | define_commit_slab(author_date_slab, timestamp_t); | |
3416 | ||
3417 | struct topo_walk_info { | |
d7f92784 | 3418 | timestamp_t min_generation; |
b4542418 DS |
3419 | struct prio_queue explore_queue; |
3420 | struct prio_queue indegree_queue; | |
3421 | struct prio_queue topo_queue; | |
3422 | struct indegree_slab indegree; | |
3423 | struct author_date_slab author_date; | |
3424 | }; | |
3425 | ||
90b666da DS |
3426 | static int topo_walk_atexit_registered; |
3427 | static unsigned int count_explore_walked; | |
3428 | static unsigned int count_indegree_walked; | |
3429 | static unsigned int count_topo_walked; | |
3430 | ||
3431 | static void trace2_topo_walk_statistics_atexit(void) | |
3432 | { | |
3433 | struct json_writer jw = JSON_WRITER_INIT; | |
3434 | ||
3435 | jw_object_begin(&jw, 0); | |
3436 | jw_object_intmax(&jw, "count_explore_walked", count_explore_walked); | |
3437 | jw_object_intmax(&jw, "count_indegree_walked", count_indegree_walked); | |
3438 | jw_object_intmax(&jw, "count_topo_walked", count_topo_walked); | |
3439 | jw_end(&jw); | |
3440 | ||
3441 | trace2_data_json("topo_walk", the_repository, "statistics", &jw); | |
3442 | ||
3443 | jw_release(&jw); | |
3444 | } | |
3445 | ||
b4542418 DS |
3446 | static inline void test_flag_and_insert(struct prio_queue *q, struct commit *c, int flag) |
3447 | { | |
3448 | if (c->object.flags & flag) | |
3449 | return; | |
3450 | ||
3451 | c->object.flags |= flag; | |
3452 | prio_queue_put(q, c); | |
3453 | } | |
3454 | ||
3455 | static void explore_walk_step(struct rev_info *revs) | |
3456 | { | |
3457 | struct topo_walk_info *info = revs->topo_walk_info; | |
3458 | struct commit_list *p; | |
3459 | struct commit *c = prio_queue_get(&info->explore_queue); | |
3460 | ||
3461 | if (!c) | |
3462 | return; | |
3463 | ||
ea3f7e59 | 3464 | if (repo_parse_commit_gently(revs->repo, c, 1) < 0) |
b4542418 DS |
3465 | return; |
3466 | ||
90b666da DS |
3467 | count_explore_walked++; |
3468 | ||
b4542418 DS |
3469 | if (revs->sort_order == REV_SORT_BY_AUTHOR_DATE) |
3470 | record_author_date(&info->author_date, c); | |
3471 | ||
3472 | if (revs->max_age != -1 && (c->date < revs->max_age)) | |
3473 | c->object.flags |= UNINTERESTING; | |
3474 | ||
3475 | if (process_parents(revs, c, NULL, NULL) < 0) | |
3476 | return; | |
3477 | ||
3478 | if (c->object.flags & UNINTERESTING) | |
9d505b7b | 3479 | mark_parents_uninteresting(revs, c); |
b4542418 DS |
3480 | |
3481 | for (p = c->parents; p; p = p->next) | |
3482 | test_flag_and_insert(&info->explore_queue, p->item, TOPO_WALK_EXPLORED); | |
3483 | } | |
3484 | ||
3485 | static void explore_to_depth(struct rev_info *revs, | |
d7f92784 | 3486 | timestamp_t gen_cutoff) |
b4542418 DS |
3487 | { |
3488 | struct topo_walk_info *info = revs->topo_walk_info; | |
3489 | struct commit *c; | |
3490 | while ((c = prio_queue_peek(&info->explore_queue)) && | |
c49c82aa | 3491 | commit_graph_generation(c) >= gen_cutoff) |
b4542418 DS |
3492 | explore_walk_step(revs); |
3493 | } | |
3494 | ||
3495 | static void indegree_walk_step(struct rev_info *revs) | |
3496 | { | |
3497 | struct commit_list *p; | |
3498 | struct topo_walk_info *info = revs->topo_walk_info; | |
3499 | struct commit *c = prio_queue_get(&info->indegree_queue); | |
3500 | ||
3501 | if (!c) | |
3502 | return; | |
3503 | ||
ea3f7e59 | 3504 | if (repo_parse_commit_gently(revs->repo, c, 1) < 0) |
b4542418 DS |
3505 | return; |
3506 | ||
90b666da DS |
3507 | count_indegree_walked++; |
3508 | ||
c49c82aa | 3509 | explore_to_depth(revs, commit_graph_generation(c)); |
b4542418 DS |
3510 | |
3511 | for (p = c->parents; p; p = p->next) { | |
3512 | struct commit *parent = p->item; | |
3513 | int *pi = indegree_slab_at(&info->indegree, parent); | |
3514 | ||
2f9bbb6d AK |
3515 | if (repo_parse_commit_gently(revs->repo, parent, 1) < 0) |
3516 | return; | |
3517 | ||
b4542418 DS |
3518 | if (*pi) |
3519 | (*pi)++; | |
3520 | else | |
3521 | *pi = 2; | |
3522 | ||
3523 | test_flag_and_insert(&info->indegree_queue, parent, TOPO_WALK_INDEGREE); | |
3524 | ||
3525 | if (revs->first_parent_only) | |
3526 | return; | |
3527 | } | |
3528 | } | |
3529 | ||
3530 | static void compute_indegrees_to_depth(struct rev_info *revs, | |
d7f92784 | 3531 | timestamp_t gen_cutoff) |
b4542418 DS |
3532 | { |
3533 | struct topo_walk_info *info = revs->topo_walk_info; | |
3534 | struct commit *c; | |
3535 | while ((c = prio_queue_peek(&info->indegree_queue)) && | |
c49c82aa | 3536 | commit_graph_generation(c) >= gen_cutoff) |
b4542418 DS |
3537 | indegree_walk_step(revs); |
3538 | } | |
f0d9cc41 | 3539 | |
ae1b383d | 3540 | static void release_revisions_topo_walk_info(struct topo_walk_info *info) |
0aa0c2b2 | 3541 | { |
ae1b383d ÆAB |
3542 | if (!info) |
3543 | return; | |
0aa0c2b2 MH |
3544 | clear_prio_queue(&info->explore_queue); |
3545 | clear_prio_queue(&info->indegree_queue); | |
3546 | clear_prio_queue(&info->topo_queue); | |
3547 | clear_indegree_slab(&info->indegree); | |
3548 | clear_author_date_slab(&info->author_date); | |
ae1b383d ÆAB |
3549 | free(info); |
3550 | } | |
0aa0c2b2 | 3551 | |
ae1b383d ÆAB |
3552 | static void reset_topo_walk(struct rev_info *revs) |
3553 | { | |
3554 | release_revisions_topo_walk_info(revs->topo_walk_info); | |
3555 | revs->topo_walk_info = NULL; | |
0aa0c2b2 MH |
3556 | } |
3557 | ||
f0d9cc41 DS |
3558 | static void init_topo_walk(struct rev_info *revs) |
3559 | { | |
3560 | struct topo_walk_info *info; | |
b4542418 | 3561 | struct commit_list *list; |
0aa0c2b2 MH |
3562 | if (revs->topo_walk_info) |
3563 | reset_topo_walk(revs); | |
3564 | ||
f0d9cc41 DS |
3565 | revs->topo_walk_info = xmalloc(sizeof(struct topo_walk_info)); |
3566 | info = revs->topo_walk_info; | |
3567 | memset(info, 0, sizeof(struct topo_walk_info)); | |
3568 | ||
b4542418 DS |
3569 | init_indegree_slab(&info->indegree); |
3570 | memset(&info->explore_queue, 0, sizeof(info->explore_queue)); | |
3571 | memset(&info->indegree_queue, 0, sizeof(info->indegree_queue)); | |
3572 | memset(&info->topo_queue, 0, sizeof(info->topo_queue)); | |
3573 | ||
3574 | switch (revs->sort_order) { | |
3575 | default: /* REV_SORT_IN_GRAPH_ORDER */ | |
3576 | info->topo_queue.compare = NULL; | |
3577 | break; | |
3578 | case REV_SORT_BY_COMMIT_DATE: | |
3579 | info->topo_queue.compare = compare_commits_by_commit_date; | |
3580 | break; | |
3581 | case REV_SORT_BY_AUTHOR_DATE: | |
3582 | init_author_date_slab(&info->author_date); | |
3583 | info->topo_queue.compare = compare_commits_by_author_date; | |
3584 | info->topo_queue.cb_data = &info->author_date; | |
3585 | break; | |
3586 | } | |
3587 | ||
3588 | info->explore_queue.compare = compare_commits_by_gen_then_commit_date; | |
3589 | info->indegree_queue.compare = compare_commits_by_gen_then_commit_date; | |
3590 | ||
3591 | info->min_generation = GENERATION_NUMBER_INFINITY; | |
3592 | for (list = revs->commits; list; list = list->next) { | |
3593 | struct commit *c = list->item; | |
d7f92784 | 3594 | timestamp_t generation; |
b4542418 | 3595 | |
ea3f7e59 | 3596 | if (repo_parse_commit_gently(revs->repo, c, 1)) |
b4542418 DS |
3597 | continue; |
3598 | ||
3599 | test_flag_and_insert(&info->explore_queue, c, TOPO_WALK_EXPLORED); | |
3600 | test_flag_and_insert(&info->indegree_queue, c, TOPO_WALK_INDEGREE); | |
3601 | ||
c752ad09 AK |
3602 | generation = commit_graph_generation(c); |
3603 | if (generation < info->min_generation) | |
3604 | info->min_generation = generation; | |
b4542418 DS |
3605 | |
3606 | *(indegree_slab_at(&info->indegree, c)) = 1; | |
3607 | ||
3608 | if (revs->sort_order == REV_SORT_BY_AUTHOR_DATE) | |
3609 | record_author_date(&info->author_date, c); | |
3610 | } | |
3611 | compute_indegrees_to_depth(revs, info->min_generation); | |
3612 | ||
3613 | for (list = revs->commits; list; list = list->next) { | |
3614 | struct commit *c = list->item; | |
3615 | ||
3616 | if (*(indegree_slab_at(&info->indegree, c)) == 1) | |
3617 | prio_queue_put(&info->topo_queue, c); | |
3618 | } | |
3619 | ||
3620 | /* | |
3621 | * This is unfortunate; the initial tips need to be shown | |
3622 | * in the order given from the revision traversal machinery. | |
3623 | */ | |
3624 | if (revs->sort_order == REV_SORT_IN_GRAPH_ORDER) | |
3625 | prio_queue_reverse(&info->topo_queue); | |
90b666da DS |
3626 | |
3627 | if (trace2_is_enabled() && !topo_walk_atexit_registered) { | |
3628 | atexit(trace2_topo_walk_statistics_atexit); | |
3629 | topo_walk_atexit_registered = 1; | |
3630 | } | |
f0d9cc41 DS |
3631 | } |
3632 | ||
3633 | static struct commit *next_topo_commit(struct rev_info *revs) | |
3634 | { | |
b4542418 DS |
3635 | struct commit *c; |
3636 | struct topo_walk_info *info = revs->topo_walk_info; | |
3637 | ||
3638 | /* pop next off of topo_queue */ | |
3639 | c = prio_queue_get(&info->topo_queue); | |
3640 | ||
3641 | if (c) | |
3642 | *(indegree_slab_at(&info->indegree, c)) = 0; | |
3643 | ||
3644 | return c; | |
f0d9cc41 DS |
3645 | } |
3646 | ||
3647 | static void expand_topo_walk(struct rev_info *revs, struct commit *commit) | |
3648 | { | |
b4542418 DS |
3649 | struct commit_list *p; |
3650 | struct topo_walk_info *info = revs->topo_walk_info; | |
3651 | if (process_parents(revs, commit, NULL, NULL) < 0) { | |
f0d9cc41 DS |
3652 | if (!revs->ignore_missing_links) |
3653 | die("Failed to traverse parents of commit %s", | |
3654 | oid_to_hex(&commit->object.oid)); | |
3655 | } | |
b4542418 | 3656 | |
90b666da DS |
3657 | count_topo_walked++; |
3658 | ||
b4542418 DS |
3659 | for (p = commit->parents; p; p = p->next) { |
3660 | struct commit *parent = p->item; | |
3661 | int *pi; | |
d7f92784 | 3662 | timestamp_t generation; |
b4542418 | 3663 | |
1d8e31a3 DS |
3664 | if (parent->object.flags & UNINTERESTING) |
3665 | continue; | |
3666 | ||
ea3f7e59 | 3667 | if (repo_parse_commit_gently(revs->repo, parent, 1) < 0) |
b4542418 DS |
3668 | continue; |
3669 | ||
c752ad09 AK |
3670 | generation = commit_graph_generation(parent); |
3671 | if (generation < info->min_generation) { | |
3672 | info->min_generation = generation; | |
b4542418 DS |
3673 | compute_indegrees_to_depth(revs, info->min_generation); |
3674 | } | |
3675 | ||
3676 | pi = indegree_slab_at(&info->indegree, parent); | |
3677 | ||
3678 | (*pi)--; | |
3679 | if (*pi == 1) | |
3680 | prio_queue_put(&info->topo_queue, parent); | |
3681 | ||
3682 | if (revs->first_parent_only) | |
3683 | return; | |
3684 | } | |
f0d9cc41 DS |
3685 | } |
3686 | ||
cc0e6c5a | 3687 | int prepare_revision_walk(struct rev_info *revs) |
a4a88b2b | 3688 | { |
1da1e07c JK |
3689 | int i; |
3690 | struct object_array old_pending; | |
2e7da8e9 | 3691 | struct commit_list **next = &revs->commits; |
cd2bdc53 | 3692 | |
1da1e07c | 3693 | memcpy(&old_pending, &revs->pending, sizeof(old_pending)); |
1f1e895f LT |
3694 | revs->pending.nr = 0; |
3695 | revs->pending.alloc = 0; | |
3696 | revs->pending.objects = NULL; | |
1da1e07c JK |
3697 | for (i = 0; i < old_pending.nr; i++) { |
3698 | struct object_array_entry *e = old_pending.objects + i; | |
20739490 | 3699 | struct commit *commit = handle_commit(revs, e); |
cd2bdc53 LT |
3700 | if (commit) { |
3701 | if (!(commit->object.flags & SEEN)) { | |
3702 | commit->object.flags |= SEEN; | |
2e7da8e9 | 3703 | next = commit_list_append(commit, next); |
cd2bdc53 LT |
3704 | } |
3705 | } | |
cd2bdc53 | 3706 | } |
f1230fb5 | 3707 | object_array_clear(&old_pending); |
cd2bdc53 | 3708 | |
d0af663e | 3709 | /* Signal whether we need per-parent treesame decoration */ |
4d826608 KB |
3710 | if (revs->simplify_merges || |
3711 | (revs->limited && limiting_can_increase_treesame(revs))) | |
d0af663e KB |
3712 | revs->treesame.name = "treesame"; |
3713 | ||
df11e196 | 3714 | if (revs->exclude_promisor_objects) { |
b3c7eef9 | 3715 | for_each_packed_object(mark_uninteresting, revs, |
df11e196 JT |
3716 | FOR_EACH_OBJECT_PROMISOR_ONLY); |
3717 | } | |
3718 | ||
f32dde8c | 3719 | if (!revs->reflog_info) |
a56b9464 | 3720 | prepare_to_use_bloom_filter(revs); |
29ef1f27 | 3721 | if (!revs->unsorted_input) |
ca92e59e | 3722 | commit_list_sort_by_date(&revs->commits); |
ba1d4505 | 3723 | if (revs->no_walk) |
cc0e6c5a | 3724 | return 0; |
f0d9cc41 | 3725 | if (revs->limited) { |
cc0e6c5a AR |
3726 | if (limit_list(revs) < 0) |
3727 | return -1; | |
f0d9cc41 DS |
3728 | if (revs->topo_order) |
3729 | sort_in_topological_order(&revs->commits, revs->sort_order); | |
3730 | } else if (revs->topo_order) | |
3731 | init_topo_walk(revs); | |
3cb9d2b6 SG |
3732 | if (revs->line_level_traverse && want_ancestry(revs)) |
3733 | /* | |
3734 | * At the moment we can only do line-level log with parent | |
3735 | * rewriting by performing this expensive pre-filtering step. | |
3736 | * If parent rewriting is not requested, then we rather | |
3737 | * perform the line-level log filtering during the regular | |
3738 | * history traversal. | |
3739 | */ | |
12da1d1f | 3740 | line_log_filter(revs); |
6546b593 JH |
3741 | if (revs->simplify_merges) |
3742 | simplify_merges(revs); | |
f35f5603 JH |
3743 | if (revs->children.name) |
3744 | set_children(revs); | |
a56b9464 | 3745 | |
cc0e6c5a | 3746 | return 0; |
a4a88b2b LT |
3747 | } |
3748 | ||
8320b1db JK |
3749 | static enum rewrite_result rewrite_one_1(struct rev_info *revs, |
3750 | struct commit **pp, | |
3751 | struct prio_queue *queue) | |
765ac8ec LT |
3752 | { |
3753 | for (;;) { | |
3754 | struct commit *p = *pp; | |
3381c790 | 3755 | if (!revs->limited) |
8320b1db | 3756 | if (process_parents(revs, p, NULL, queue) < 0) |
cc0e6c5a | 3757 | return rewrite_one_error; |
7dc0fe3b LT |
3758 | if (p->object.flags & UNINTERESTING) |
3759 | return rewrite_one_ok; | |
3760 | if (!(p->object.flags & TREESAME)) | |
cc0e6c5a | 3761 | return rewrite_one_ok; |
765ac8ec | 3762 | if (!p->parents) |
cc0e6c5a | 3763 | return rewrite_one_noparents; |
afe8a907 | 3764 | if (!(p = one_relevant_parent(revs, p->parents))) |
4d826608 KB |
3765 | return rewrite_one_ok; |
3766 | *pp = p; | |
765ac8ec LT |
3767 | } |
3768 | } | |
3769 | ||
8320b1db JK |
3770 | static void merge_queue_into_list(struct prio_queue *q, struct commit_list **list) |
3771 | { | |
3772 | while (q->nr) { | |
3773 | struct commit *item = prio_queue_peek(q); | |
3774 | struct commit_list *p = *list; | |
3775 | ||
3776 | if (p && p->item->date >= item->date) | |
3777 | list = &p->next; | |
3778 | else { | |
3779 | p = commit_list_insert(item, list); | |
3780 | list = &p->next; /* skip newly added item */ | |
3781 | prio_queue_get(q); /* pop item */ | |
3782 | } | |
3783 | } | |
3784 | } | |
3785 | ||
3786 | static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp) | |
3787 | { | |
3788 | struct prio_queue queue = { compare_commits_by_commit_date }; | |
3789 | enum rewrite_result ret = rewrite_one_1(revs, pp, &queue); | |
3790 | merge_queue_into_list(&queue, &revs->commits); | |
3791 | clear_prio_queue(&queue); | |
3792 | return ret; | |
3793 | } | |
3794 | ||
c7edcae0 BY |
3795 | int rewrite_parents(struct rev_info *revs, struct commit *commit, |
3796 | rewrite_parent_fn_t rewrite_parent) | |
765ac8ec LT |
3797 | { |
3798 | struct commit_list **pp = &commit->parents; | |
3799 | while (*pp) { | |
3800 | struct commit_list *parent = *pp; | |
c7edcae0 | 3801 | switch (rewrite_parent(revs, &parent->item)) { |
cc0e6c5a AR |
3802 | case rewrite_one_ok: |
3803 | break; | |
3804 | case rewrite_one_noparents: | |
765ac8ec LT |
3805 | *pp = parent->next; |
3806 | continue; | |
cc0e6c5a AR |
3807 | case rewrite_one_error: |
3808 | return -1; | |
765ac8ec LT |
3809 | } |
3810 | pp = &parent->next; | |
3811 | } | |
d0af663e | 3812 | remove_duplicate_parents(revs, commit); |
cc0e6c5a | 3813 | return 0; |
765ac8ec LT |
3814 | } |
3815 | ||
8ecae9b0 JH |
3816 | static int commit_match(struct commit *commit, struct rev_info *opt) |
3817 | { | |
72fd13f7 | 3818 | int retval; |
04deccda | 3819 | const char *encoding; |
b000c59b | 3820 | const char *message; |
72fd13f7 | 3821 | struct strbuf buf = STRBUF_INIT; |
04deccda | 3822 | |
80235ba7 | 3823 | if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list) |
8ecae9b0 | 3824 | return 1; |
baa6378f JH |
3825 | |
3826 | /* Prepend "fake" headers as needed */ | |
3827 | if (opt->grep_filter.use_reflog_filter) { | |
72fd13f7 NTND |
3828 | strbuf_addstr(&buf, "reflog "); |
3829 | get_reflog_message(&buf, opt->reflog_info); | |
3830 | strbuf_addch(&buf, '\n'); | |
72fd13f7 | 3831 | } |
baa6378f | 3832 | |
04deccda JK |
3833 | /* |
3834 | * We grep in the user's output encoding, under the assumption that it | |
3835 | * is the encoding they are most likely to write their grep pattern | |
3836 | * for. In addition, it means we will match the "notes" encoding below, | |
3837 | * so we will not end up with a buffer that has two different encodings | |
3838 | * in it. | |
3839 | */ | |
3840 | encoding = get_log_output_encoding(); | |
5a10d236 | 3841 | message = logmsg_reencode(commit, NULL, encoding); |
04deccda | 3842 | |
baa6378f JH |
3843 | /* Copy the commit to temporary if we are using "fake" headers */ |
3844 | if (buf.len) | |
04deccda | 3845 | strbuf_addstr(&buf, message); |
baa6378f | 3846 | |
df874fa8 | 3847 | if (opt->grep_filter.header_list && opt->mailmap) { |
e9c1b0e3 SA |
3848 | const char *commit_headers[] = { "author ", "committer ", NULL }; |
3849 | ||
d72fbe81 | 3850 | if (!buf.len) |
04deccda | 3851 | strbuf_addstr(&buf, message); |
d72fbe81 | 3852 | |
66a8a953 | 3853 | apply_mailmap_to_header(&buf, commit_headers, opt->mailmap); |
d72fbe81 AP |
3854 | } |
3855 | ||
38cfe915 NTND |
3856 | /* Append "fake" message parts as needed */ |
3857 | if (opt->show_notes) { | |
3858 | if (!buf.len) | |
04deccda | 3859 | strbuf_addstr(&buf, message); |
fb61e4d3 | 3860 | format_display_notes(&commit->object.oid, &buf, encoding, 1); |
38cfe915 NTND |
3861 | } |
3862 | ||
b000c59b JK |
3863 | /* |
3864 | * Find either in the original commit message, or in the temporary. | |
3865 | * Note that we cast away the constness of "message" here. It is | |
3866 | * const because it may come from the cached commit buffer. That's OK, | |
3867 | * because we know that it is modifiable heap memory, and that while | |
3868 | * grep_buffer may modify it for speed, it will restore any | |
3869 | * changes before returning. | |
3870 | */ | |
72fd13f7 NTND |
3871 | if (buf.len) |
3872 | retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len); | |
3873 | else | |
3874 | retval = grep_buffer(&opt->grep_filter, | |
b000c59b | 3875 | (char *)message, strlen(message)); |
72fd13f7 | 3876 | strbuf_release(&buf); |
b66103c3 | 3877 | unuse_commit_buffer(commit, message); |
794c0002 | 3878 | return retval; |
8ecae9b0 JH |
3879 | } |
3880 | ||
53d00b39 | 3881 | static inline int want_ancestry(const struct rev_info *revs) |
f35f5603 | 3882 | { |
8bb65883 | 3883 | return (revs->rewrite_parents || revs->children.name); |
f35f5603 JH |
3884 | } |
3885 | ||
de239446 JK |
3886 | /* |
3887 | * Return a timestamp to be used for --since/--until comparisons for this | |
3888 | * commit, based on the revision options. | |
3889 | */ | |
3890 | static timestamp_t comparison_date(const struct rev_info *revs, | |
3891 | struct commit *commit) | |
3892 | { | |
3893 | return revs->reflog_info ? | |
3894 | get_reflog_timestamp(revs->reflog_info) : | |
3895 | commit->date; | |
3896 | } | |
3897 | ||
beb5af43 | 3898 | enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit) |
252a7c02 LT |
3899 | { |
3900 | if (commit->object.flags & SHOWN) | |
3901 | return commit_ignore; | |
14c3c80c | 3902 | if (revs->unpacked && has_object_pack(&commit->object.oid)) |
252a7c02 | 3903 | return commit_ignore; |
c9fff000 TB |
3904 | if (revs->no_kept_objects) { |
3905 | if (has_object_kept_pack(&commit->object.oid, | |
3906 | revs->keep_pack_cache_flags)) | |
3907 | return commit_ignore; | |
3908 | } | |
252a7c02 LT |
3909 | if (commit->object.flags & UNINTERESTING) |
3910 | return commit_ignore; | |
3cb9d2b6 SG |
3911 | if (revs->line_level_traverse && !want_ancestry(revs)) { |
3912 | /* | |
3913 | * In case of line-level log with parent rewriting | |
3914 | * prepare_revision_walk() already took care of all line-level | |
3915 | * log filtering, and there is nothing left to do here. | |
3916 | * | |
3917 | * If parent rewriting was not requested, then this is the | |
3918 | * place to perform the line-level log filtering. Notably, | |
3919 | * this check, though expensive, must come before the other, | |
3920 | * cheaper filtering conditions, because the tracked line | |
3921 | * ranges must be adjusted even when the commit will end up | |
3922 | * being ignored based on other conditions. | |
3923 | */ | |
3924 | if (!line_log_process_ranges_arbitrary_commit(revs, commit)) | |
3925 | return commit_ignore; | |
3926 | } | |
de239446 JK |
3927 | if (revs->min_age != -1 && |
3928 | comparison_date(revs, commit) > revs->min_age) | |
3929 | return commit_ignore; | |
96697781 MV |
3930 | if (revs->max_age_as_filter != -1 && |
3931 | comparison_date(revs, commit) < revs->max_age_as_filter) | |
3932 | return commit_ignore; | |
ad5aeede | 3933 | if (revs->min_parents || (revs->max_parents >= 0)) { |
bf3418b0 | 3934 | int n = commit_list_count(commit->parents); |
ad5aeede MG |
3935 | if ((n < revs->min_parents) || |
3936 | ((revs->max_parents >= 0) && (n > revs->max_parents))) | |
3937 | return commit_ignore; | |
3938 | } | |
252a7c02 LT |
3939 | if (!commit_match(commit, revs)) |
3940 | return commit_ignore; | |
53b2c823 | 3941 | if (revs->prune && revs->dense) { |
252a7c02 | 3942 | /* Commit without changes? */ |
7dc0fe3b | 3943 | if (commit->object.flags & TREESAME) { |
bf3418b0 KB |
3944 | int n; |
3945 | struct commit_list *p; | |
252a7c02 | 3946 | /* drop merges unless we want parenthood */ |
f35f5603 | 3947 | if (!want_ancestry(revs)) |
252a7c02 | 3948 | return commit_ignore; |
8d049e18 DS |
3949 | |
3950 | if (revs->show_pulls && (commit->object.flags & PULL_MERGE)) | |
3951 | return commit_show; | |
3952 | ||
bf3418b0 KB |
3953 | /* |
3954 | * If we want ancestry, then need to keep any merges | |
3955 | * between relevant commits to tie together topology. | |
3956 | * For consistency with TREESAME and simplification | |
3957 | * use "relevant" here rather than just INTERESTING, | |
3958 | * to treat bottom commit(s) as part of the topology. | |
3959 | */ | |
3960 | for (n = 0, p = commit->parents; p; p = p->next) | |
3961 | if (relevant_commit(p->item)) | |
3962 | if (++n >= 2) | |
3963 | return commit_show; | |
3964 | return commit_ignore; | |
252a7c02 | 3965 | } |
252a7c02 LT |
3966 | } |
3967 | return commit_show; | |
3968 | } | |
3969 | ||
0131c490 JH |
3970 | define_commit_slab(saved_parents, struct commit_list *); |
3971 | ||
3972 | #define EMPTY_PARENT_LIST ((struct commit_list *)-1) | |
3973 | ||
3974 | /* | |
3975 | * You may only call save_parents() once per commit (this is checked | |
3976 | * for non-root commits). | |
3977 | */ | |
3978 | static void save_parents(struct rev_info *revs, struct commit *commit) | |
3979 | { | |
3980 | struct commit_list **pp; | |
3981 | ||
3982 | if (!revs->saved_parents_slab) { | |
3983 | revs->saved_parents_slab = xmalloc(sizeof(struct saved_parents)); | |
3984 | init_saved_parents(revs->saved_parents_slab); | |
3985 | } | |
3986 | ||
3987 | pp = saved_parents_at(revs->saved_parents_slab, commit); | |
3988 | ||
3989 | /* | |
3990 | * When walking with reflogs, we may visit the same commit | |
3991 | * several times: once for each appearance in the reflog. | |
3992 | * | |
3993 | * In this case, save_parents() will be called multiple times. | |
3994 | * We want to keep only the first set of parents. We need to | |
3995 | * store a sentinel value for an empty (i.e., NULL) parent | |
3996 | * list to distinguish it from a not-yet-saved list, however. | |
3997 | */ | |
3998 | if (*pp) | |
3999 | return; | |
4000 | if (commit->parents) | |
4001 | *pp = copy_commit_list(commit->parents); | |
4002 | else | |
4003 | *pp = EMPTY_PARENT_LIST; | |
4004 | } | |
4005 | ||
4006 | static void free_saved_parents(struct rev_info *revs) | |
4007 | { | |
4008 | if (revs->saved_parents_slab) | |
4009 | clear_saved_parents(revs->saved_parents_slab); | |
4010 | } | |
4011 | ||
4012 | struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit) | |
4013 | { | |
4014 | struct commit_list *parents; | |
4015 | ||
4016 | if (!revs->saved_parents_slab) | |
4017 | return commit->parents; | |
4018 | ||
4019 | parents = *saved_parents_at(revs->saved_parents_slab, commit); | |
4020 | if (parents == EMPTY_PARENT_LIST) | |
4021 | return NULL; | |
4022 | return parents; | |
4023 | } | |
4024 | ||
beb5af43 AS |
4025 | enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) |
4026 | { | |
4027 | enum commit_action action = get_commit_action(revs, commit); | |
4028 | ||
4029 | if (action == commit_show && | |
beb5af43 | 4030 | revs->prune && revs->dense && want_ancestry(revs)) { |
53d00b39 TR |
4031 | /* |
4032 | * --full-diff on simplified parents is no good: it | |
4033 | * will show spurious changes from the commits that | |
4034 | * were elided. So we save the parents on the side | |
4035 | * when --full-diff is in effect. | |
4036 | */ | |
4037 | if (revs->full_diff) | |
4038 | save_parents(revs, commit); | |
c7edcae0 | 4039 | if (rewrite_parents(revs, commit, rewrite_one) < 0) |
beb5af43 AS |
4040 | return commit_error; |
4041 | } | |
4042 | return action; | |
4043 | } | |
4044 | ||
1b32dece NTND |
4045 | static void track_linear(struct rev_info *revs, struct commit *commit) |
4046 | { | |
4047 | if (revs->track_first_time) { | |
4048 | revs->linear = 1; | |
4049 | revs->track_first_time = 0; | |
4050 | } else { | |
4051 | struct commit_list *p; | |
4052 | for (p = revs->previous_parents; p; p = p->next) | |
4053 | if (p->item == NULL || /* first commit */ | |
4a7e27e9 | 4054 | oideq(&p->item->object.oid, &commit->object.oid)) |
1b32dece NTND |
4055 | break; |
4056 | revs->linear = p != NULL; | |
4057 | } | |
4058 | if (revs->reverse) { | |
4059 | if (revs->linear) | |
4060 | commit->object.flags |= TRACK_LINEAR; | |
4061 | } | |
4062 | free_commit_list(revs->previous_parents); | |
4063 | revs->previous_parents = copy_commit_list(commit->parents); | |
4064 | } | |
4065 | ||
d5db6c9e | 4066 | static struct commit *get_revision_1(struct rev_info *revs) |
a4a88b2b | 4067 | { |
7c2f08aa | 4068 | while (1) { |
d08565bf | 4069 | struct commit *commit; |
a4a88b2b | 4070 | |
d08565bf JK |
4071 | if (revs->reflog_info) |
4072 | commit = next_reflog_entry(revs->reflog_info); | |
f0d9cc41 DS |
4073 | else if (revs->topo_walk_info) |
4074 | commit = next_topo_commit(revs); | |
d08565bf JK |
4075 | else |
4076 | commit = pop_commit(&revs->commits); | |
2a0925be | 4077 | |
7c2f08aa JK |
4078 | if (!commit) |
4079 | return NULL; | |
4080 | ||
d08565bf | 4081 | if (revs->reflog_info) |
ffa1eeae | 4082 | commit->object.flags &= ~(ADDED | SEEN | SHOWN); |
8860fd42 | 4083 | |
2a0925be LT |
4084 | /* |
4085 | * If we haven't done the list limiting, we need to look at | |
be7db6e5 LT |
4086 | * the parents here. We also need to do the date-based limiting |
4087 | * that we'd otherwise have done in limit_list(). | |
2a0925be | 4088 | */ |
be7db6e5 | 4089 | if (!revs->limited) { |
744f4985 | 4090 | if (revs->max_age != -1 && |
de239446 | 4091 | comparison_date(revs, commit) < revs->max_age) |
86ab4906 | 4092 | continue; |
d08565bf JK |
4093 | |
4094 | if (revs->reflog_info) | |
4095 | try_to_simplify_commit(revs, commit); | |
f0d9cc41 DS |
4096 | else if (revs->topo_walk_info) |
4097 | expand_topo_walk(revs, commit); | |
5284fc5c | 4098 | else if (process_parents(revs, commit, &revs->commits, NULL) < 0) { |
2db1a43f VM |
4099 | if (!revs->ignore_missing_links) |
4100 | die("Failed to traverse parents of commit %s", | |
f2fd0760 | 4101 | oid_to_hex(&commit->object.oid)); |
2db1a43f | 4102 | } |
be7db6e5 | 4103 | } |
744f4985 | 4104 | |
252a7c02 LT |
4105 | switch (simplify_commit(revs, commit)) { |
4106 | case commit_ignore: | |
8ecae9b0 | 4107 | continue; |
252a7c02 | 4108 | case commit_error: |
ed62089c | 4109 | die("Failed to simplify parents of commit %s", |
f2fd0760 | 4110 | oid_to_hex(&commit->object.oid)); |
252a7c02 | 4111 | default: |
1b32dece NTND |
4112 | if (revs->track_linear) |
4113 | track_linear(revs, commit); | |
252a7c02 | 4114 | return commit; |
384e99a4 | 4115 | } |
7c2f08aa | 4116 | } |
765ac8ec | 4117 | } |
d5db6c9e | 4118 | |
be6754c6 MH |
4119 | /* |
4120 | * Return true for entries that have not yet been shown. (This is an | |
4121 | * object_array_each_func_t.) | |
4122 | */ | |
4123 | static int entry_unshown(struct object_array_entry *entry, void *cb_data_unused) | |
86ab4906 | 4124 | { |
be6754c6 MH |
4125 | return !(entry->item->flags & SHOWN); |
4126 | } | |
86ab4906 | 4127 | |
be6754c6 MH |
4128 | /* |
4129 | * If array is on the verge of a realloc, garbage-collect any entries | |
4130 | * that have already been shown to try to free up some space. | |
4131 | */ | |
4132 | static void gc_boundary(struct object_array *array) | |
4133 | { | |
4134 | if (array->nr == array->alloc) | |
4135 | object_array_filter(array, entry_unshown, NULL); | |
86ab4906 JH |
4136 | } |
4137 | ||
4603ec0f AS |
4138 | static void create_boundary_commit_list(struct rev_info *revs) |
4139 | { | |
4140 | unsigned i; | |
4141 | struct commit *c; | |
4142 | struct object_array *array = &revs->boundary_commits; | |
4143 | struct object_array_entry *objects = array->objects; | |
4144 | ||
4145 | /* | |
4146 | * If revs->commits is non-NULL at this point, an error occurred in | |
4147 | * get_revision_1(). Ignore the error and continue printing the | |
4148 | * boundary commits anyway. (This is what the code has always | |
4149 | * done.) | |
4150 | */ | |
bf20fe4c ÆAB |
4151 | free_commit_list(revs->commits); |
4152 | revs->commits = NULL; | |
4603ec0f AS |
4153 | |
4154 | /* | |
4155 | * Put all of the actual boundary commits from revs->boundary_commits | |
4156 | * into revs->commits | |
4157 | */ | |
4158 | for (i = 0; i < array->nr; i++) { | |
4159 | c = (struct commit *)(objects[i].item); | |
4160 | if (!c) | |
4161 | continue; | |
4162 | if (!(c->object.flags & CHILD_SHOWN)) | |
4163 | continue; | |
4164 | if (c->object.flags & (SHOWN | BOUNDARY)) | |
4165 | continue; | |
4166 | c->object.flags |= BOUNDARY; | |
4167 | commit_list_insert(c, &revs->commits); | |
4168 | } | |
4169 | ||
4170 | /* | |
4171 | * If revs->topo_order is set, sort the boundary commits | |
4172 | * in topological order | |
4173 | */ | |
08f704f2 | 4174 | sort_in_topological_order(&revs->commits, revs->sort_order); |
4603ec0f AS |
4175 | } |
4176 | ||
7fefda5c | 4177 | static struct commit *get_revision_internal(struct rev_info *revs) |
d5db6c9e JH |
4178 | { |
4179 | struct commit *c = NULL; | |
86ab4906 JH |
4180 | struct commit_list *l; |
4181 | ||
4182 | if (revs->boundary == 2) { | |
4603ec0f AS |
4183 | /* |
4184 | * All of the normal commits have already been returned, | |
4185 | * and we are now returning boundary commits. | |
4186 | * create_boundary_commit_list() has populated | |
4187 | * revs->commits with the remaining commits to return. | |
4188 | */ | |
4189 | c = pop_commit(&revs->commits); | |
4190 | if (c) | |
4191 | c->object.flags |= SHOWN; | |
9c5e66e9 JS |
4192 | return c; |
4193 | } | |
4194 | ||
86ab4906 | 4195 | /* |
b72a1904 JK |
4196 | * If our max_count counter has reached zero, then we are done. We |
4197 | * don't simply return NULL because we still might need to show | |
4198 | * boundary commits. But we want to avoid calling get_revision_1, which | |
4199 | * might do a considerable amount of work finding the next commit only | |
4200 | * for us to throw it away. | |
4201 | * | |
4202 | * If it is non-zero, then either we don't have a max_count at all | |
4203 | * (-1), or it is still counting, in which case we decrement. | |
86ab4906 | 4204 | */ |
b72a1904 JK |
4205 | if (revs->max_count) { |
4206 | c = get_revision_1(revs); | |
4207 | if (c) { | |
9e57ac55 | 4208 | while (revs->skip_count > 0) { |
b72a1904 JK |
4209 | revs->skip_count--; |
4210 | c = get_revision_1(revs); | |
4211 | if (!c) | |
4212 | break; | |
4213 | } | |
8839ac94 | 4214 | } |
86ab4906 | 4215 | |
b72a1904 JK |
4216 | if (revs->max_count > 0) |
4217 | revs->max_count--; | |
d5db6c9e | 4218 | } |
86ab4906 | 4219 | |
c33d8593 JH |
4220 | if (c) |
4221 | c->object.flags |= SHOWN; | |
4222 | ||
9e57ac55 | 4223 | if (!revs->boundary) |
d5db6c9e | 4224 | return c; |
86ab4906 JH |
4225 | |
4226 | if (!c) { | |
4227 | /* | |
4228 | * get_revision_1() runs out the commits, and | |
4229 | * we are done computing the boundaries. | |
4230 | * switch to boundary commits output mode. | |
4231 | */ | |
4232 | revs->boundary = 2; | |
4603ec0f AS |
4233 | |
4234 | /* | |
4235 | * Update revs->commits to contain the list of | |
4236 | * boundary commits. | |
4237 | */ | |
4238 | create_boundary_commit_list(revs); | |
4239 | ||
3c68d67b | 4240 | return get_revision_internal(revs); |
86ab4906 JH |
4241 | } |
4242 | ||
4243 | /* | |
4244 | * boundary commits are the commits that are parents of the | |
4245 | * ones we got from get_revision_1() but they themselves are | |
4246 | * not returned from get_revision_1(). Before returning | |
4247 | * 'c', we need to mark its parents that they could be boundaries. | |
4248 | */ | |
4249 | ||
4250 | for (l = c->parents; l; l = l->next) { | |
4251 | struct object *p; | |
4252 | p = &(l->item->object); | |
c33d8593 | 4253 | if (p->flags & (CHILD_SHOWN | SHOWN)) |
86ab4906 JH |
4254 | continue; |
4255 | p->flags |= CHILD_SHOWN; | |
4256 | gc_boundary(&revs->boundary_commits); | |
4257 | add_object_array(p, NULL, &revs->boundary_commits); | |
4258 | } | |
4259 | ||
4260 | return c; | |
d5db6c9e | 4261 | } |
7fefda5c AS |
4262 | |
4263 | struct commit *get_revision(struct rev_info *revs) | |
4264 | { | |
498bcd31 TR |
4265 | struct commit *c; |
4266 | struct commit_list *reversed; | |
4267 | ||
4268 | if (revs->reverse) { | |
4269 | reversed = NULL; | |
9e57ac55 | 4270 | while ((c = get_revision_internal(revs))) |
498bcd31 | 4271 | commit_list_insert(c, &reversed); |
498bcd31 TR |
4272 | revs->commits = reversed; |
4273 | revs->reverse = 0; | |
4274 | revs->reverse_output_stage = 1; | |
4275 | } | |
4276 | ||
1b32dece NTND |
4277 | if (revs->reverse_output_stage) { |
4278 | c = pop_commit(&revs->commits); | |
4279 | if (revs->track_linear) | |
4280 | revs->linear = !!(c && c->object.flags & TRACK_LINEAR); | |
4281 | return c; | |
4282 | } | |
498bcd31 TR |
4283 | |
4284 | c = get_revision_internal(revs); | |
7fefda5c AS |
4285 | if (c && revs->graph) |
4286 | graph_update(revs->graph, c); | |
1b32dece | 4287 | if (!c) { |
53d00b39 | 4288 | free_saved_parents(revs); |
bf20fe4c ÆAB |
4289 | free_commit_list(revs->previous_parents); |
4290 | revs->previous_parents = NULL; | |
1b32dece | 4291 | } |
7fefda5c AS |
4292 | return c; |
4293 | } | |
1df2d656 | 4294 | |
49825164 | 4295 | const char *get_revision_mark(const struct rev_info *revs, const struct commit *commit) |
1df2d656 MG |
4296 | { |
4297 | if (commit->object.flags & BOUNDARY) | |
4298 | return "-"; | |
4299 | else if (commit->object.flags & UNINTERESTING) | |
4300 | return "^"; | |
adbbb31e MG |
4301 | else if (commit->object.flags & PATCHSAME) |
4302 | return "="; | |
1df2d656 MG |
4303 | else if (!revs || revs->left_right) { |
4304 | if (commit->object.flags & SYMMETRIC_LEFT) | |
4305 | return "<"; | |
4306 | else | |
4307 | return ">"; | |
4308 | } else if (revs->graph) | |
4309 | return "*"; | |
adbbb31e MG |
4310 | else if (revs->cherry_mark) |
4311 | return "+"; | |
1df2d656 MG |
4312 | return ""; |
4313 | } | |
b1b47554 MG |
4314 | |
4315 | void put_revision_mark(const struct rev_info *revs, const struct commit *commit) | |
4316 | { | |
49825164 | 4317 | const char *mark = get_revision_mark(revs, commit); |
b1b47554 MG |
4318 | if (!strlen(mark)) |
4319 | return; | |
4320 | fputs(mark, stdout); | |
4321 | putchar(' '); | |
4322 | } |