1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
4 #include "git-compat-util.h"
6 #include "environment.h"
9 #include "object-name.h"
10 #include "object-file.h"
11 #include "object-store.h"
18 #include "diff-merges.h"
21 #include "repository.h"
24 #include "reflog-walk.h"
25 #include "patch-ids.h"
27 #include "string-list.h"
30 #include "commit-slab.h"
31 #include "cache-tree.h"
36 #include "read-cache.h"
38 #include "sparse-index.h"
41 #include "commit-reach.h"
42 #include "commit-graph.h"
43 #include "prio-queue.h"
47 #include "json-writer.h"
48 #include "list-objects-filter-options.h"
49 #include "resolve-undo.h"
50 #include "parse-options.h"
51 #include "wildmatch.h"
53 volatile show_early_output_fn_t show_early_output
;
55 static char *term_bad
;
56 static char *term_good
;
58 implement_shared_commit_slab(revision_sources
, char *);
60 static inline int want_ancestry(const struct rev_info
*revs
);
62 static void mark_blob_uninteresting(struct blob
*blob
)
66 if (blob
->object
.flags
& UNINTERESTING
)
68 blob
->object
.flags
|= UNINTERESTING
;
71 static void mark_tree_contents_uninteresting(struct repository
*r
,
74 struct tree_desc desc
;
75 struct name_entry entry
;
77 if (parse_tree_gently(tree
, 1) < 0)
80 init_tree_desc(&desc
, &tree
->object
.oid
, tree
->buffer
, tree
->size
);
81 while (tree_entry(&desc
, &entry
)) {
82 switch (object_type(entry
.mode
)) {
84 mark_tree_uninteresting(r
, lookup_tree(r
, &entry
.oid
));
87 mark_blob_uninteresting(lookup_blob(r
, &entry
.oid
));
90 /* Subproject commit - not in this repository */
96 * We don't care about the tree any more
97 * after it has been marked uninteresting.
99 free_tree_buffer(tree
);
102 void mark_tree_uninteresting(struct repository
*r
, struct tree
*tree
)
110 if (obj
->flags
& UNINTERESTING
)
112 obj
->flags
|= UNINTERESTING
;
113 mark_tree_contents_uninteresting(r
, tree
);
116 struct path_and_oids_entry
{
117 struct hashmap_entry ent
;
122 static int path_and_oids_cmp(const void *hashmap_cmp_fn_data UNUSED
,
123 const struct hashmap_entry
*eptr
,
124 const struct hashmap_entry
*entry_or_key
,
125 const void *keydata UNUSED
)
127 const struct path_and_oids_entry
*e1
, *e2
;
129 e1
= container_of(eptr
, const struct path_and_oids_entry
, ent
);
130 e2
= container_of(entry_or_key
, const struct path_and_oids_entry
, ent
);
132 return strcmp(e1
->path
, e2
->path
);
135 static void paths_and_oids_clear(struct hashmap
*map
)
137 struct hashmap_iter iter
;
138 struct path_and_oids_entry
*entry
;
140 hashmap_for_each_entry(map
, &iter
, entry
, ent
/* member name */) {
141 oidset_clear(&entry
->trees
);
145 hashmap_clear_and_free(map
, struct path_and_oids_entry
, ent
);
148 static void paths_and_oids_insert(struct hashmap
*map
,
150 const struct object_id
*oid
)
152 int hash
= strhash(path
);
153 struct path_and_oids_entry key
;
154 struct path_and_oids_entry
*entry
;
156 hashmap_entry_init(&key
.ent
, hash
);
158 /* use a shallow copy for the lookup */
159 key
.path
= (char *)path
;
160 oidset_init(&key
.trees
, 0);
162 entry
= hashmap_get_entry(map
, &key
, ent
, NULL
);
164 CALLOC_ARRAY(entry
, 1);
165 hashmap_entry_init(&entry
->ent
, hash
);
166 entry
->path
= xstrdup(key
.path
);
167 oidset_init(&entry
->trees
, 16);
168 hashmap_put(map
, &entry
->ent
);
171 oidset_insert(&entry
->trees
, oid
);
174 static void add_children_by_path(struct repository
*r
,
178 struct tree_desc desc
;
179 struct name_entry entry
;
184 if (parse_tree_gently(tree
, 1) < 0)
187 init_tree_desc(&desc
, &tree
->object
.oid
, tree
->buffer
, tree
->size
);
188 while (tree_entry(&desc
, &entry
)) {
189 switch (object_type(entry
.mode
)) {
191 paths_and_oids_insert(map
, entry
.path
, &entry
.oid
);
193 if (tree
->object
.flags
& UNINTERESTING
) {
194 struct tree
*child
= lookup_tree(r
, &entry
.oid
);
196 child
->object
.flags
|= UNINTERESTING
;
200 if (tree
->object
.flags
& UNINTERESTING
) {
201 struct blob
*child
= lookup_blob(r
, &entry
.oid
);
203 child
->object
.flags
|= UNINTERESTING
;
207 /* Subproject commit - not in this repository */
212 free_tree_buffer(tree
);
215 void mark_trees_uninteresting_sparse(struct repository
*r
,
216 struct oidset
*trees
)
218 unsigned has_interesting
= 0, has_uninteresting
= 0;
219 struct hashmap map
= HASHMAP_INIT(path_and_oids_cmp
, NULL
);
220 struct hashmap_iter map_iter
;
221 struct path_and_oids_entry
*entry
;
222 struct object_id
*oid
;
223 struct oidset_iter iter
;
225 oidset_iter_init(trees
, &iter
);
226 while ((!has_interesting
|| !has_uninteresting
) &&
227 (oid
= oidset_iter_next(&iter
))) {
228 struct tree
*tree
= lookup_tree(r
, oid
);
233 if (tree
->object
.flags
& UNINTERESTING
)
234 has_uninteresting
= 1;
239 /* Do not walk unless we have both types of trees. */
240 if (!has_uninteresting
|| !has_interesting
)
243 oidset_iter_init(trees
, &iter
);
244 while ((oid
= oidset_iter_next(&iter
))) {
245 struct tree
*tree
= lookup_tree(r
, oid
);
246 add_children_by_path(r
, tree
, &map
);
249 hashmap_for_each_entry(&map
, &map_iter
, entry
, ent
/* member name */)
250 mark_trees_uninteresting_sparse(r
, &entry
->trees
);
252 paths_and_oids_clear(&map
);
255 struct commit_stack
{
256 struct commit
**items
;
259 #define COMMIT_STACK_INIT { 0 }
261 static void commit_stack_push(struct commit_stack
*stack
, struct commit
*commit
)
263 ALLOC_GROW(stack
->items
, stack
->nr
+ 1, stack
->alloc
);
264 stack
->items
[stack
->nr
++] = commit
;
267 static struct commit
*commit_stack_pop(struct commit_stack
*stack
)
269 return stack
->nr
? stack
->items
[--stack
->nr
] : NULL
;
272 static void commit_stack_clear(struct commit_stack
*stack
)
274 FREE_AND_NULL(stack
->items
);
275 stack
->nr
= stack
->alloc
= 0;
278 static void mark_one_parent_uninteresting(struct rev_info
*revs
, struct commit
*commit
,
279 struct commit_stack
*pending
)
281 struct commit_list
*l
;
283 if (commit
->object
.flags
& UNINTERESTING
)
285 commit
->object
.flags
|= UNINTERESTING
;
288 * Normally we haven't parsed the parent
289 * yet, so we won't have a parent of a parent
290 * here. However, it may turn out that we've
291 * reached this commit some other way (where it
292 * wasn't uninteresting), in which case we need
293 * to mark its parents recursively too..
295 for (l
= commit
->parents
; l
; l
= l
->next
) {
296 commit_stack_push(pending
, l
->item
);
297 if (revs
&& revs
->exclude_first_parent_only
)
302 void mark_parents_uninteresting(struct rev_info
*revs
, struct commit
*commit
)
304 struct commit_stack pending
= COMMIT_STACK_INIT
;
305 struct commit_list
*l
;
307 for (l
= commit
->parents
; l
; l
= l
->next
) {
308 mark_one_parent_uninteresting(revs
, l
->item
, &pending
);
309 if (revs
&& revs
->exclude_first_parent_only
)
313 while (pending
.nr
> 0)
314 mark_one_parent_uninteresting(revs
, commit_stack_pop(&pending
),
317 commit_stack_clear(&pending
);
320 static void add_pending_object_with_path(struct rev_info
*revs
,
322 const char *name
, unsigned mode
,
325 struct interpret_branch_name_options options
= { 0 };
328 if (revs
->no_walk
&& (obj
->flags
& UNINTERESTING
))
330 if (revs
->reflog_info
&& obj
->type
== OBJ_COMMIT
) {
331 struct strbuf buf
= STRBUF_INIT
;
332 size_t namelen
= strlen(name
);
333 int len
= repo_interpret_branch_name(the_repository
, name
,
334 namelen
, &buf
, &options
);
336 if (0 < len
&& len
< namelen
&& buf
.len
)
337 strbuf_addstr(&buf
, name
+ len
);
338 add_reflog_for_walk(revs
->reflog_info
,
339 (struct commit
*)obj
,
340 buf
.buf
[0] ? buf
.buf
: name
);
341 strbuf_release(&buf
);
342 return; /* do not add the commit itself */
344 add_object_array_with_path(obj
, name
, &revs
->pending
, mode
, path
);
347 static void add_pending_object_with_mode(struct rev_info
*revs
,
349 const char *name
, unsigned mode
)
351 add_pending_object_with_path(revs
, obj
, name
, mode
, NULL
);
354 void add_pending_object(struct rev_info
*revs
,
355 struct object
*obj
, const char *name
)
357 add_pending_object_with_mode(revs
, obj
, name
, S_IFINVALID
);
360 void add_head_to_pending(struct rev_info
*revs
)
362 struct object_id oid
;
364 if (repo_get_oid(the_repository
, "HEAD", &oid
))
366 obj
= parse_object(revs
->repo
, &oid
);
369 add_pending_object(revs
, obj
, "HEAD");
372 static struct object
*get_reference(struct rev_info
*revs
, const char *name
,
373 const struct object_id
*oid
,
376 struct object
*object
;
378 object
= parse_object_with_flags(revs
->repo
, oid
,
379 revs
->verify_objects
? 0 :
380 PARSE_OBJECT_SKIP_HASH_CHECK
|
381 PARSE_OBJECT_DISCARD_TREE
);
384 if (revs
->ignore_missing
)
386 if (revs
->exclude_promisor_objects
&&
387 is_promisor_object(revs
->repo
, oid
))
389 if (revs
->do_not_die_on_missing_objects
) {
390 oidset_insert(&revs
->missing_commits
, oid
);
393 die("bad object %s", name
);
395 object
->flags
|= flags
;
399 void add_pending_oid(struct rev_info
*revs
, const char *name
,
400 const struct object_id
*oid
, unsigned int flags
)
402 struct object
*object
= get_reference(revs
, name
, oid
, flags
);
403 add_pending_object(revs
, object
, name
);
406 static struct commit
*handle_commit(struct rev_info
*revs
,
407 struct object_array_entry
*entry
)
409 struct object
*object
= entry
->item
;
410 const char *name
= entry
->name
;
411 const char *path
= entry
->path
;
412 unsigned int mode
= entry
->mode
;
413 unsigned long flags
= object
->flags
;
416 * Tag object? Look what it points to..
418 while (object
->type
== OBJ_TAG
) {
419 struct tag
*tag
= (struct tag
*) object
;
420 struct object_id
*oid
;
421 if (revs
->tag_objects
&& !(flags
& UNINTERESTING
))
422 add_pending_object(revs
, object
, tag
->tag
);
423 oid
= get_tagged_oid(tag
);
424 object
= parse_object(revs
->repo
, oid
);
426 if (revs
->ignore_missing_links
|| (flags
& UNINTERESTING
))
428 if (revs
->exclude_promisor_objects
&&
429 is_promisor_object(revs
->repo
, &tag
->tagged
->oid
))
431 if (revs
->do_not_die_on_missing_objects
&& oid
) {
432 oidset_insert(&revs
->missing_commits
, oid
);
435 die("bad object %s", oid_to_hex(&tag
->tagged
->oid
));
437 object
->flags
|= flags
;
439 * We'll handle the tagged object by looping or dropping
440 * through to the non-tag handlers below. Do not
441 * propagate path data from the tag's pending entry.
448 * Commit object? Just return it, we'll do all the complex
451 if (object
->type
== OBJ_COMMIT
) {
452 struct commit
*commit
= (struct commit
*)object
;
454 if (repo_parse_commit(revs
->repo
, commit
) < 0)
455 die("unable to parse commit %s", name
);
456 if (flags
& UNINTERESTING
) {
457 mark_parents_uninteresting(revs
, commit
);
459 if (!revs
->topo_order
|| !generation_numbers_enabled(the_repository
))
463 char **slot
= revision_sources_at(revs
->sources
, commit
);
466 *slot
= xstrdup(name
);
472 * Tree object? Either mark it uninteresting, or add it
473 * to the list of objects to look at later..
475 if (object
->type
== OBJ_TREE
) {
476 struct tree
*tree
= (struct tree
*)object
;
477 if (!revs
->tree_objects
)
479 if (flags
& UNINTERESTING
) {
480 mark_tree_contents_uninteresting(revs
->repo
, tree
);
483 add_pending_object_with_path(revs
, object
, name
, mode
, path
);
488 * Blob object? You know the drill by now..
490 if (object
->type
== OBJ_BLOB
) {
491 if (!revs
->blob_objects
)
493 if (flags
& UNINTERESTING
)
495 add_pending_object_with_path(revs
, object
, name
, mode
, path
);
498 die("%s is unknown object", name
);
501 static int everybody_uninteresting(struct commit_list
*orig
,
502 struct commit
**interesting_cache
)
504 struct commit_list
*list
= orig
;
506 if (*interesting_cache
) {
507 struct commit
*commit
= *interesting_cache
;
508 if (!(commit
->object
.flags
& UNINTERESTING
))
513 struct commit
*commit
= list
->item
;
515 if (commit
->object
.flags
& UNINTERESTING
)
518 *interesting_cache
= commit
;
525 * A definition of "relevant" commit that we can use to simplify limited graphs
526 * by eliminating side branches.
528 * A "relevant" commit is one that is !UNINTERESTING (ie we are including it
529 * in our list), or that is a specified BOTTOM commit. Then after computing
530 * a limited list, during processing we can generally ignore boundary merges
531 * coming from outside the graph, (ie from irrelevant parents), and treat
532 * those merges as if they were single-parent. TREESAME is defined to consider
533 * only relevant parents, if any. If we are TREESAME to our on-graph parents,
534 * we don't care if we were !TREESAME to non-graph parents.
536 * Treating bottom commits as relevant ensures that a limited graph's
537 * connection to the actual bottom commit is not viewed as a side branch, but
538 * treated as part of the graph. For example:
540 * ....Z...A---X---o---o---B
544 * When computing "A..B", the A-X connection is at least as important as
545 * Y-X, despite A being flagged UNINTERESTING.
547 * And when computing --ancestry-path "A..B", the A-X connection is more
548 * important than Y-X, despite both A and Y being flagged UNINTERESTING.
550 static inline int relevant_commit(struct commit
*commit
)
552 return (commit
->object
.flags
& (UNINTERESTING
| BOTTOM
)) != UNINTERESTING
;
556 * Return a single relevant commit from a parent list. If we are a TREESAME
557 * commit, and this selects one of our parents, then we can safely simplify to
560 static struct commit
*one_relevant_parent(const struct rev_info
*revs
,
561 struct commit_list
*orig
)
563 struct commit_list
*list
= orig
;
564 struct commit
*relevant
= NULL
;
570 * For 1-parent commits, or if first-parent-only, then return that
571 * first parent (even if not "relevant" by the above definition).
572 * TREESAME will have been set purely on that parent.
574 if (revs
->first_parent_only
|| !orig
->next
)
578 * For multi-parent commits, identify a sole relevant parent, if any.
579 * If we have only one relevant parent, then TREESAME will be set purely
580 * with regard to that parent, and we can simplify accordingly.
582 * If we have more than one relevant parent, or no relevant parents
583 * (and multiple irrelevant ones), then we can't select a parent here
587 struct commit
*commit
= list
->item
;
589 if (relevant_commit(commit
)) {
599 * The goal is to get REV_TREE_NEW as the result only if the
600 * diff consists of all '+' (and no other changes), REV_TREE_OLD
601 * if the whole diff is removal of old data, and otherwise
602 * REV_TREE_DIFFERENT (of course if the trees are the same we
603 * want REV_TREE_SAME).
605 * The only time we care about the distinction is when
606 * remove_empty_trees is in effect, in which case we care only about
607 * whether the whole change is REV_TREE_NEW, or if there's another type
608 * of change. Which means we can stop the diff early in either of these
611 * 1. We're not using remove_empty_trees at all.
613 * 2. We saw anything except REV_TREE_NEW.
615 #define REV_TREE_SAME 0
616 #define REV_TREE_NEW 1 /* Only new files */
617 #define REV_TREE_OLD 2 /* Only files removed */
618 #define REV_TREE_DIFFERENT 3 /* Mixed changes */
619 static int tree_difference
= REV_TREE_SAME
;
621 static void file_add_remove(struct diff_options
*options
,
623 unsigned mode UNUSED
,
624 const struct object_id
*oid UNUSED
,
625 int oid_valid UNUSED
,
626 const char *fullpath UNUSED
,
627 unsigned dirty_submodule UNUSED
)
629 int diff
= addremove
== '+' ? REV_TREE_NEW
: REV_TREE_OLD
;
630 struct rev_info
*revs
= options
->change_fn_data
;
632 tree_difference
|= diff
;
633 if (!revs
->remove_empty_trees
|| tree_difference
!= REV_TREE_NEW
)
634 options
->flags
.has_changes
= 1;
637 static void file_change(struct diff_options
*options
,
638 unsigned old_mode UNUSED
,
639 unsigned new_mode UNUSED
,
640 const struct object_id
*old_oid UNUSED
,
641 const struct object_id
*new_oid UNUSED
,
642 int old_oid_valid UNUSED
,
643 int new_oid_valid UNUSED
,
644 const char *fullpath UNUSED
,
645 unsigned old_dirty_submodule UNUSED
,
646 unsigned new_dirty_submodule UNUSED
)
648 tree_difference
= REV_TREE_DIFFERENT
;
649 options
->flags
.has_changes
= 1;
652 static int bloom_filter_atexit_registered
;
653 static unsigned int count_bloom_filter_maybe
;
654 static unsigned int count_bloom_filter_definitely_not
;
655 static unsigned int count_bloom_filter_false_positive
;
656 static unsigned int count_bloom_filter_not_present
;
658 static void trace2_bloom_filter_statistics_atexit(void)
660 struct json_writer jw
= JSON_WRITER_INIT
;
662 jw_object_begin(&jw
, 0);
663 jw_object_intmax(&jw
, "filter_not_present", count_bloom_filter_not_present
);
664 jw_object_intmax(&jw
, "maybe", count_bloom_filter_maybe
);
665 jw_object_intmax(&jw
, "definitely_not", count_bloom_filter_definitely_not
);
666 jw_object_intmax(&jw
, "false_positive", count_bloom_filter_false_positive
);
669 trace2_data_json("bloom", the_repository
, "statistics", &jw
);
674 static int forbid_bloom_filters(struct pathspec
*spec
)
676 if (spec
->has_wildcard
)
680 if (spec
->magic
& ~PATHSPEC_LITERAL
)
682 if (spec
->nr
&& (spec
->items
[0].magic
& ~PATHSPEC_LITERAL
))
688 static void prepare_to_use_bloom_filter(struct rev_info
*revs
)
690 struct pathspec_item
*pi
;
691 char *path_alloc
= NULL
;
692 const char *path
, *p
;
694 int path_component_nr
= 1;
699 if (forbid_bloom_filters(&revs
->prune_data
))
702 repo_parse_commit(revs
->repo
, revs
->commits
->item
);
704 revs
->bloom_filter_settings
= get_bloom_filter_settings(revs
->repo
);
705 if (!revs
->bloom_filter_settings
)
708 if (!revs
->pruning
.pathspec
.nr
)
711 pi
= &revs
->pruning
.pathspec
.items
[0];
713 /* remove single trailing slash from path, if needed */
714 if (pi
->len
> 0 && pi
->match
[pi
->len
- 1] == '/') {
715 path_alloc
= xmemdupz(pi
->match
, pi
->len
- 1);
722 revs
->bloom_filter_settings
= NULL
;
730 * At this point, the path is normalized to use Unix-style
731 * path separators. This is required due to how the
732 * changed-path Bloom filters store the paths.
739 revs
->bloom_keys_nr
= path_component_nr
;
740 ALLOC_ARRAY(revs
->bloom_keys
, revs
->bloom_keys_nr
);
742 fill_bloom_key(path
, len
, &revs
->bloom_keys
[0],
743 revs
->bloom_filter_settings
);
744 path_component_nr
= 1;
749 fill_bloom_key(path
, p
- path
,
750 &revs
->bloom_keys
[path_component_nr
++],
751 revs
->bloom_filter_settings
);
755 if (trace2_is_enabled() && !bloom_filter_atexit_registered
) {
756 atexit(trace2_bloom_filter_statistics_atexit
);
757 bloom_filter_atexit_registered
= 1;
763 static int check_maybe_different_in_bloom_filter(struct rev_info
*revs
,
764 struct commit
*commit
)
766 struct bloom_filter
*filter
;
769 if (!revs
->repo
->objects
->commit_graph
)
772 if (commit_graph_generation(commit
) == GENERATION_NUMBER_INFINITY
)
775 filter
= get_bloom_filter(revs
->repo
, commit
);
778 count_bloom_filter_not_present
++;
782 for (j
= 0; result
&& j
< revs
->bloom_keys_nr
; j
++) {
783 result
= bloom_filter_contains(filter
,
784 &revs
->bloom_keys
[j
],
785 revs
->bloom_filter_settings
);
789 count_bloom_filter_maybe
++;
791 count_bloom_filter_definitely_not
++;
796 static int rev_compare_tree(struct rev_info
*revs
,
797 struct commit
*parent
, struct commit
*commit
, int nth_parent
)
799 struct tree
*t1
= repo_get_commit_tree(the_repository
, parent
);
800 struct tree
*t2
= repo_get_commit_tree(the_repository
, commit
);
808 if (revs
->simplify_by_decoration
) {
810 * If we are simplifying by decoration, then the commit
811 * is worth showing if it has a tag pointing at it.
813 if (get_name_decoration(&commit
->object
))
814 return REV_TREE_DIFFERENT
;
816 * A commit that is not pointed by a tag is uninteresting
817 * if we are not limited by path. This means that you will
818 * see the usual "commits that touch the paths" plus any
819 * tagged commit by specifying both --simplify-by-decoration
822 if (!revs
->prune_data
.nr
)
823 return REV_TREE_SAME
;
826 if (revs
->bloom_keys_nr
&& !nth_parent
) {
827 bloom_ret
= check_maybe_different_in_bloom_filter(revs
, commit
);
830 return REV_TREE_SAME
;
833 tree_difference
= REV_TREE_SAME
;
834 revs
->pruning
.flags
.has_changes
= 0;
835 diff_tree_oid(&t1
->object
.oid
, &t2
->object
.oid
, "", &revs
->pruning
);
838 if (bloom_ret
== 1 && tree_difference
== REV_TREE_SAME
)
839 count_bloom_filter_false_positive
++;
841 return tree_difference
;
844 static int rev_same_tree_as_empty(struct rev_info
*revs
, struct commit
*commit
,
847 struct tree
*t1
= repo_get_commit_tree(the_repository
, commit
);
853 if (!nth_parent
&& revs
->bloom_keys_nr
) {
854 bloom_ret
= check_maybe_different_in_bloom_filter(revs
, commit
);
859 tree_difference
= REV_TREE_SAME
;
860 revs
->pruning
.flags
.has_changes
= 0;
861 diff_tree_oid(NULL
, &t1
->object
.oid
, "", &revs
->pruning
);
863 if (bloom_ret
== 1 && tree_difference
== REV_TREE_SAME
)
864 count_bloom_filter_false_positive
++;
866 return tree_difference
== REV_TREE_SAME
;
869 struct treesame_state
{
870 unsigned int nparents
;
871 unsigned char treesame
[FLEX_ARRAY
];
874 static struct treesame_state
*initialise_treesame(struct rev_info
*revs
, struct commit
*commit
)
876 unsigned n
= commit_list_count(commit
->parents
);
877 struct treesame_state
*st
= xcalloc(1, st_add(sizeof(*st
), n
));
879 add_decoration(&revs
->treesame
, &commit
->object
, st
);
884 * Must be called immediately after removing the nth_parent from a commit's
885 * parent list, if we are maintaining the per-parent treesame[] decoration.
886 * This does not recalculate the master TREESAME flag - update_treesame()
887 * should be called to update it after a sequence of treesame[] modifications
888 * that may have affected it.
890 static int compact_treesame(struct rev_info
*revs
, struct commit
*commit
, unsigned nth_parent
)
892 struct treesame_state
*st
;
895 if (!commit
->parents
) {
897 * Have just removed the only parent from a non-merge.
898 * Different handling, as we lack decoration.
901 die("compact_treesame %u", nth_parent
);
902 old_same
= !!(commit
->object
.flags
& TREESAME
);
903 if (rev_same_tree_as_empty(revs
, commit
, nth_parent
))
904 commit
->object
.flags
|= TREESAME
;
906 commit
->object
.flags
&= ~TREESAME
;
910 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
911 if (!st
|| nth_parent
>= st
->nparents
)
912 die("compact_treesame %u", nth_parent
);
914 old_same
= st
->treesame
[nth_parent
];
915 memmove(st
->treesame
+ nth_parent
,
916 st
->treesame
+ nth_parent
+ 1,
917 st
->nparents
- nth_parent
- 1);
920 * If we've just become a non-merge commit, update TREESAME
921 * immediately, and remove the no-longer-needed decoration.
922 * If still a merge, defer update until update_treesame().
924 if (--st
->nparents
== 1) {
925 if (commit
->parents
->next
)
926 die("compact_treesame parents mismatch");
927 if (st
->treesame
[0] && revs
->dense
)
928 commit
->object
.flags
|= TREESAME
;
930 commit
->object
.flags
&= ~TREESAME
;
931 free(add_decoration(&revs
->treesame
, &commit
->object
, NULL
));
937 static unsigned update_treesame(struct rev_info
*revs
, struct commit
*commit
)
939 if (commit
->parents
&& commit
->parents
->next
) {
941 struct treesame_state
*st
;
942 struct commit_list
*p
;
943 unsigned relevant_parents
;
944 unsigned relevant_change
, irrelevant_change
;
946 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
948 die("update_treesame %s", oid_to_hex(&commit
->object
.oid
));
949 relevant_parents
= 0;
950 relevant_change
= irrelevant_change
= 0;
951 for (p
= commit
->parents
, n
= 0; p
; n
++, p
= p
->next
) {
952 if (relevant_commit(p
->item
)) {
953 relevant_change
|= !st
->treesame
[n
];
956 irrelevant_change
|= !st
->treesame
[n
];
958 if (relevant_parents
? relevant_change
: irrelevant_change
)
959 commit
->object
.flags
&= ~TREESAME
;
961 commit
->object
.flags
|= TREESAME
;
964 return commit
->object
.flags
& TREESAME
;
967 static inline int limiting_can_increase_treesame(const struct rev_info
*revs
)
970 * TREESAME is irrelevant unless prune && dense;
971 * if simplify_history is set, we can't have a mixture of TREESAME and
972 * !TREESAME INTERESTING parents (and we don't have treesame[]
973 * decoration anyway);
974 * if first_parent_only is set, then the TREESAME flag is locked
975 * against the first parent (and again we lack treesame[] decoration).
977 return revs
->prune
&& revs
->dense
&&
978 !revs
->simplify_history
&&
979 !revs
->first_parent_only
;
982 static void try_to_simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
984 struct commit_list
**pp
, *parent
;
985 struct treesame_state
*ts
= NULL
;
986 int relevant_change
= 0, irrelevant_change
= 0;
987 int relevant_parents
, nth_parent
;
990 * If we don't do pruning, everything is interesting
995 if (!repo_get_commit_tree(the_repository
, commit
))
998 if (!commit
->parents
) {
1000 * Pretend as if we are comparing ourselves to the
1001 * (non-existent) first parent of this commit object. Even
1002 * though no such parent exists, its changed-path Bloom filter
1003 * (if one exists) is relative to the empty tree, using Bloom
1004 * filters is allowed here.
1006 if (rev_same_tree_as_empty(revs
, commit
, 0))
1007 commit
->object
.flags
|= TREESAME
;
1012 * Normal non-merge commit? If we don't want to make the
1013 * history dense, we consider it always to be a change..
1015 if (!revs
->dense
&& !commit
->parents
->next
)
1018 for (pp
= &commit
->parents
, nth_parent
= 0, relevant_parents
= 0;
1019 (parent
= *pp
) != NULL
;
1020 pp
= &parent
->next
, nth_parent
++) {
1021 struct commit
*p
= parent
->item
;
1022 if (relevant_commit(p
))
1025 if (nth_parent
== 1) {
1027 * This our second loop iteration - so we now know
1028 * we're dealing with a merge.
1030 * Do not compare with later parents when we care only about
1031 * the first parent chain, in order to avoid derailing the
1032 * traversal to follow a side branch that brought everything
1033 * in the path we are limited to by the pathspec.
1035 if (revs
->first_parent_only
)
1038 * If this will remain a potentially-simplifiable
1039 * merge, remember per-parent treesame if needed.
1040 * Initialise the array with the comparison from our
1043 if (revs
->treesame
.name
&&
1044 !revs
->simplify_history
&&
1045 !(commit
->object
.flags
& UNINTERESTING
)) {
1046 ts
= initialise_treesame(revs
, commit
);
1047 if (!(irrelevant_change
|| relevant_change
))
1048 ts
->treesame
[0] = 1;
1051 if (repo_parse_commit(revs
->repo
, p
) < 0)
1052 die("cannot simplify commit %s (because of %s)",
1053 oid_to_hex(&commit
->object
.oid
),
1054 oid_to_hex(&p
->object
.oid
));
1055 switch (rev_compare_tree(revs
, p
, commit
, nth_parent
)) {
1057 if (!revs
->simplify_history
|| !relevant_commit(p
)) {
1058 /* Even if a merge with an uninteresting
1059 * side branch brought the entire change
1060 * we are interested in, we do not want
1061 * to lose the other branches of this
1062 * merge, so we just keep going.
1065 ts
->treesame
[nth_parent
] = 1;
1069 free_commit_list(parent
->next
);
1070 parent
->next
= NULL
;
1071 while (commit
->parents
!= parent
)
1072 pop_commit(&commit
->parents
);
1073 commit
->parents
= parent
;
1076 * A merge commit is a "diversion" if it is not
1077 * TREESAME to its first parent but is TREESAME
1078 * to a later parent. In the simplified history,
1079 * we "divert" the history walk to the later
1080 * parent. These commits are shown when "show_pulls"
1081 * is enabled, so do not mark the object as
1084 if (!revs
->show_pulls
|| !nth_parent
)
1085 commit
->object
.flags
|= TREESAME
;
1090 if (revs
->remove_empty_trees
&&
1091 rev_same_tree_as_empty(revs
, p
, nth_parent
)) {
1092 /* We are adding all the specified
1093 * paths from this parent, so the
1094 * history beyond this parent is not
1095 * interesting. Remove its parents
1096 * (they are grandparents for us).
1097 * IOW, we pretend this parent is a
1100 if (repo_parse_commit(revs
->repo
, p
) < 0)
1101 die("cannot simplify commit %s (invalid %s)",
1102 oid_to_hex(&commit
->object
.oid
),
1103 oid_to_hex(&p
->object
.oid
));
1104 free_commit_list(p
->parents
);
1109 case REV_TREE_DIFFERENT
:
1110 if (relevant_commit(p
))
1111 relevant_change
= 1;
1113 irrelevant_change
= 1;
1116 commit
->object
.flags
|= PULL_MERGE
;
1120 die("bad tree compare for commit %s", oid_to_hex(&commit
->object
.oid
));
1124 * TREESAME is straightforward for single-parent commits. For merge
1125 * commits, it is most useful to define it so that "irrelevant"
1126 * parents cannot make us !TREESAME - if we have any relevant
1127 * parents, then we only consider TREESAMEness with respect to them,
1128 * allowing irrelevant merges from uninteresting branches to be
1129 * simplified away. Only if we have only irrelevant parents do we
1130 * base TREESAME on them. Note that this logic is replicated in
1131 * update_treesame, which should be kept in sync.
1133 if (relevant_parents
? !relevant_change
: !irrelevant_change
)
1134 commit
->object
.flags
|= TREESAME
;
1137 static int process_parents(struct rev_info
*revs
, struct commit
*commit
,
1138 struct commit_list
**list
, struct prio_queue
*queue
)
1140 struct commit_list
*parent
= commit
->parents
;
1141 unsigned pass_flags
;
1143 if (commit
->object
.flags
& ADDED
)
1145 if (revs
->do_not_die_on_missing_objects
&&
1146 oidset_contains(&revs
->missing_commits
, &commit
->object
.oid
))
1148 commit
->object
.flags
|= ADDED
;
1150 if (revs
->include_check
&&
1151 !revs
->include_check(commit
, revs
->include_check_data
))
1155 * If the commit is uninteresting, don't try to
1156 * prune parents - we want the maximal uninteresting
1159 * Normally we haven't parsed the parent
1160 * yet, so we won't have a parent of a parent
1161 * here. However, it may turn out that we've
1162 * reached this commit some other way (where it
1163 * wasn't uninteresting), in which case we need
1164 * to mark its parents recursively too..
1166 if (commit
->object
.flags
& UNINTERESTING
) {
1168 struct commit
*p
= parent
->item
;
1169 parent
= parent
->next
;
1171 p
->object
.flags
|= UNINTERESTING
;
1172 if (repo_parse_commit_gently(revs
->repo
, p
, 1) < 0)
1175 mark_parents_uninteresting(revs
, p
);
1176 if (p
->object
.flags
& SEEN
)
1178 p
->object
.flags
|= (SEEN
| NOT_USER_GIVEN
);
1180 commit_list_insert_by_date(p
, list
);
1182 prio_queue_put(queue
, p
);
1183 if (revs
->exclude_first_parent_only
)
1190 * Ok, the commit wasn't uninteresting. Try to
1191 * simplify the commit history and find the parent
1192 * that has no differences in the path set if one exists.
1194 try_to_simplify_commit(revs
, commit
);
1199 pass_flags
= (commit
->object
.flags
& (SYMMETRIC_LEFT
| ANCESTRY_PATH
));
1201 for (parent
= commit
->parents
; parent
; parent
= parent
->next
) {
1202 struct commit
*p
= parent
->item
;
1203 int gently
= revs
->ignore_missing_links
||
1204 revs
->exclude_promisor_objects
||
1205 revs
->do_not_die_on_missing_objects
;
1206 if (repo_parse_commit_gently(revs
->repo
, p
, gently
) < 0) {
1207 if (revs
->exclude_promisor_objects
&&
1208 is_promisor_object(revs
->repo
, &p
->object
.oid
)) {
1209 if (revs
->first_parent_only
)
1214 if (revs
->do_not_die_on_missing_objects
)
1215 oidset_insert(&revs
->missing_commits
, &p
->object
.oid
);
1217 return -1; /* corrupt repository */
1219 if (revs
->sources
) {
1220 char **slot
= revision_sources_at(revs
->sources
, p
);
1223 *slot
= *revision_sources_at(revs
->sources
, commit
);
1225 p
->object
.flags
|= pass_flags
;
1226 if (!(p
->object
.flags
& SEEN
)) {
1227 p
->object
.flags
|= (SEEN
| NOT_USER_GIVEN
);
1229 commit_list_insert_by_date(p
, list
);
1231 prio_queue_put(queue
, p
);
1233 if (revs
->first_parent_only
)
1239 static void cherry_pick_list(struct commit_list
*list
, struct rev_info
*revs
)
1241 struct commit_list
*p
;
1242 int left_count
= 0, right_count
= 0;
1244 struct patch_ids ids
;
1245 unsigned cherry_flag
;
1247 /* First count the commits on the left and on the right */
1248 for (p
= list
; p
; p
= p
->next
) {
1249 struct commit
*commit
= p
->item
;
1250 unsigned flags
= commit
->object
.flags
;
1251 if (flags
& BOUNDARY
)
1253 else if (flags
& SYMMETRIC_LEFT
)
1259 if (!left_count
|| !right_count
)
1262 left_first
= left_count
< right_count
;
1263 init_patch_ids(revs
->repo
, &ids
);
1264 ids
.diffopts
.pathspec
= revs
->diffopt
.pathspec
;
1266 /* Compute patch-ids for one side */
1267 for (p
= list
; p
; p
= p
->next
) {
1268 struct commit
*commit
= p
->item
;
1269 unsigned flags
= commit
->object
.flags
;
1271 if (flags
& BOUNDARY
)
1274 * If we have fewer left, left_first is set and we omit
1275 * commits on the right branch in this loop. If we have
1276 * fewer right, we skip the left ones.
1278 if (left_first
!= !!(flags
& SYMMETRIC_LEFT
))
1280 add_commit_patch_id(commit
, &ids
);
1283 /* either cherry_mark or cherry_pick are true */
1284 cherry_flag
= revs
->cherry_mark
? PATCHSAME
: SHOWN
;
1286 /* Check the other side */
1287 for (p
= list
; p
; p
= p
->next
) {
1288 struct commit
*commit
= p
->item
;
1289 struct patch_id
*id
;
1290 unsigned flags
= commit
->object
.flags
;
1292 if (flags
& BOUNDARY
)
1295 * If we have fewer left, left_first is set and we omit
1296 * commits on the left branch in this loop.
1298 if (left_first
== !!(flags
& SYMMETRIC_LEFT
))
1302 * Have we seen the same patch id?
1304 id
= patch_id_iter_first(commit
, &ids
);
1308 commit
->object
.flags
|= cherry_flag
;
1310 id
->commit
->object
.flags
|= cherry_flag
;
1311 } while ((id
= patch_id_iter_next(id
, &ids
)));
1314 free_patch_ids(&ids
);
1317 /* How many extra uninteresting commits we want to see.. */
1320 static int still_interesting(struct commit_list
*src
, timestamp_t date
, int slop
,
1321 struct commit
**interesting_cache
)
1324 * No source list at all? We're definitely done..
1330 * Does the destination list contain entries with a date
1331 * before the source list? Definitely _not_ done.
1333 if (date
<= src
->item
->date
)
1337 * Does the source list still have interesting commits in
1338 * it? Definitely not done..
1340 if (!everybody_uninteresting(src
, interesting_cache
))
1343 /* Ok, we're closing in.. */
1348 * "rev-list --ancestry-path=C_0 [--ancestry-path=C_1 ...] A..B"
1349 * computes commits that are ancestors of B but not ancestors of A but
1350 * further limits the result to those that have any of C in their
1351 * ancestry path (i.e. are either ancestors of any of C, descendants
1352 * of any of C, or are any of C). If --ancestry-path is specified with
1353 * no commit, we use all bottom commits for C.
1355 * Before this function is called, ancestors of C will have already
1356 * been marked with ANCESTRY_PATH previously.
1358 * This takes the list of bottom commits and the result of "A..B"
1359 * without --ancestry-path, and limits the latter further to the ones
1360 * that have any of C in their ancestry path. Since the ancestors of C
1361 * have already been marked (a prerequisite of this function), we just
1362 * need to mark the descendants, then exclude any commit that does not
1363 * have any of these marks.
1365 static void limit_to_ancestry(struct commit_list
*bottoms
, struct commit_list
*list
)
1367 struct commit_list
*p
;
1368 struct commit_list
*rlist
= NULL
;
1372 * Reverse the list so that it will be likely that we would
1373 * process parents before children.
1375 for (p
= list
; p
; p
= p
->next
)
1376 commit_list_insert(p
->item
, &rlist
);
1378 for (p
= bottoms
; p
; p
= p
->next
)
1379 p
->item
->object
.flags
|= TMP_MARK
;
1382 * Mark the ones that can reach bottom commits in "list",
1383 * in a bottom-up fashion.
1387 for (p
= rlist
; p
; p
= p
->next
) {
1388 struct commit
*c
= p
->item
;
1389 struct commit_list
*parents
;
1390 if (c
->object
.flags
& (TMP_MARK
| UNINTERESTING
))
1392 for (parents
= c
->parents
;
1394 parents
= parents
->next
) {
1395 if (!(parents
->item
->object
.flags
& TMP_MARK
))
1397 c
->object
.flags
|= TMP_MARK
;
1402 } while (made_progress
);
1405 * NEEDSWORK: decide if we want to remove parents that are
1406 * not marked with TMP_MARK from commit->parents for commits
1407 * in the resulting list. We may not want to do that, though.
1411 * The ones that are not marked with either TMP_MARK or
1412 * ANCESTRY_PATH are uninteresting
1414 for (p
= list
; p
; p
= p
->next
) {
1415 struct commit
*c
= p
->item
;
1416 if (c
->object
.flags
& (TMP_MARK
| ANCESTRY_PATH
))
1418 c
->object
.flags
|= UNINTERESTING
;
1421 /* We are done with TMP_MARK and ANCESTRY_PATH */
1422 for (p
= list
; p
; p
= p
->next
)
1423 p
->item
->object
.flags
&= ~(TMP_MARK
| ANCESTRY_PATH
);
1424 for (p
= bottoms
; p
; p
= p
->next
)
1425 p
->item
->object
.flags
&= ~(TMP_MARK
| ANCESTRY_PATH
);
1426 free_commit_list(rlist
);
1430 * Before walking the history, add the set of "negative" refs the
1431 * caller has asked to exclude to the bottom list.
1433 * This is used to compute "rev-list --ancestry-path A..B", as we need
1434 * to filter the result of "A..B" further to the ones that can actually
1437 static void collect_bottom_commits(struct commit_list
*list
,
1438 struct commit_list
**bottom
)
1440 struct commit_list
*elem
;
1441 for (elem
= list
; elem
; elem
= elem
->next
)
1442 if (elem
->item
->object
.flags
& BOTTOM
)
1443 commit_list_insert(elem
->item
, bottom
);
1446 /* Assumes either left_only or right_only is set */
1447 static void limit_left_right(struct commit_list
*list
, struct rev_info
*revs
)
1449 struct commit_list
*p
;
1451 for (p
= list
; p
; p
= p
->next
) {
1452 struct commit
*commit
= p
->item
;
1454 if (revs
->right_only
) {
1455 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
1456 commit
->object
.flags
|= SHOWN
;
1457 } else /* revs->left_only is set */
1458 if (!(commit
->object
.flags
& SYMMETRIC_LEFT
))
1459 commit
->object
.flags
|= SHOWN
;
1463 static int limit_list(struct rev_info
*revs
)
1466 timestamp_t date
= TIME_MAX
;
1467 struct commit_list
*original_list
= revs
->commits
;
1468 struct commit_list
*newlist
= NULL
;
1469 struct commit_list
**p
= &newlist
;
1470 struct commit
*interesting_cache
= NULL
;
1472 if (revs
->ancestry_path_implicit_bottoms
) {
1473 collect_bottom_commits(original_list
,
1474 &revs
->ancestry_path_bottoms
);
1475 if (!revs
->ancestry_path_bottoms
)
1476 die("--ancestry-path given but there are no bottom commits");
1479 while (original_list
) {
1480 struct commit
*commit
= pop_commit(&original_list
);
1481 struct object
*obj
= &commit
->object
;
1482 show_early_output_fn_t show
;
1484 if (commit
== interesting_cache
)
1485 interesting_cache
= NULL
;
1487 if (revs
->max_age
!= -1 && (commit
->date
< revs
->max_age
))
1488 obj
->flags
|= UNINTERESTING
;
1489 if (process_parents(revs
, commit
, &original_list
, NULL
) < 0)
1491 if (obj
->flags
& UNINTERESTING
) {
1492 mark_parents_uninteresting(revs
, commit
);
1493 slop
= still_interesting(original_list
, date
, slop
, &interesting_cache
);
1498 if (revs
->min_age
!= -1 && (commit
->date
> revs
->min_age
) &&
1499 !revs
->line_level_traverse
)
1501 if (revs
->max_age_as_filter
!= -1 &&
1502 (commit
->date
< revs
->max_age_as_filter
) && !revs
->line_level_traverse
)
1504 date
= commit
->date
;
1505 p
= &commit_list_insert(commit
, p
)->next
;
1507 show
= show_early_output
;
1511 show(revs
, newlist
);
1512 show_early_output
= NULL
;
1514 if (revs
->cherry_pick
|| revs
->cherry_mark
)
1515 cherry_pick_list(newlist
, revs
);
1517 if (revs
->left_only
|| revs
->right_only
)
1518 limit_left_right(newlist
, revs
);
1520 if (revs
->ancestry_path
)
1521 limit_to_ancestry(revs
->ancestry_path_bottoms
, newlist
);
1524 * Check if any commits have become TREESAME by some of their parents
1525 * becoming UNINTERESTING.
1527 if (limiting_can_increase_treesame(revs
)) {
1528 struct commit_list
*list
= NULL
;
1529 for (list
= newlist
; list
; list
= list
->next
) {
1530 struct commit
*c
= list
->item
;
1531 if (c
->object
.flags
& (UNINTERESTING
| TREESAME
))
1533 update_treesame(revs
, c
);
1537 free_commit_list(original_list
);
1538 revs
->commits
= newlist
;
1543 * Add an entry to refs->cmdline with the specified information.
1546 static void add_rev_cmdline(struct rev_info
*revs
,
1547 struct object
*item
,
1552 struct rev_cmdline_info
*info
= &revs
->cmdline
;
1553 unsigned int nr
= info
->nr
;
1555 ALLOC_GROW(info
->rev
, nr
+ 1, info
->alloc
);
1556 info
->rev
[nr
].item
= item
;
1557 info
->rev
[nr
].name
= xstrdup(name
);
1558 info
->rev
[nr
].whence
= whence
;
1559 info
->rev
[nr
].flags
= flags
;
1563 static void add_rev_cmdline_list(struct rev_info
*revs
,
1564 struct commit_list
*commit_list
,
1568 while (commit_list
) {
1569 struct object
*object
= &commit_list
->item
->object
;
1570 add_rev_cmdline(revs
, object
, oid_to_hex(&object
->oid
),
1572 commit_list
= commit_list
->next
;
1576 int ref_excluded(const struct ref_exclusions
*exclusions
, const char *path
)
1578 const char *stripped_path
= strip_namespace(path
);
1579 struct string_list_item
*item
;
1581 for_each_string_list_item(item
, &exclusions
->excluded_refs
) {
1582 if (!wildmatch(item
->string
, path
, 0))
1586 if (ref_is_hidden(stripped_path
, path
, &exclusions
->hidden_refs
))
1592 void init_ref_exclusions(struct ref_exclusions
*exclusions
)
1594 struct ref_exclusions blank
= REF_EXCLUSIONS_INIT
;
1595 memcpy(exclusions
, &blank
, sizeof(*exclusions
));
1598 void clear_ref_exclusions(struct ref_exclusions
*exclusions
)
1600 string_list_clear(&exclusions
->excluded_refs
, 0);
1601 strvec_clear(&exclusions
->hidden_refs
);
1602 exclusions
->hidden_refs_configured
= 0;
1605 void add_ref_exclusion(struct ref_exclusions
*exclusions
, const char *exclude
)
1607 string_list_append(&exclusions
->excluded_refs
, exclude
);
1610 struct exclude_hidden_refs_cb
{
1611 struct ref_exclusions
*exclusions
;
1612 const char *section
;
1615 static int hide_refs_config(const char *var
, const char *value
,
1616 const struct config_context
*ctx UNUSED
,
1619 struct exclude_hidden_refs_cb
*cb
= cb_data
;
1620 cb
->exclusions
->hidden_refs_configured
= 1;
1621 return parse_hide_refs_config(var
, value
, cb
->section
,
1622 &cb
->exclusions
->hidden_refs
);
1625 void exclude_hidden_refs(struct ref_exclusions
*exclusions
, const char *section
)
1627 struct exclude_hidden_refs_cb cb
;
1629 if (strcmp(section
, "fetch") && strcmp(section
, "receive") &&
1630 strcmp(section
, "uploadpack"))
1631 die(_("unsupported section for hidden refs: %s"), section
);
1633 if (exclusions
->hidden_refs_configured
)
1634 die(_("--exclude-hidden= passed more than once"));
1636 cb
.exclusions
= exclusions
;
1637 cb
.section
= section
;
1639 git_config(hide_refs_config
, &cb
);
1642 struct all_refs_cb
{
1644 int warned_bad_reflog
;
1645 struct rev_info
*all_revs
;
1646 const char *name_for_errormsg
;
1647 struct worktree
*wt
;
1650 static int handle_one_ref(const char *path
, const char *referent UNUSED
, const struct object_id
*oid
,
1654 struct all_refs_cb
*cb
= cb_data
;
1655 struct object
*object
;
1657 if (ref_excluded(&cb
->all_revs
->ref_excludes
, path
))
1660 object
= get_reference(cb
->all_revs
, path
, oid
, cb
->all_flags
);
1661 add_rev_cmdline(cb
->all_revs
, object
, path
, REV_CMD_REF
, cb
->all_flags
);
1662 add_pending_object(cb
->all_revs
, object
, path
);
1666 static void init_all_refs_cb(struct all_refs_cb
*cb
, struct rev_info
*revs
,
1669 cb
->all_revs
= revs
;
1670 cb
->all_flags
= flags
;
1671 revs
->rev_input_given
= 1;
1675 static void handle_refs(struct ref_store
*refs
,
1676 struct rev_info
*revs
, unsigned flags
,
1677 int (*for_each
)(struct ref_store
*, each_ref_fn
, void *))
1679 struct all_refs_cb cb
;
1682 /* this could happen with uninitialized submodules */
1686 init_all_refs_cb(&cb
, revs
, flags
);
1687 for_each(refs
, handle_one_ref
, &cb
);
1690 static void handle_one_reflog_commit(struct object_id
*oid
, void *cb_data
)
1692 struct all_refs_cb
*cb
= cb_data
;
1693 if (!is_null_oid(oid
)) {
1694 struct object
*o
= parse_object(cb
->all_revs
->repo
, oid
);
1696 o
->flags
|= cb
->all_flags
;
1697 /* ??? CMDLINEFLAGS ??? */
1698 add_pending_object(cb
->all_revs
, o
, "");
1700 else if (!cb
->warned_bad_reflog
) {
1701 warning("reflog of '%s' references pruned commits",
1702 cb
->name_for_errormsg
);
1703 cb
->warned_bad_reflog
= 1;
1708 static int handle_one_reflog_ent(struct object_id
*ooid
, struct object_id
*noid
,
1709 const char *email UNUSED
,
1710 timestamp_t timestamp UNUSED
,
1712 const char *message UNUSED
,
1715 handle_one_reflog_commit(ooid
, cb_data
);
1716 handle_one_reflog_commit(noid
, cb_data
);
1720 static int handle_one_reflog(const char *refname_in_wt
, void *cb_data
)
1722 struct all_refs_cb
*cb
= cb_data
;
1723 struct strbuf refname
= STRBUF_INIT
;
1725 cb
->warned_bad_reflog
= 0;
1726 strbuf_worktree_ref(cb
->wt
, &refname
, refname_in_wt
);
1727 cb
->name_for_errormsg
= refname
.buf
;
1728 refs_for_each_reflog_ent(get_main_ref_store(the_repository
),
1730 handle_one_reflog_ent
, cb_data
);
1731 strbuf_release(&refname
);
1735 static void add_other_reflogs_to_pending(struct all_refs_cb
*cb
)
1737 struct worktree
**worktrees
, **p
;
1739 worktrees
= get_worktrees();
1740 for (p
= worktrees
; *p
; p
++) {
1741 struct worktree
*wt
= *p
;
1747 refs_for_each_reflog(get_worktree_ref_store(wt
),
1751 free_worktrees(worktrees
);
1754 void add_reflogs_to_pending(struct rev_info
*revs
, unsigned flags
)
1756 struct all_refs_cb cb
;
1759 cb
.all_flags
= flags
;
1761 refs_for_each_reflog(get_main_ref_store(the_repository
),
1762 handle_one_reflog
, &cb
);
1764 if (!revs
->single_worktree
)
1765 add_other_reflogs_to_pending(&cb
);
1768 static void add_cache_tree(struct cache_tree
*it
, struct rev_info
*revs
,
1769 struct strbuf
*path
, unsigned int flags
)
1771 size_t baselen
= path
->len
;
1774 if (it
->entry_count
>= 0) {
1775 struct tree
*tree
= lookup_tree(revs
->repo
, &it
->oid
);
1776 tree
->object
.flags
|= flags
;
1777 add_pending_object_with_path(revs
, &tree
->object
, "",
1781 for (i
= 0; i
< it
->subtree_nr
; i
++) {
1782 struct cache_tree_sub
*sub
= it
->down
[i
];
1783 strbuf_addf(path
, "%s%s", baselen
? "/" : "", sub
->name
);
1784 add_cache_tree(sub
->cache_tree
, revs
, path
, flags
);
1785 strbuf_setlen(path
, baselen
);
1790 static void add_resolve_undo_to_pending(struct index_state
*istate
, struct rev_info
*revs
)
1792 struct string_list_item
*item
;
1793 struct string_list
*resolve_undo
= istate
->resolve_undo
;
1798 for_each_string_list_item(item
, resolve_undo
) {
1799 const char *path
= item
->string
;
1800 struct resolve_undo_info
*ru
= item
->util
;
1805 for (i
= 0; i
< 3; i
++) {
1808 if (!ru
->mode
[i
] || !S_ISREG(ru
->mode
[i
]))
1811 blob
= lookup_blob(revs
->repo
, &ru
->oid
[i
]);
1813 warning(_("resolve-undo records `%s` which is missing"),
1814 oid_to_hex(&ru
->oid
[i
]));
1817 add_pending_object_with_path(revs
, &blob
->object
, "",
1823 static void do_add_index_objects_to_pending(struct rev_info
*revs
,
1824 struct index_state
*istate
,
1829 /* TODO: audit for interaction with sparse-index. */
1830 ensure_full_index(istate
);
1831 for (i
= 0; i
< istate
->cache_nr
; i
++) {
1832 struct cache_entry
*ce
= istate
->cache
[i
];
1835 if (S_ISGITLINK(ce
->ce_mode
))
1838 blob
= lookup_blob(revs
->repo
, &ce
->oid
);
1840 die("unable to add index blob to traversal");
1841 blob
->object
.flags
|= flags
;
1842 add_pending_object_with_path(revs
, &blob
->object
, "",
1843 ce
->ce_mode
, ce
->name
);
1846 if (istate
->cache_tree
) {
1847 struct strbuf path
= STRBUF_INIT
;
1848 add_cache_tree(istate
->cache_tree
, revs
, &path
, flags
);
1849 strbuf_release(&path
);
1852 add_resolve_undo_to_pending(istate
, revs
);
1855 void add_index_objects_to_pending(struct rev_info
*revs
, unsigned int flags
)
1857 struct worktree
**worktrees
, **p
;
1859 repo_read_index(revs
->repo
);
1860 do_add_index_objects_to_pending(revs
, revs
->repo
->index
, flags
);
1862 if (revs
->single_worktree
)
1865 worktrees
= get_worktrees();
1866 for (p
= worktrees
; *p
; p
++) {
1867 struct worktree
*wt
= *p
;
1868 struct index_state istate
= INDEX_STATE_INIT(revs
->repo
);
1872 continue; /* current index already taken care of */
1874 wt_gitdir
= get_worktree_git_dir(wt
);
1876 if (read_index_from(&istate
,
1877 worktree_git_path(the_repository
, wt
, "index"),
1879 do_add_index_objects_to_pending(revs
, &istate
, flags
);
1881 discard_index(&istate
);
1884 free_worktrees(worktrees
);
1887 struct add_alternate_refs_data
{
1888 struct rev_info
*revs
;
1892 static void add_one_alternate_ref(const struct object_id
*oid
,
1895 const char *name
= ".alternate";
1896 struct add_alternate_refs_data
*data
= vdata
;
1899 obj
= get_reference(data
->revs
, name
, oid
, data
->flags
);
1900 add_rev_cmdline(data
->revs
, obj
, name
, REV_CMD_REV
, data
->flags
);
1901 add_pending_object(data
->revs
, obj
, name
);
1904 static void add_alternate_refs_to_pending(struct rev_info
*revs
,
1907 struct add_alternate_refs_data data
;
1910 for_each_alternate_ref(add_one_alternate_ref
, &data
);
1913 static int add_parents_only(struct rev_info
*revs
, const char *arg_
, int flags
,
1916 struct object_id oid
;
1918 struct commit
*commit
;
1919 struct commit_list
*parents
;
1921 const char *arg
= arg_
;
1924 flags
^= UNINTERESTING
| BOTTOM
;
1927 if (repo_get_oid_committish(the_repository
, arg
, &oid
))
1930 it
= get_reference(revs
, arg
, &oid
, 0);
1931 if (!it
&& revs
->ignore_missing
)
1933 if (it
->type
!= OBJ_TAG
)
1935 if (!((struct tag
*)it
)->tagged
)
1937 oidcpy(&oid
, &((struct tag
*)it
)->tagged
->oid
);
1939 if (it
->type
!= OBJ_COMMIT
)
1941 commit
= (struct commit
*)it
;
1942 if (exclude_parent
&&
1943 exclude_parent
> commit_list_count(commit
->parents
))
1945 for (parents
= commit
->parents
, parent_number
= 1;
1947 parents
= parents
->next
, parent_number
++) {
1948 if (exclude_parent
&& parent_number
!= exclude_parent
)
1951 it
= &parents
->item
->object
;
1953 add_rev_cmdline(revs
, it
, arg_
, REV_CMD_PARENTS_ONLY
, flags
);
1954 add_pending_object(revs
, it
, arg
);
1959 void repo_init_revisions(struct repository
*r
,
1960 struct rev_info
*revs
,
1963 struct rev_info blank
= REV_INFO_INIT
;
1964 memcpy(revs
, &blank
, sizeof(*revs
));
1967 revs
->pruning
.repo
= r
;
1968 revs
->pruning
.add_remove
= file_add_remove
;
1969 revs
->pruning
.change
= file_change
;
1970 revs
->pruning
.change_fn_data
= revs
;
1971 revs
->prefix
= prefix
;
1973 grep_init(&revs
->grep_filter
, revs
->repo
);
1974 revs
->grep_filter
.status_only
= 1;
1976 repo_diff_setup(revs
->repo
, &revs
->diffopt
);
1977 if (prefix
&& !revs
->diffopt
.prefix
) {
1978 revs
->diffopt
.prefix
= prefix
;
1979 revs
->diffopt
.prefix_length
= strlen(prefix
);
1982 init_display_notes(&revs
->notes_opt
);
1983 list_objects_filter_init(&revs
->filter
);
1984 init_ref_exclusions(&revs
->ref_excludes
);
1985 oidset_init(&revs
->missing_commits
, 0);
1988 static void add_pending_commit_list(struct rev_info
*revs
,
1989 struct commit_list
*commit_list
,
1992 while (commit_list
) {
1993 struct object
*object
= &commit_list
->item
->object
;
1994 object
->flags
|= flags
;
1995 add_pending_object(revs
, object
, oid_to_hex(&object
->oid
));
1996 commit_list
= commit_list
->next
;
2000 static const char *lookup_other_head(struct object_id
*oid
)
2003 static const char *const other_head
[] = {
2004 "MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "REBASE_HEAD"
2007 for (i
= 0; i
< ARRAY_SIZE(other_head
); i
++)
2008 if (!refs_read_ref_full(get_main_ref_store(the_repository
), other_head
[i
],
2009 RESOLVE_REF_READING
| RESOLVE_REF_NO_RECURSE
,
2011 if (is_null_oid(oid
))
2012 die(_("%s exists but is a symbolic ref"), other_head
[i
]);
2013 return other_head
[i
];
2016 die(_("--merge requires one of the pseudorefs MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD or REBASE_HEAD"));
2019 static void prepare_show_merge(struct rev_info
*revs
)
2021 struct commit_list
*bases
= NULL
;
2022 struct commit
*head
, *other
;
2023 struct object_id oid
;
2024 const char *other_name
;
2025 const char **prune
= NULL
;
2026 int i
, prune_num
= 1; /* counting terminating NULL */
2027 struct index_state
*istate
= revs
->repo
->index
;
2029 if (repo_get_oid(the_repository
, "HEAD", &oid
))
2030 die("--merge without HEAD?");
2031 head
= lookup_commit_or_die(&oid
, "HEAD");
2032 other_name
= lookup_other_head(&oid
);
2033 other
= lookup_commit_or_die(&oid
, other_name
);
2034 add_pending_object(revs
, &head
->object
, "HEAD");
2035 add_pending_object(revs
, &other
->object
, other_name
);
2036 if (repo_get_merge_bases(the_repository
, head
, other
, &bases
) < 0)
2038 add_rev_cmdline_list(revs
, bases
, REV_CMD_MERGE_BASE
, UNINTERESTING
| BOTTOM
);
2039 add_pending_commit_list(revs
, bases
, UNINTERESTING
| BOTTOM
);
2040 free_commit_list(bases
);
2041 head
->object
.flags
|= SYMMETRIC_LEFT
;
2043 if (!istate
->cache_nr
)
2044 repo_read_index(revs
->repo
);
2045 for (i
= 0; i
< istate
->cache_nr
; i
++) {
2046 const struct cache_entry
*ce
= istate
->cache
[i
];
2049 if (ce_path_match(istate
, ce
, &revs
->prune_data
, NULL
)) {
2051 REALLOC_ARRAY(prune
, prune_num
);
2052 prune
[prune_num
-2] = ce
->name
;
2053 prune
[prune_num
-1] = NULL
;
2055 while ((i
+1 < istate
->cache_nr
) &&
2056 ce_same_name(ce
, istate
->cache
[i
+1]))
2059 clear_pathspec(&revs
->prune_data
);
2060 parse_pathspec(&revs
->prune_data
, PATHSPEC_ALL_MAGIC
& ~PATHSPEC_LITERAL
,
2061 PATHSPEC_PREFER_FULL
| PATHSPEC_LITERAL_PATH
, "", prune
);
2066 static int dotdot_missing(const char *arg
, char *dotdot
,
2067 struct rev_info
*revs
, int symmetric
)
2069 if (revs
->ignore_missing
)
2071 /* de-munge so we report the full argument */
2074 ? "Invalid symmetric difference expression %s"
2075 : "Invalid revision range %s", arg
);
2078 static int handle_dotdot_1(const char *arg
, char *dotdot
,
2079 struct rev_info
*revs
, int flags
,
2080 int cant_be_filename
,
2081 struct object_context
*a_oc
,
2082 struct object_context
*b_oc
)
2084 const char *a_name
, *b_name
;
2085 struct object_id a_oid
, b_oid
;
2086 struct object
*a_obj
, *b_obj
;
2087 unsigned int a_flags
, b_flags
;
2089 unsigned int flags_exclude
= flags
^ (UNINTERESTING
| BOTTOM
);
2090 unsigned int oc_flags
= GET_OID_COMMITTISH
| GET_OID_RECORD_PATH
;
2096 b_name
= dotdot
+ 2;
2097 if (*b_name
== '.') {
2104 if (get_oid_with_context(revs
->repo
, a_name
, oc_flags
, &a_oid
, a_oc
) ||
2105 get_oid_with_context(revs
->repo
, b_name
, oc_flags
, &b_oid
, b_oc
))
2108 if (!cant_be_filename
) {
2110 verify_non_filename(revs
->prefix
, arg
);
2114 a_obj
= parse_object(revs
->repo
, &a_oid
);
2115 b_obj
= parse_object(revs
->repo
, &b_oid
);
2116 if (!a_obj
|| !b_obj
)
2117 return dotdot_missing(arg
, dotdot
, revs
, symmetric
);
2122 a_flags
= flags_exclude
;
2124 /* A...B -- find merge bases between the two */
2125 struct commit
*a
, *b
;
2126 struct commit_list
*exclude
= NULL
;
2128 a
= lookup_commit_reference(revs
->repo
, &a_obj
->oid
);
2129 b
= lookup_commit_reference(revs
->repo
, &b_obj
->oid
);
2131 return dotdot_missing(arg
, dotdot
, revs
, symmetric
);
2133 if (repo_get_merge_bases(the_repository
, a
, b
, &exclude
) < 0) {
2134 free_commit_list(exclude
);
2137 add_rev_cmdline_list(revs
, exclude
, REV_CMD_MERGE_BASE
,
2139 add_pending_commit_list(revs
, exclude
, flags_exclude
);
2140 free_commit_list(exclude
);
2143 a_flags
= flags
| SYMMETRIC_LEFT
;
2146 a_obj
->flags
|= a_flags
;
2147 b_obj
->flags
|= b_flags
;
2148 add_rev_cmdline(revs
, a_obj
, a_name
, REV_CMD_LEFT
, a_flags
);
2149 add_rev_cmdline(revs
, b_obj
, b_name
, REV_CMD_RIGHT
, b_flags
);
2150 add_pending_object_with_path(revs
, a_obj
, a_name
, a_oc
->mode
, a_oc
->path
);
2151 add_pending_object_with_path(revs
, b_obj
, b_name
, b_oc
->mode
, b_oc
->path
);
2155 static int handle_dotdot(const char *arg
,
2156 struct rev_info
*revs
, int flags
,
2157 int cant_be_filename
)
2159 struct object_context a_oc
= {0}, b_oc
= {0};
2160 char *dotdot
= strstr(arg
, "..");
2167 ret
= handle_dotdot_1(arg
, dotdot
, revs
, flags
, cant_be_filename
,
2171 object_context_release(&a_oc
);
2172 object_context_release(&b_oc
);
2176 static int handle_revision_arg_1(const char *arg_
, struct rev_info
*revs
, int flags
, unsigned revarg_opt
)
2178 struct object_context oc
= {0};
2180 struct object
*object
;
2181 struct object_id oid
;
2183 const char *arg
= arg_
;
2184 int cant_be_filename
= revarg_opt
& REVARG_CANNOT_BE_FILENAME
;
2185 unsigned get_sha1_flags
= GET_OID_RECORD_PATH
;
2188 flags
= flags
& UNINTERESTING
? flags
| BOTTOM
: flags
& ~BOTTOM
;
2190 if (!cant_be_filename
&& !strcmp(arg
, "..")) {
2192 * Just ".."? That is not a range but the
2193 * pathspec for the parent directory.
2199 if (!handle_dotdot(arg
, revs
, flags
, revarg_opt
)) {
2204 mark
= strstr(arg
, "^@");
2205 if (mark
&& !mark
[2]) {
2207 if (add_parents_only(revs
, arg
, flags
, 0)) {
2213 mark
= strstr(arg
, "^!");
2214 if (mark
&& !mark
[2]) {
2216 if (!add_parents_only(revs
, arg
, flags
^ (UNINTERESTING
| BOTTOM
), 0))
2219 mark
= strstr(arg
, "^-");
2221 int exclude_parent
= 1;
2224 if (strtol_i(mark
+ 2, 10, &exclude_parent
) ||
2225 exclude_parent
< 1) {
2232 if (!add_parents_only(revs
, arg
, flags
^ (UNINTERESTING
| BOTTOM
), exclude_parent
))
2238 local_flags
= UNINTERESTING
| BOTTOM
;
2242 if (revarg_opt
& REVARG_COMMITTISH
)
2243 get_sha1_flags
|= GET_OID_COMMITTISH
;
2246 * Even if revs->do_not_die_on_missing_objects is set, we
2247 * should error out if we can't even get an oid, as
2248 * `--missing=print` should be able to report missing oids.
2250 if (get_oid_with_context(revs
->repo
, arg
, get_sha1_flags
, &oid
, &oc
)) {
2251 ret
= revs
->ignore_missing
? 0 : -1;
2254 if (!cant_be_filename
)
2255 verify_non_filename(revs
->prefix
, arg
);
2256 object
= get_reference(revs
, arg
, &oid
, flags
^ local_flags
);
2258 ret
= (revs
->ignore_missing
|| revs
->do_not_die_on_missing_objects
) ? 0 : -1;
2261 add_rev_cmdline(revs
, object
, arg_
, REV_CMD_REV
, flags
^ local_flags
);
2262 add_pending_object_with_path(revs
, object
, arg
, oc
.mode
, oc
.path
);
2267 object_context_release(&oc
);
2271 int handle_revision_arg(const char *arg
, struct rev_info
*revs
, int flags
, unsigned revarg_opt
)
2273 int ret
= handle_revision_arg_1(arg
, revs
, flags
, revarg_opt
);
2275 revs
->rev_input_given
= 1;
2279 static void read_pathspec_from_stdin(struct strbuf
*sb
,
2280 struct strvec
*prune
)
2282 while (strbuf_getline(sb
, stdin
) != EOF
)
2283 strvec_push(prune
, sb
->buf
);
2286 static void add_grep(struct rev_info
*revs
, const char *ptn
, enum grep_pat_token what
)
2288 append_grep_pattern(&revs
->grep_filter
, ptn
, "command line", 0, what
);
2291 static void add_header_grep(struct rev_info
*revs
, enum grep_header_field field
, const char *pattern
)
2293 append_header_grep_pattern(&revs
->grep_filter
, field
, pattern
);
2296 static void add_message_grep(struct rev_info
*revs
, const char *pattern
)
2298 add_grep(revs
, pattern
, GREP_PATTERN_BODY
);
2301 static int parse_count(const char *arg
)
2305 if (strtol_i(arg
, 10, &count
) < 0)
2306 die("'%s': not an integer", arg
);
2310 static timestamp_t
parse_age(const char *arg
)
2316 num
= parse_timestamp(arg
, &p
, 10);
2317 if (errno
|| *p
|| p
== arg
)
2318 die("'%s': not a number of seconds since epoch", arg
);
2322 static int handle_revision_opt(struct rev_info
*revs
, int argc
, const char **argv
,
2323 int *unkc
, const char **unkv
,
2324 const struct setup_revision_opt
* opt
)
2326 const char *arg
= argv
[0];
2327 const char *optarg
= NULL
;
2329 const unsigned hexsz
= the_hash_algo
->hexsz
;
2331 /* pseudo revision arguments */
2332 if (!strcmp(arg
, "--all") || !strcmp(arg
, "--branches") ||
2333 !strcmp(arg
, "--tags") || !strcmp(arg
, "--remotes") ||
2334 !strcmp(arg
, "--reflog") || !strcmp(arg
, "--not") ||
2335 !strcmp(arg
, "--no-walk") || !strcmp(arg
, "--do-walk") ||
2336 !strcmp(arg
, "--bisect") || starts_with(arg
, "--glob=") ||
2337 !strcmp(arg
, "--indexed-objects") ||
2338 !strcmp(arg
, "--alternate-refs") ||
2339 starts_with(arg
, "--exclude=") || starts_with(arg
, "--exclude-hidden=") ||
2340 starts_with(arg
, "--branches=") || starts_with(arg
, "--tags=") ||
2341 starts_with(arg
, "--remotes=") || starts_with(arg
, "--no-walk="))
2343 unkv
[(*unkc
)++] = arg
;
2347 if ((argcount
= parse_long_opt("max-count", argv
, &optarg
))) {
2348 revs
->max_count
= parse_count(optarg
);
2351 } else if ((argcount
= parse_long_opt("skip", argv
, &optarg
))) {
2352 revs
->skip_count
= parse_count(optarg
);
2354 } else if ((*arg
== '-') && isdigit(arg
[1])) {
2355 /* accept -<digit>, like traditional "head" */
2356 revs
->max_count
= parse_count(arg
+ 1);
2358 } else if (!strcmp(arg
, "-n")) {
2360 return error("-n requires an argument");
2361 revs
->max_count
= parse_count(argv
[1]);
2364 } else if (skip_prefix(arg
, "-n", &optarg
)) {
2365 revs
->max_count
= parse_count(optarg
);
2367 } else if ((argcount
= parse_long_opt("max-age", argv
, &optarg
))) {
2368 revs
->max_age
= parse_age(optarg
);
2370 } else if ((argcount
= parse_long_opt("since", argv
, &optarg
))) {
2371 revs
->max_age
= approxidate(optarg
);
2373 } else if ((argcount
= parse_long_opt("since-as-filter", argv
, &optarg
))) {
2374 revs
->max_age_as_filter
= approxidate(optarg
);
2376 } else if ((argcount
= parse_long_opt("after", argv
, &optarg
))) {
2377 revs
->max_age
= approxidate(optarg
);
2379 } else if ((argcount
= parse_long_opt("min-age", argv
, &optarg
))) {
2380 revs
->min_age
= parse_age(optarg
);
2382 } else if ((argcount
= parse_long_opt("before", argv
, &optarg
))) {
2383 revs
->min_age
= approxidate(optarg
);
2385 } else if ((argcount
= parse_long_opt("until", argv
, &optarg
))) {
2386 revs
->min_age
= approxidate(optarg
);
2388 } else if (!strcmp(arg
, "--first-parent")) {
2389 revs
->first_parent_only
= 1;
2390 } else if (!strcmp(arg
, "--exclude-first-parent-only")) {
2391 revs
->exclude_first_parent_only
= 1;
2392 } else if (!strcmp(arg
, "--ancestry-path")) {
2393 revs
->ancestry_path
= 1;
2394 revs
->simplify_history
= 0;
2396 revs
->ancestry_path_implicit_bottoms
= 1;
2397 } else if (skip_prefix(arg
, "--ancestry-path=", &optarg
)) {
2399 struct object_id oid
;
2400 const char *msg
= _("could not get commit for --ancestry-path argument %s");
2402 revs
->ancestry_path
= 1;
2403 revs
->simplify_history
= 0;
2406 if (repo_get_oid_committish(revs
->repo
, optarg
, &oid
))
2407 return error(msg
, optarg
);
2408 get_reference(revs
, optarg
, &oid
, ANCESTRY_PATH
);
2409 c
= lookup_commit_reference(revs
->repo
, &oid
);
2411 return error(msg
, optarg
);
2412 commit_list_insert(c
, &revs
->ancestry_path_bottoms
);
2413 } else if (!strcmp(arg
, "-g") || !strcmp(arg
, "--walk-reflogs")) {
2414 init_reflog_walk(&revs
->reflog_info
);
2415 } else if (!strcmp(arg
, "--default")) {
2417 return error("bad --default argument");
2418 revs
->def
= argv
[1];
2420 } else if (!strcmp(arg
, "--merge")) {
2421 revs
->show_merge
= 1;
2422 } else if (!strcmp(arg
, "--topo-order")) {
2423 revs
->sort_order
= REV_SORT_IN_GRAPH_ORDER
;
2424 revs
->topo_order
= 1;
2425 } else if (!strcmp(arg
, "--simplify-merges")) {
2426 revs
->simplify_merges
= 1;
2427 revs
->topo_order
= 1;
2428 revs
->rewrite_parents
= 1;
2429 revs
->simplify_history
= 0;
2431 } else if (!strcmp(arg
, "--simplify-by-decoration")) {
2432 revs
->simplify_merges
= 1;
2433 revs
->topo_order
= 1;
2434 revs
->rewrite_parents
= 1;
2435 revs
->simplify_history
= 0;
2436 revs
->simplify_by_decoration
= 1;
2439 } else if (!strcmp(arg
, "--date-order")) {
2440 revs
->sort_order
= REV_SORT_BY_COMMIT_DATE
;
2441 revs
->topo_order
= 1;
2442 } else if (!strcmp(arg
, "--author-date-order")) {
2443 revs
->sort_order
= REV_SORT_BY_AUTHOR_DATE
;
2444 revs
->topo_order
= 1;
2445 } else if (!strcmp(arg
, "--early-output")) {
2446 revs
->early_output
= 100;
2447 revs
->topo_order
= 1;
2448 } else if (skip_prefix(arg
, "--early-output=", &optarg
)) {
2449 if (strtoul_ui(optarg
, 10, &revs
->early_output
) < 0)
2450 die("'%s': not a non-negative integer", optarg
);
2451 revs
->topo_order
= 1;
2452 } else if (!strcmp(arg
, "--parents")) {
2453 revs
->rewrite_parents
= 1;
2454 revs
->print_parents
= 1;
2455 } else if (!strcmp(arg
, "--dense")) {
2457 } else if (!strcmp(arg
, "--sparse")) {
2459 } else if (!strcmp(arg
, "--in-commit-order")) {
2460 revs
->tree_blobs_in_commit_order
= 1;
2461 } else if (!strcmp(arg
, "--remove-empty")) {
2462 revs
->remove_empty_trees
= 1;
2463 } else if (!strcmp(arg
, "--merges")) {
2464 revs
->min_parents
= 2;
2465 } else if (!strcmp(arg
, "--no-merges")) {
2466 revs
->max_parents
= 1;
2467 } else if (skip_prefix(arg
, "--min-parents=", &optarg
)) {
2468 revs
->min_parents
= parse_count(optarg
);
2469 } else if (!strcmp(arg
, "--no-min-parents")) {
2470 revs
->min_parents
= 0;
2471 } else if (skip_prefix(arg
, "--max-parents=", &optarg
)) {
2472 revs
->max_parents
= parse_count(optarg
);
2473 } else if (!strcmp(arg
, "--no-max-parents")) {
2474 revs
->max_parents
= -1;
2475 } else if (!strcmp(arg
, "--boundary")) {
2477 } else if (!strcmp(arg
, "--left-right")) {
2478 revs
->left_right
= 1;
2479 } else if (!strcmp(arg
, "--left-only")) {
2480 if (revs
->right_only
)
2481 die(_("options '%s' and '%s' cannot be used together"),
2482 "--left-only", "--right-only/--cherry");
2483 revs
->left_only
= 1;
2485 } else if (!strcmp(arg
, "--right-only")) {
2486 if (revs
->left_only
)
2487 die(_("options '%s' and '%s' cannot be used together"), "--right-only", "--left-only");
2488 revs
->right_only
= 1;
2490 } else if (!strcmp(arg
, "--cherry")) {
2491 if (revs
->left_only
)
2492 die(_("options '%s' and '%s' cannot be used together"), "--cherry", "--left-only");
2493 revs
->cherry_mark
= 1;
2494 revs
->right_only
= 1;
2495 revs
->max_parents
= 1;
2497 } else if (!strcmp(arg
, "--count")) {
2499 } else if (!strcmp(arg
, "--cherry-mark")) {
2500 if (revs
->cherry_pick
)
2501 die(_("options '%s' and '%s' cannot be used together"), "--cherry-mark", "--cherry-pick");
2502 revs
->cherry_mark
= 1;
2503 revs
->limited
= 1; /* needs limit_list() */
2504 } else if (!strcmp(arg
, "--cherry-pick")) {
2505 if (revs
->cherry_mark
)
2506 die(_("options '%s' and '%s' cannot be used together"), "--cherry-pick", "--cherry-mark");
2507 revs
->cherry_pick
= 1;
2509 } else if (!strcmp(arg
, "--objects")) {
2510 revs
->tag_objects
= 1;
2511 revs
->tree_objects
= 1;
2512 revs
->blob_objects
= 1;
2513 } else if (!strcmp(arg
, "--objects-edge")) {
2514 revs
->tag_objects
= 1;
2515 revs
->tree_objects
= 1;
2516 revs
->blob_objects
= 1;
2517 revs
->edge_hint
= 1;
2518 } else if (!strcmp(arg
, "--objects-edge-aggressive")) {
2519 revs
->tag_objects
= 1;
2520 revs
->tree_objects
= 1;
2521 revs
->blob_objects
= 1;
2522 revs
->edge_hint
= 1;
2523 revs
->edge_hint_aggressive
= 1;
2524 } else if (!strcmp(arg
, "--verify-objects")) {
2525 revs
->tag_objects
= 1;
2526 revs
->tree_objects
= 1;
2527 revs
->blob_objects
= 1;
2528 revs
->verify_objects
= 1;
2529 disable_commit_graph(revs
->repo
);
2530 } else if (!strcmp(arg
, "--unpacked")) {
2532 } else if (starts_with(arg
, "--unpacked=")) {
2533 die(_("--unpacked=<packfile> no longer supported"));
2534 } else if (!strcmp(arg
, "--no-kept-objects")) {
2535 revs
->no_kept_objects
= 1;
2536 revs
->keep_pack_cache_flags
|= IN_CORE_KEEP_PACKS
;
2537 revs
->keep_pack_cache_flags
|= ON_DISK_KEEP_PACKS
;
2538 } else if (skip_prefix(arg
, "--no-kept-objects=", &optarg
)) {
2539 revs
->no_kept_objects
= 1;
2540 if (!strcmp(optarg
, "in-core"))
2541 revs
->keep_pack_cache_flags
|= IN_CORE_KEEP_PACKS
;
2542 if (!strcmp(optarg
, "on-disk"))
2543 revs
->keep_pack_cache_flags
|= ON_DISK_KEEP_PACKS
;
2544 } else if (!strcmp(arg
, "-r")) {
2546 revs
->diffopt
.flags
.recursive
= 1;
2547 } else if (!strcmp(arg
, "-t")) {
2549 revs
->diffopt
.flags
.recursive
= 1;
2550 revs
->diffopt
.flags
.tree_in_recursive
= 1;
2551 } else if ((argcount
= diff_merges_parse_opts(revs
, argv
))) {
2553 } else if (!strcmp(arg
, "-v")) {
2554 revs
->verbose_header
= 1;
2555 } else if (!strcmp(arg
, "--pretty")) {
2556 revs
->verbose_header
= 1;
2557 revs
->pretty_given
= 1;
2558 get_commit_format(NULL
, revs
);
2559 } else if (skip_prefix(arg
, "--pretty=", &optarg
) ||
2560 skip_prefix(arg
, "--format=", &optarg
)) {
2562 * Detached form ("--pretty X" as opposed to "--pretty=X")
2563 * not allowed, since the argument is optional.
2565 revs
->verbose_header
= 1;
2566 revs
->pretty_given
= 1;
2567 get_commit_format(optarg
, revs
);
2568 } else if (!strcmp(arg
, "--expand-tabs")) {
2569 revs
->expand_tabs_in_log
= 8;
2570 } else if (!strcmp(arg
, "--no-expand-tabs")) {
2571 revs
->expand_tabs_in_log
= 0;
2572 } else if (skip_prefix(arg
, "--expand-tabs=", &arg
)) {
2574 if (strtol_i(arg
, 10, &val
) < 0 || val
< 0)
2575 die("'%s': not a non-negative integer", arg
);
2576 revs
->expand_tabs_in_log
= val
;
2577 } else if (!strcmp(arg
, "--show-notes") || !strcmp(arg
, "--notes")) {
2578 enable_default_display_notes(&revs
->notes_opt
, &revs
->show_notes
);
2579 revs
->show_notes_given
= 1;
2580 } else if (!strcmp(arg
, "--show-signature")) {
2581 revs
->show_signature
= 1;
2582 } else if (!strcmp(arg
, "--no-show-signature")) {
2583 revs
->show_signature
= 0;
2584 } else if (!strcmp(arg
, "--show-linear-break")) {
2585 revs
->break_bar
= " ..........";
2586 revs
->track_linear
= 1;
2587 revs
->track_first_time
= 1;
2588 } else if (skip_prefix(arg
, "--show-linear-break=", &optarg
)) {
2589 revs
->break_bar
= xstrdup(optarg
);
2590 revs
->track_linear
= 1;
2591 revs
->track_first_time
= 1;
2592 } else if (!strcmp(arg
, "--show-notes-by-default")) {
2593 revs
->show_notes_by_default
= 1;
2594 } else if (skip_prefix(arg
, "--show-notes=", &optarg
) ||
2595 skip_prefix(arg
, "--notes=", &optarg
)) {
2596 if (starts_with(arg
, "--show-notes=") &&
2597 revs
->notes_opt
.use_default_notes
< 0)
2598 revs
->notes_opt
.use_default_notes
= 1;
2599 enable_ref_display_notes(&revs
->notes_opt
, &revs
->show_notes
, optarg
);
2600 revs
->show_notes_given
= 1;
2601 } else if (!strcmp(arg
, "--no-notes")) {
2602 disable_display_notes(&revs
->notes_opt
, &revs
->show_notes
);
2603 revs
->show_notes_given
= 1;
2604 } else if (!strcmp(arg
, "--standard-notes")) {
2605 revs
->show_notes_given
= 1;
2606 revs
->notes_opt
.use_default_notes
= 1;
2607 } else if (!strcmp(arg
, "--no-standard-notes")) {
2608 revs
->notes_opt
.use_default_notes
= 0;
2609 } else if (!strcmp(arg
, "--oneline")) {
2610 revs
->verbose_header
= 1;
2611 get_commit_format("oneline", revs
);
2612 revs
->pretty_given
= 1;
2613 revs
->abbrev_commit
= 1;
2614 } else if (!strcmp(arg
, "--graph")) {
2615 graph_clear(revs
->graph
);
2616 revs
->graph
= graph_init(revs
);
2617 } else if (!strcmp(arg
, "--no-graph")) {
2618 graph_clear(revs
->graph
);
2620 } else if (!strcmp(arg
, "--encode-email-headers")) {
2621 revs
->encode_email_headers
= 1;
2622 } else if (!strcmp(arg
, "--no-encode-email-headers")) {
2623 revs
->encode_email_headers
= 0;
2624 } else if (!strcmp(arg
, "--root")) {
2625 revs
->show_root_diff
= 1;
2626 } else if (!strcmp(arg
, "--no-commit-id")) {
2627 revs
->no_commit_id
= 1;
2628 } else if (!strcmp(arg
, "--always")) {
2629 revs
->always_show_header
= 1;
2630 } else if (!strcmp(arg
, "--no-abbrev")) {
2632 } else if (!strcmp(arg
, "--abbrev")) {
2633 revs
->abbrev
= DEFAULT_ABBREV
;
2634 } else if (skip_prefix(arg
, "--abbrev=", &optarg
)) {
2635 revs
->abbrev
= strtoul(optarg
, NULL
, 10);
2636 if (revs
->abbrev
< MINIMUM_ABBREV
)
2637 revs
->abbrev
= MINIMUM_ABBREV
;
2638 else if (revs
->abbrev
> hexsz
)
2639 revs
->abbrev
= hexsz
;
2640 } else if (!strcmp(arg
, "--abbrev-commit")) {
2641 revs
->abbrev_commit
= 1;
2642 revs
->abbrev_commit_given
= 1;
2643 } else if (!strcmp(arg
, "--no-abbrev-commit")) {
2644 revs
->abbrev_commit
= 0;
2645 } else if (!strcmp(arg
, "--full-diff")) {
2647 revs
->full_diff
= 1;
2648 } else if (!strcmp(arg
, "--show-pulls")) {
2649 revs
->show_pulls
= 1;
2650 } else if (!strcmp(arg
, "--full-history")) {
2651 revs
->simplify_history
= 0;
2652 } else if (!strcmp(arg
, "--relative-date")) {
2653 revs
->date_mode
.type
= DATE_RELATIVE
;
2654 revs
->date_mode_explicit
= 1;
2655 } else if ((argcount
= parse_long_opt("date", argv
, &optarg
))) {
2656 parse_date_format(optarg
, &revs
->date_mode
);
2657 revs
->date_mode_explicit
= 1;
2659 } else if (!strcmp(arg
, "--log-size")) {
2660 revs
->show_log_size
= 1;
2663 * Grepping the commit log
2665 else if ((argcount
= parse_long_opt("author", argv
, &optarg
))) {
2666 add_header_grep(revs
, GREP_HEADER_AUTHOR
, optarg
);
2668 } else if ((argcount
= parse_long_opt("committer", argv
, &optarg
))) {
2669 add_header_grep(revs
, GREP_HEADER_COMMITTER
, optarg
);
2671 } else if ((argcount
= parse_long_opt("grep-reflog", argv
, &optarg
))) {
2672 add_header_grep(revs
, GREP_HEADER_REFLOG
, optarg
);
2674 } else if ((argcount
= parse_long_opt("grep", argv
, &optarg
))) {
2675 add_message_grep(revs
, optarg
);
2677 } else if (!strcmp(arg
, "--basic-regexp")) {
2678 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_BRE
;
2679 } else if (!strcmp(arg
, "--extended-regexp") || !strcmp(arg
, "-E")) {
2680 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_ERE
;
2681 } else if (!strcmp(arg
, "--regexp-ignore-case") || !strcmp(arg
, "-i")) {
2682 revs
->grep_filter
.ignore_case
= 1;
2683 revs
->diffopt
.pickaxe_opts
|= DIFF_PICKAXE_IGNORE_CASE
;
2684 } else if (!strcmp(arg
, "--fixed-strings") || !strcmp(arg
, "-F")) {
2685 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_FIXED
;
2686 } else if (!strcmp(arg
, "--perl-regexp") || !strcmp(arg
, "-P")) {
2687 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_PCRE
;
2688 } else if (!strcmp(arg
, "--all-match")) {
2689 revs
->grep_filter
.all_match
= 1;
2690 } else if (!strcmp(arg
, "--invert-grep")) {
2691 revs
->grep_filter
.no_body_match
= 1;
2692 } else if ((argcount
= parse_long_opt("encoding", argv
, &optarg
))) {
2693 free(git_log_output_encoding
);
2694 if (strcmp(optarg
, "none"))
2695 git_log_output_encoding
= xstrdup(optarg
);
2697 git_log_output_encoding
= xstrdup("");
2699 } else if (!strcmp(arg
, "--reverse")) {
2701 } else if (!strcmp(arg
, "--children")) {
2702 revs
->children
.name
= "children";
2704 } else if (!strcmp(arg
, "--ignore-missing")) {
2705 revs
->ignore_missing
= 1;
2706 } else if (opt
&& opt
->allow_exclude_promisor_objects
&&
2707 !strcmp(arg
, "--exclude-promisor-objects")) {
2708 if (fetch_if_missing
)
2709 BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0");
2710 revs
->exclude_promisor_objects
= 1;
2712 int opts
= diff_opt_parse(&revs
->diffopt
, argv
, argc
, revs
->prefix
);
2714 unkv
[(*unkc
)++] = arg
;
2721 void parse_revision_opt(struct rev_info
*revs
, struct parse_opt_ctx_t
*ctx
,
2722 const struct option
*options
,
2723 const char * const usagestr
[])
2725 int n
= handle_revision_opt(revs
, ctx
->argc
, ctx
->argv
,
2726 &ctx
->cpidx
, ctx
->out
, NULL
);
2728 error("unknown option `%s'", ctx
->argv
[0]);
2729 usage_with_options(usagestr
, options
);
2735 void revision_opts_finish(struct rev_info
*revs
)
2737 if (revs
->graph
&& revs
->track_linear
)
2738 die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");
2741 revs
->topo_order
= 1;
2742 revs
->rewrite_parents
= 1;
2746 static int for_each_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
,
2747 void *cb_data
, const char *term
)
2749 struct strbuf bisect_refs
= STRBUF_INIT
;
2751 strbuf_addf(&bisect_refs
, "refs/bisect/%s", term
);
2752 status
= refs_for_each_fullref_in(refs
, bisect_refs
.buf
, NULL
, fn
, cb_data
);
2753 strbuf_release(&bisect_refs
);
2757 static int for_each_bad_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
, void *cb_data
)
2759 return for_each_bisect_ref(refs
, fn
, cb_data
, term_bad
);
2762 static int for_each_good_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
, void *cb_data
)
2764 return for_each_bisect_ref(refs
, fn
, cb_data
, term_good
);
2767 static int handle_revision_pseudo_opt(struct rev_info
*revs
,
2768 const char **argv
, int *flags
)
2770 const char *arg
= argv
[0];
2772 struct ref_store
*refs
;
2775 if (revs
->repo
!= the_repository
) {
2777 * We need some something like get_submodule_worktrees()
2778 * before we can go through all worktrees of a submodule,
2779 * .e.g with adding all HEADs from --all, which is not
2780 * supported right now, so stick to single worktree.
2782 if (!revs
->single_worktree
)
2783 BUG("--single-worktree cannot be used together with submodule");
2785 refs
= get_main_ref_store(revs
->repo
);
2790 * Commands like "git shortlog" will not accept the options below
2791 * unless parse_revision_opt queues them (as opposed to erroring
2794 * When implementing your new pseudo-option, remember to
2795 * register it in the list at the top of handle_revision_opt.
2797 if (!strcmp(arg
, "--all")) {
2798 handle_refs(refs
, revs
, *flags
, refs_for_each_ref
);
2799 handle_refs(refs
, revs
, *flags
, refs_head_ref
);
2800 if (!revs
->single_worktree
) {
2801 struct all_refs_cb cb
;
2803 init_all_refs_cb(&cb
, revs
, *flags
);
2804 other_head_refs(handle_one_ref
, &cb
);
2806 clear_ref_exclusions(&revs
->ref_excludes
);
2807 } else if (!strcmp(arg
, "--branches")) {
2808 if (revs
->ref_excludes
.hidden_refs_configured
)
2809 return error(_("options '%s' and '%s' cannot be used together"),
2810 "--exclude-hidden", "--branches");
2811 handle_refs(refs
, revs
, *flags
, refs_for_each_branch_ref
);
2812 clear_ref_exclusions(&revs
->ref_excludes
);
2813 } else if (!strcmp(arg
, "--bisect")) {
2814 read_bisect_terms(&term_bad
, &term_good
);
2815 handle_refs(refs
, revs
, *flags
, for_each_bad_bisect_ref
);
2816 handle_refs(refs
, revs
, *flags
^ (UNINTERESTING
| BOTTOM
),
2817 for_each_good_bisect_ref
);
2819 } else if (!strcmp(arg
, "--tags")) {
2820 if (revs
->ref_excludes
.hidden_refs_configured
)
2821 return error(_("options '%s' and '%s' cannot be used together"),
2822 "--exclude-hidden", "--tags");
2823 handle_refs(refs
, revs
, *flags
, refs_for_each_tag_ref
);
2824 clear_ref_exclusions(&revs
->ref_excludes
);
2825 } else if (!strcmp(arg
, "--remotes")) {
2826 if (revs
->ref_excludes
.hidden_refs_configured
)
2827 return error(_("options '%s' and '%s' cannot be used together"),
2828 "--exclude-hidden", "--remotes");
2829 handle_refs(refs
, revs
, *flags
, refs_for_each_remote_ref
);
2830 clear_ref_exclusions(&revs
->ref_excludes
);
2831 } else if ((argcount
= parse_long_opt("glob", argv
, &optarg
))) {
2832 struct all_refs_cb cb
;
2833 init_all_refs_cb(&cb
, revs
, *flags
);
2834 refs_for_each_glob_ref(get_main_ref_store(the_repository
),
2835 handle_one_ref
, optarg
, &cb
);
2836 clear_ref_exclusions(&revs
->ref_excludes
);
2838 } else if ((argcount
= parse_long_opt("exclude", argv
, &optarg
))) {
2839 add_ref_exclusion(&revs
->ref_excludes
, optarg
);
2841 } else if ((argcount
= parse_long_opt("exclude-hidden", argv
, &optarg
))) {
2842 exclude_hidden_refs(&revs
->ref_excludes
, optarg
);
2844 } else if (skip_prefix(arg
, "--branches=", &optarg
)) {
2845 struct all_refs_cb cb
;
2846 if (revs
->ref_excludes
.hidden_refs_configured
)
2847 return error(_("options '%s' and '%s' cannot be used together"),
2848 "--exclude-hidden", "--branches");
2849 init_all_refs_cb(&cb
, revs
, *flags
);
2850 refs_for_each_glob_ref_in(get_main_ref_store(the_repository
),
2851 handle_one_ref
, optarg
,
2852 "refs/heads/", &cb
);
2853 clear_ref_exclusions(&revs
->ref_excludes
);
2854 } else if (skip_prefix(arg
, "--tags=", &optarg
)) {
2855 struct all_refs_cb cb
;
2856 if (revs
->ref_excludes
.hidden_refs_configured
)
2857 return error(_("options '%s' and '%s' cannot be used together"),
2858 "--exclude-hidden", "--tags");
2859 init_all_refs_cb(&cb
, revs
, *flags
);
2860 refs_for_each_glob_ref_in(get_main_ref_store(the_repository
),
2861 handle_one_ref
, optarg
,
2863 clear_ref_exclusions(&revs
->ref_excludes
);
2864 } else if (skip_prefix(arg
, "--remotes=", &optarg
)) {
2865 struct all_refs_cb cb
;
2866 if (revs
->ref_excludes
.hidden_refs_configured
)
2867 return error(_("options '%s' and '%s' cannot be used together"),
2868 "--exclude-hidden", "--remotes");
2869 init_all_refs_cb(&cb
, revs
, *flags
);
2870 refs_for_each_glob_ref_in(get_main_ref_store(the_repository
),
2871 handle_one_ref
, optarg
,
2872 "refs/remotes/", &cb
);
2873 clear_ref_exclusions(&revs
->ref_excludes
);
2874 } else if (!strcmp(arg
, "--reflog")) {
2875 add_reflogs_to_pending(revs
, *flags
);
2876 } else if (!strcmp(arg
, "--indexed-objects")) {
2877 add_index_objects_to_pending(revs
, *flags
);
2878 } else if (!strcmp(arg
, "--alternate-refs")) {
2879 add_alternate_refs_to_pending(revs
, *flags
);
2880 } else if (!strcmp(arg
, "--not")) {
2881 *flags
^= UNINTERESTING
| BOTTOM
;
2882 } else if (!strcmp(arg
, "--no-walk")) {
2884 } else if (skip_prefix(arg
, "--no-walk=", &optarg
)) {
2886 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
2887 * not allowed, since the argument is optional.
2890 if (!strcmp(optarg
, "sorted"))
2891 revs
->unsorted_input
= 0;
2892 else if (!strcmp(optarg
, "unsorted"))
2893 revs
->unsorted_input
= 1;
2895 return error("invalid argument to --no-walk");
2896 } else if (!strcmp(arg
, "--do-walk")) {
2898 } else if (!strcmp(arg
, "--single-worktree")) {
2899 revs
->single_worktree
= 1;
2900 } else if (skip_prefix(arg
, ("--filter="), &arg
)) {
2901 parse_list_objects_filter(&revs
->filter
, arg
);
2902 } else if (!strcmp(arg
, ("--no-filter"))) {
2903 list_objects_filter_set_no_filter(&revs
->filter
);
2911 static void read_revisions_from_stdin(struct rev_info
*revs
,
2912 struct strvec
*prune
)
2915 int seen_dashdash
= 0;
2916 int seen_end_of_options
= 0;
2920 save_warning
= warn_on_object_refname_ambiguity
;
2921 warn_on_object_refname_ambiguity
= 0;
2923 strbuf_init(&sb
, 1000);
2924 while (strbuf_getline(&sb
, stdin
) != EOF
) {
2928 if (!strcmp(sb
.buf
, "--")) {
2933 if (!seen_end_of_options
&& sb
.buf
[0] == '-') {
2934 const char *argv
[] = { sb
.buf
, NULL
};
2936 if (!strcmp(sb
.buf
, "--end-of-options")) {
2937 seen_end_of_options
= 1;
2941 if (handle_revision_pseudo_opt(revs
, argv
, &flags
) > 0)
2944 die(_("invalid option '%s' in --stdin mode"), sb
.buf
);
2947 if (handle_revision_arg(sb
.buf
, revs
, flags
,
2948 REVARG_CANNOT_BE_FILENAME
))
2949 die("bad revision '%s'", sb
.buf
);
2952 read_pathspec_from_stdin(&sb
, prune
);
2954 strbuf_release(&sb
);
2955 warn_on_object_refname_ambiguity
= save_warning
;
2958 static void NORETURN
diagnose_missing_default(const char *def
)
2961 const char *refname
;
2963 refname
= refs_resolve_ref_unsafe(get_main_ref_store(the_repository
),
2964 def
, 0, NULL
, &flags
);
2965 if (!refname
|| !(flags
& REF_ISSYMREF
) || (flags
& REF_ISBROKEN
))
2966 die(_("your current branch appears to be broken"));
2968 skip_prefix(refname
, "refs/heads/", &refname
);
2969 die(_("your current branch '%s' does not have any commits yet"),
2974 * Parse revision information, filling in the "rev_info" structure,
2975 * and removing the used arguments from the argument list.
2977 * Returns the number of arguments left that weren't recognized
2978 * (which are also moved to the head of the argument list)
2980 int setup_revisions(int argc
, const char **argv
, struct rev_info
*revs
, struct setup_revision_opt
*opt
)
2982 int i
, flags
, left
, seen_dashdash
, revarg_opt
;
2983 struct strvec prune_data
= STRVEC_INIT
;
2984 int seen_end_of_options
= 0;
2986 /* First, search for "--" */
2987 if (opt
&& opt
->assume_dashdash
) {
2991 for (i
= 1; i
< argc
; i
++) {
2992 const char *arg
= argv
[i
];
2993 if (strcmp(arg
, "--"))
2995 if (opt
&& opt
->free_removed_argv_elements
)
2996 free((char *)argv
[i
]);
3000 strvec_pushv(&prune_data
, argv
+ i
+ 1);
3006 /* Second, deal with arguments and options */
3008 revarg_opt
= opt
? opt
->revarg_opt
: 0;
3010 revarg_opt
|= REVARG_CANNOT_BE_FILENAME
;
3011 for (left
= i
= 1; i
< argc
; i
++) {
3012 const char *arg
= argv
[i
];
3013 if (!seen_end_of_options
&& *arg
== '-') {
3016 opts
= handle_revision_pseudo_opt(
3024 if (!strcmp(arg
, "--stdin")) {
3025 if (revs
->disable_stdin
) {
3029 if (revs
->read_from_stdin
++)
3030 die("--stdin given twice?");
3031 read_revisions_from_stdin(revs
, &prune_data
);
3035 if (!strcmp(arg
, "--end-of-options")) {
3036 seen_end_of_options
= 1;
3040 opts
= handle_revision_opt(revs
, argc
- i
, argv
+ i
,
3052 if (handle_revision_arg(arg
, revs
, flags
, revarg_opt
)) {
3054 if (seen_dashdash
|| *arg
== '^')
3055 die("bad revision '%s'", arg
);
3057 /* If we didn't have a "--":
3058 * (1) all filenames must exist;
3059 * (2) all rev-args must not be interpretable
3060 * as a valid filename.
3061 * but the latter we have checked in the main loop.
3063 for (j
= i
; j
< argc
; j
++)
3064 verify_filename(revs
->prefix
, argv
[j
], j
== i
);
3066 strvec_pushv(&prune_data
, argv
+ i
);
3070 revision_opts_finish(revs
);
3072 if (prune_data
.nr
) {
3074 * If we need to introduce the magic "a lone ':' means no
3075 * pathspec whatsoever", here is the place to do so.
3077 * if (prune_data.nr == 1 && !strcmp(prune_data[0], ":")) {
3078 * prune_data.nr = 0;
3079 * prune_data.alloc = 0;
3080 * free(prune_data.path);
3081 * prune_data.path = NULL;
3083 * terminate prune_data.alloc with NULL and
3084 * call init_pathspec() to set revs->prune_data here.
3087 parse_pathspec(&revs
->prune_data
, 0, 0,
3088 revs
->prefix
, prune_data
.v
);
3090 strvec_clear(&prune_data
);
3093 revs
->def
= opt
? opt
->def
: NULL
;
3094 if (opt
&& opt
->tweak
)
3096 if (revs
->show_merge
)
3097 prepare_show_merge(revs
);
3098 if (revs
->def
&& !revs
->pending
.nr
&& !revs
->rev_input_given
) {
3099 struct object_id oid
;
3100 struct object
*object
;
3101 struct object_context oc
;
3102 if (get_oid_with_context(revs
->repo
, revs
->def
, 0, &oid
, &oc
))
3103 diagnose_missing_default(revs
->def
);
3104 object
= get_reference(revs
, revs
->def
, &oid
, 0);
3105 add_pending_object_with_mode(revs
, object
, revs
->def
, oc
.mode
);
3106 object_context_release(&oc
);
3109 /* Did the user ask for any diff output? Run the diff! */
3110 if (revs
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
)
3113 /* Pickaxe, diff-filter and rename following need diffs */
3114 if ((revs
->diffopt
.pickaxe_opts
& DIFF_PICKAXE_KINDS_MASK
) ||
3115 revs
->diffopt
.filter
||
3116 revs
->diffopt
.flags
.follow_renames
)
3119 if (revs
->diffopt
.objfind
)
3120 revs
->simplify_history
= 0;
3122 if (revs
->line_level_traverse
) {
3123 if (want_ancestry(revs
))
3125 revs
->topo_order
= 1;
3128 if (revs
->topo_order
&& !generation_numbers_enabled(the_repository
))
3131 if (revs
->prune_data
.nr
) {
3132 copy_pathspec(&revs
->pruning
.pathspec
, &revs
->prune_data
);
3133 /* Can't prune commits with rename following: the paths change.. */
3134 if (!revs
->diffopt
.flags
.follow_renames
)
3136 if (!revs
->full_diff
)
3137 copy_pathspec(&revs
->diffopt
.pathspec
,
3141 diff_merges_setup_revs(revs
);
3143 revs
->diffopt
.abbrev
= revs
->abbrev
;
3145 diff_setup_done(&revs
->diffopt
);
3147 if (!is_encoding_utf8(get_log_output_encoding()))
3148 revs
->grep_filter
.ignore_locale
= 1;
3149 compile_grep_patterns(&revs
->grep_filter
);
3151 if (revs
->reflog_info
&& revs
->limited
)
3152 die("cannot combine --walk-reflogs with history-limiting options");
3153 if (revs
->rewrite_parents
&& revs
->children
.name
)
3154 die(_("options '%s' and '%s' cannot be used together"), "--parents", "--children");
3155 if (revs
->filter
.choice
&& !revs
->blob_objects
)
3156 die(_("object filtering requires --objects"));
3159 * Limitations on the graph functionality
3161 die_for_incompatible_opt3(!!revs
->graph
, "--graph",
3162 !!revs
->reverse
, "--reverse",
3163 !!revs
->reflog_info
, "--walk-reflogs");
3165 if (revs
->no_walk
&& revs
->graph
)
3166 die(_("options '%s' and '%s' cannot be used together"), "--no-walk", "--graph");
3167 if (!revs
->reflog_info
&& revs
->grep_filter
.use_reflog_filter
)
3168 die(_("the option '%s' requires '%s'"), "--grep-reflog", "--walk-reflogs");
3170 if (revs
->line_level_traverse
&&
3171 (revs
->diffopt
.output_format
& ~(DIFF_FORMAT_PATCH
| DIFF_FORMAT_NO_OUTPUT
)))
3172 die(_("-L does not yet support diff formats besides -p and -s"));
3174 if (revs
->expand_tabs_in_log
< 0)
3175 revs
->expand_tabs_in_log
= revs
->expand_tabs_in_log_default
;
3177 if (!revs
->show_notes_given
&& revs
->show_notes_by_default
) {
3178 enable_default_display_notes(&revs
->notes_opt
, &revs
->show_notes
);
3179 revs
->show_notes_given
= 1;
3185 static void release_revisions_cmdline(struct rev_cmdline_info
*cmdline
)
3189 for (i
= 0; i
< cmdline
->nr
; i
++)
3190 free((char *)cmdline
->rev
[i
].name
);
3194 static void release_revisions_mailmap(struct string_list
*mailmap
)
3198 clear_mailmap(mailmap
);
3202 static void release_revisions_topo_walk_info(struct topo_walk_info
*info
);
3204 static void free_void_commit_list(void *list
)
3206 free_commit_list(list
);
3209 void release_revisions(struct rev_info
*revs
)
3211 free_commit_list(revs
->commits
);
3212 free_commit_list(revs
->ancestry_path_bottoms
);
3213 release_display_notes(&revs
->notes_opt
);
3214 object_array_clear(&revs
->pending
);
3215 object_array_clear(&revs
->boundary_commits
);
3216 release_revisions_cmdline(&revs
->cmdline
);
3217 list_objects_filter_release(&revs
->filter
);
3218 clear_pathspec(&revs
->prune_data
);
3219 date_mode_release(&revs
->date_mode
);
3220 release_revisions_mailmap(revs
->mailmap
);
3221 free_grep_patterns(&revs
->grep_filter
);
3222 graph_clear(revs
->graph
);
3223 diff_free(&revs
->diffopt
);
3224 diff_free(&revs
->pruning
);
3225 reflog_walk_info_release(revs
->reflog_info
);
3226 release_revisions_topo_walk_info(revs
->topo_walk_info
);
3227 clear_decoration(&revs
->children
, free_void_commit_list
);
3228 clear_decoration(&revs
->merge_simplification
, free
);
3229 clear_decoration(&revs
->treesame
, free
);
3230 line_log_free(revs
);
3231 oidset_clear(&revs
->missing_commits
);
3233 for (int i
= 0; i
< revs
->bloom_keys_nr
; i
++)
3234 clear_bloom_key(&revs
->bloom_keys
[i
]);
3235 FREE_AND_NULL(revs
->bloom_keys
);
3236 revs
->bloom_keys_nr
= 0;
3239 static void add_child(struct rev_info
*revs
, struct commit
*parent
, struct commit
*child
)
3241 struct commit_list
*l
= xcalloc(1, sizeof(*l
));
3244 l
->next
= add_decoration(&revs
->children
, &parent
->object
, l
);
3247 static int remove_duplicate_parents(struct rev_info
*revs
, struct commit
*commit
)
3249 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
3250 struct commit_list
**pp
, *p
;
3251 int surviving_parents
;
3253 /* Examine existing parents while marking ones we have seen... */
3254 pp
= &commit
->parents
;
3255 surviving_parents
= 0;
3256 while ((p
= *pp
) != NULL
) {
3257 struct commit
*parent
= p
->item
;
3258 if (parent
->object
.flags
& TMP_MARK
) {
3262 compact_treesame(revs
, commit
, surviving_parents
);
3265 parent
->object
.flags
|= TMP_MARK
;
3266 surviving_parents
++;
3269 /* clear the temporary mark */
3270 for (p
= commit
->parents
; p
; p
= p
->next
) {
3271 p
->item
->object
.flags
&= ~TMP_MARK
;
3273 /* no update_treesame() - removing duplicates can't affect TREESAME */
3274 return surviving_parents
;
3277 struct merge_simplify_state
{
3278 struct commit
*simplified
;
3281 static struct merge_simplify_state
*locate_simplify_state(struct rev_info
*revs
, struct commit
*commit
)
3283 struct merge_simplify_state
*st
;
3285 st
= lookup_decoration(&revs
->merge_simplification
, &commit
->object
);
3287 CALLOC_ARRAY(st
, 1);
3288 add_decoration(&revs
->merge_simplification
, &commit
->object
, st
);
3293 static int mark_redundant_parents(struct commit
*commit
)
3295 struct commit_list
*h
= reduce_heads(commit
->parents
);
3296 int i
= 0, marked
= 0;
3297 struct commit_list
*po
, *pn
;
3299 /* Want these for sanity-checking only */
3300 int orig_cnt
= commit_list_count(commit
->parents
);
3301 int cnt
= commit_list_count(h
);
3304 * Not ready to remove items yet, just mark them for now, based
3305 * on the output of reduce_heads(). reduce_heads outputs the reduced
3306 * set in its original order, so this isn't too hard.
3308 po
= commit
->parents
;
3311 if (pn
&& po
->item
== pn
->item
) {
3315 po
->item
->object
.flags
|= TMP_MARK
;
3321 if (i
!= cnt
|| cnt
+marked
!= orig_cnt
)
3322 die("mark_redundant_parents %d %d %d %d", orig_cnt
, cnt
, i
, marked
);
3324 free_commit_list(h
);
3329 static int mark_treesame_root_parents(struct commit
*commit
)
3331 struct commit_list
*p
;
3334 for (p
= commit
->parents
; p
; p
= p
->next
) {
3335 struct commit
*parent
= p
->item
;
3336 if (!parent
->parents
&& (parent
->object
.flags
& TREESAME
)) {
3337 parent
->object
.flags
|= TMP_MARK
;
3346 * Awkward naming - this means one parent we are TREESAME to.
3347 * cf mark_treesame_root_parents: root parents that are TREESAME (to an
3348 * empty tree). Better name suggestions?
3350 static int leave_one_treesame_to_parent(struct rev_info
*revs
, struct commit
*commit
)
3352 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
3353 struct commit
*unmarked
= NULL
, *marked
= NULL
;
3354 struct commit_list
*p
;
3357 for (p
= commit
->parents
, n
= 0; p
; p
= p
->next
, n
++) {
3358 if (ts
->treesame
[n
]) {
3359 if (p
->item
->object
.flags
& TMP_MARK
) {
3372 * If we are TREESAME to a marked-for-deletion parent, but not to any
3373 * unmarked parents, unmark the first TREESAME parent. This is the
3374 * parent that the default simplify_history==1 scan would have followed,
3375 * and it doesn't make sense to omit that path when asking for a
3376 * simplified full history. Retaining it improves the chances of
3377 * understanding odd missed merges that took an old version of a file.
3381 * I--------*X A modified the file, but mainline merge X used
3382 * \ / "-s ours", so took the version from I. X is
3383 * `-*A--' TREESAME to I and !TREESAME to A.
3385 * Default log from X would produce "I". Without this check,
3386 * --full-history --simplify-merges would produce "I-A-X", showing
3387 * the merge commit X and that it changed A, but not making clear that
3388 * it had just taken the I version. With this check, the topology above
3391 * Note that it is possible that the simplification chooses a different
3392 * TREESAME parent from the default, in which case this test doesn't
3393 * activate, and we _do_ drop the default parent. Example:
3395 * I------X A modified the file, but it was reverted in B,
3396 * \ / meaning mainline merge X is TREESAME to both
3399 * Default log would produce "I" by following the first parent;
3400 * --full-history --simplify-merges will produce "I-A-B". But this is a
3401 * reasonable result - it presents a logical full history leading from
3402 * I to X, and X is not an important merge.
3404 if (!unmarked
&& marked
) {
3405 marked
->object
.flags
&= ~TMP_MARK
;
3412 static int remove_marked_parents(struct rev_info
*revs
, struct commit
*commit
)
3414 struct commit_list
**pp
, *p
;
3415 int nth_parent
, removed
= 0;
3417 pp
= &commit
->parents
;
3419 while ((p
= *pp
) != NULL
) {
3420 struct commit
*parent
= p
->item
;
3421 if (parent
->object
.flags
& TMP_MARK
) {
3422 parent
->object
.flags
&= ~TMP_MARK
;
3426 compact_treesame(revs
, commit
, nth_parent
);
3433 /* Removing parents can only increase TREESAMEness */
3434 if (removed
&& !(commit
->object
.flags
& TREESAME
))
3435 update_treesame(revs
, commit
);
3440 static struct commit_list
**simplify_one(struct rev_info
*revs
, struct commit
*commit
, struct commit_list
**tail
)
3442 struct commit_list
*p
;
3443 struct commit
*parent
;
3444 struct merge_simplify_state
*st
, *pst
;
3447 st
= locate_simplify_state(revs
, commit
);
3450 * Have we handled this one?
3456 * An UNINTERESTING commit simplifies to itself, so does a
3457 * root commit. We do not rewrite parents of such commit
3460 if ((commit
->object
.flags
& UNINTERESTING
) || !commit
->parents
) {
3461 st
->simplified
= commit
;
3466 * Do we know what commit all of our parents that matter
3467 * should be rewritten to? Otherwise we are not ready to
3468 * rewrite this one yet.
3470 for (cnt
= 0, p
= commit
->parents
; p
; p
= p
->next
) {
3471 pst
= locate_simplify_state(revs
, p
->item
);
3472 if (!pst
->simplified
) {
3473 tail
= &commit_list_insert(p
->item
, tail
)->next
;
3476 if (revs
->first_parent_only
)
3480 tail
= &commit_list_insert(commit
, tail
)->next
;
3485 * Rewrite our list of parents. Note that this cannot
3486 * affect our TREESAME flags in any way - a commit is
3487 * always TREESAME to its simplification.
3489 for (p
= commit
->parents
; p
; p
= p
->next
) {
3490 pst
= locate_simplify_state(revs
, p
->item
);
3491 p
->item
= pst
->simplified
;
3492 if (revs
->first_parent_only
)
3496 if (revs
->first_parent_only
)
3499 cnt
= remove_duplicate_parents(revs
, commit
);
3502 * It is possible that we are a merge and one side branch
3503 * does not have any commit that touches the given paths;
3504 * in such a case, the immediate parent from that branch
3505 * will be rewritten to be the merge base.
3507 * o----X X: the commit we are looking at;
3508 * / / o: a commit that touches the paths;
3511 * Further, a merge of an independent branch that doesn't
3512 * touch the path will reduce to a treesame root parent:
3514 * ----o----X X: the commit we are looking at;
3515 * / o: a commit that touches the paths;
3516 * r r: a root commit not touching the paths
3518 * Detect and simplify both cases.
3521 int marked
= mark_redundant_parents(commit
);
3522 marked
+= mark_treesame_root_parents(commit
);
3524 marked
-= leave_one_treesame_to_parent(revs
, commit
);
3526 cnt
= remove_marked_parents(revs
, commit
);
3530 * A commit simplifies to itself if it is a root, if it is
3531 * UNINTERESTING, if it touches the given paths, or if it is a
3532 * merge and its parents don't simplify to one relevant commit
3533 * (the first two cases are already handled at the beginning of
3536 * Otherwise, it simplifies to what its sole relevant parent
3540 (commit
->object
.flags
& UNINTERESTING
) ||
3541 !(commit
->object
.flags
& TREESAME
) ||
3542 (parent
= one_relevant_parent(revs
, commit
->parents
)) == NULL
||
3543 (revs
->show_pulls
&& (commit
->object
.flags
& PULL_MERGE
)))
3544 st
->simplified
= commit
;
3546 pst
= locate_simplify_state(revs
, parent
);
3547 st
->simplified
= pst
->simplified
;
3552 static void simplify_merges(struct rev_info
*revs
)
3554 struct commit_list
*list
, *next
;
3555 struct commit_list
*yet_to_do
, **tail
;
3556 struct commit
*commit
;
3561 /* feed the list reversed */
3563 for (list
= revs
->commits
; list
; list
= next
) {
3564 commit
= list
->item
;
3567 * Do not free(list) here yet; the original list
3568 * is used later in this function.
3570 commit_list_insert(commit
, &yet_to_do
);
3577 commit
= pop_commit(&list
);
3578 tail
= simplify_one(revs
, commit
, tail
);
3582 /* clean up the result, removing the simplified ones */
3583 list
= revs
->commits
;
3584 revs
->commits
= NULL
;
3585 tail
= &revs
->commits
;
3587 struct merge_simplify_state
*st
;
3589 commit
= pop_commit(&list
);
3590 st
= locate_simplify_state(revs
, commit
);
3591 if (st
->simplified
== commit
)
3592 tail
= &commit_list_insert(commit
, tail
)->next
;
3596 static void set_children(struct rev_info
*revs
)
3598 struct commit_list
*l
;
3599 for (l
= revs
->commits
; l
; l
= l
->next
) {
3600 struct commit
*commit
= l
->item
;
3601 struct commit_list
*p
;
3603 for (p
= commit
->parents
; p
; p
= p
->next
)
3604 add_child(revs
, p
->item
, commit
);
3608 void reset_revision_walk(void)
3610 clear_object_flags(the_repository
,
3611 SEEN
| ADDED
| SHOWN
| TOPO_WALK_EXPLORED
| TOPO_WALK_INDEGREE
);
3614 static int mark_uninteresting(const struct object_id
*oid
,
3615 struct packed_git
*pack UNUSED
,
3616 uint32_t pos UNUSED
,
3619 struct rev_info
*revs
= cb
;
3620 struct object
*o
= lookup_unknown_object(revs
->repo
, oid
);
3621 o
->flags
|= UNINTERESTING
| SEEN
;
3625 define_commit_slab(indegree_slab
, int);
3626 define_commit_slab(author_date_slab
, timestamp_t
);
3628 struct topo_walk_info
{
3629 timestamp_t min_generation
;
3630 struct prio_queue explore_queue
;
3631 struct prio_queue indegree_queue
;
3632 struct prio_queue topo_queue
;
3633 struct indegree_slab indegree
;
3634 struct author_date_slab author_date
;
3637 static int topo_walk_atexit_registered
;
3638 static unsigned int count_explore_walked
;
3639 static unsigned int count_indegree_walked
;
3640 static unsigned int count_topo_walked
;
3642 static void trace2_topo_walk_statistics_atexit(void)
3644 struct json_writer jw
= JSON_WRITER_INIT
;
3646 jw_object_begin(&jw
, 0);
3647 jw_object_intmax(&jw
, "count_explore_walked", count_explore_walked
);
3648 jw_object_intmax(&jw
, "count_indegree_walked", count_indegree_walked
);
3649 jw_object_intmax(&jw
, "count_topo_walked", count_topo_walked
);
3652 trace2_data_json("topo_walk", the_repository
, "statistics", &jw
);
3657 static inline void test_flag_and_insert(struct prio_queue
*q
, struct commit
*c
, int flag
)
3659 if (c
->object
.flags
& flag
)
3662 c
->object
.flags
|= flag
;
3663 prio_queue_put(q
, c
);
3666 static void explore_walk_step(struct rev_info
*revs
)
3668 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3669 struct commit_list
*p
;
3670 struct commit
*c
= prio_queue_get(&info
->explore_queue
);
3675 if (repo_parse_commit_gently(revs
->repo
, c
, 1) < 0)
3678 count_explore_walked
++;
3680 if (revs
->sort_order
== REV_SORT_BY_AUTHOR_DATE
)
3681 record_author_date(&info
->author_date
, c
);
3683 if (revs
->max_age
!= -1 && (c
->date
< revs
->max_age
))
3684 c
->object
.flags
|= UNINTERESTING
;
3686 if (process_parents(revs
, c
, NULL
, NULL
) < 0)
3689 if (c
->object
.flags
& UNINTERESTING
)
3690 mark_parents_uninteresting(revs
, c
);
3692 for (p
= c
->parents
; p
; p
= p
->next
)
3693 test_flag_and_insert(&info
->explore_queue
, p
->item
, TOPO_WALK_EXPLORED
);
3696 static void explore_to_depth(struct rev_info
*revs
,
3697 timestamp_t gen_cutoff
)
3699 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3701 while ((c
= prio_queue_peek(&info
->explore_queue
)) &&
3702 commit_graph_generation(c
) >= gen_cutoff
)
3703 explore_walk_step(revs
);
3706 static void indegree_walk_step(struct rev_info
*revs
)
3708 struct commit_list
*p
;
3709 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3710 struct commit
*c
= prio_queue_get(&info
->indegree_queue
);
3715 if (repo_parse_commit_gently(revs
->repo
, c
, 1) < 0)
3718 count_indegree_walked
++;
3720 explore_to_depth(revs
, commit_graph_generation(c
));
3722 for (p
= c
->parents
; p
; p
= p
->next
) {
3723 struct commit
*parent
= p
->item
;
3724 int *pi
= indegree_slab_at(&info
->indegree
, parent
);
3726 if (repo_parse_commit_gently(revs
->repo
, parent
, 1) < 0)
3734 test_flag_and_insert(&info
->indegree_queue
, parent
, TOPO_WALK_INDEGREE
);
3736 if (revs
->first_parent_only
)
3741 static void compute_indegrees_to_depth(struct rev_info
*revs
,
3742 timestamp_t gen_cutoff
)
3744 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3746 while ((c
= prio_queue_peek(&info
->indegree_queue
)) &&
3747 commit_graph_generation(c
) >= gen_cutoff
)
3748 indegree_walk_step(revs
);
3751 static void release_revisions_topo_walk_info(struct topo_walk_info
*info
)
3755 clear_prio_queue(&info
->explore_queue
);
3756 clear_prio_queue(&info
->indegree_queue
);
3757 clear_prio_queue(&info
->topo_queue
);
3758 clear_indegree_slab(&info
->indegree
);
3759 clear_author_date_slab(&info
->author_date
);
3763 static void reset_topo_walk(struct rev_info
*revs
)
3765 release_revisions_topo_walk_info(revs
->topo_walk_info
);
3766 revs
->topo_walk_info
= NULL
;
3769 static void init_topo_walk(struct rev_info
*revs
)
3771 struct topo_walk_info
*info
;
3772 struct commit_list
*list
;
3773 if (revs
->topo_walk_info
)
3774 reset_topo_walk(revs
);
3776 revs
->topo_walk_info
= xmalloc(sizeof(struct topo_walk_info
));
3777 info
= revs
->topo_walk_info
;
3778 memset(info
, 0, sizeof(struct topo_walk_info
));
3780 init_indegree_slab(&info
->indegree
);
3781 memset(&info
->explore_queue
, 0, sizeof(info
->explore_queue
));
3782 memset(&info
->indegree_queue
, 0, sizeof(info
->indegree_queue
));
3783 memset(&info
->topo_queue
, 0, sizeof(info
->topo_queue
));
3785 switch (revs
->sort_order
) {
3786 default: /* REV_SORT_IN_GRAPH_ORDER */
3787 info
->topo_queue
.compare
= NULL
;
3789 case REV_SORT_BY_COMMIT_DATE
:
3790 info
->topo_queue
.compare
= compare_commits_by_commit_date
;
3792 case REV_SORT_BY_AUTHOR_DATE
:
3793 init_author_date_slab(&info
->author_date
);
3794 info
->topo_queue
.compare
= compare_commits_by_author_date
;
3795 info
->topo_queue
.cb_data
= &info
->author_date
;
3799 info
->explore_queue
.compare
= compare_commits_by_gen_then_commit_date
;
3800 info
->indegree_queue
.compare
= compare_commits_by_gen_then_commit_date
;
3802 info
->min_generation
= GENERATION_NUMBER_INFINITY
;
3803 for (list
= revs
->commits
; list
; list
= list
->next
) {
3804 struct commit
*c
= list
->item
;
3805 timestamp_t generation
;
3807 if (repo_parse_commit_gently(revs
->repo
, c
, 1))
3810 test_flag_and_insert(&info
->explore_queue
, c
, TOPO_WALK_EXPLORED
);
3811 test_flag_and_insert(&info
->indegree_queue
, c
, TOPO_WALK_INDEGREE
);
3813 generation
= commit_graph_generation(c
);
3814 if (generation
< info
->min_generation
)
3815 info
->min_generation
= generation
;
3817 *(indegree_slab_at(&info
->indegree
, c
)) = 1;
3819 if (revs
->sort_order
== REV_SORT_BY_AUTHOR_DATE
)
3820 record_author_date(&info
->author_date
, c
);
3822 compute_indegrees_to_depth(revs
, info
->min_generation
);
3824 for (list
= revs
->commits
; list
; list
= list
->next
) {
3825 struct commit
*c
= list
->item
;
3827 if (*(indegree_slab_at(&info
->indegree
, c
)) == 1)
3828 prio_queue_put(&info
->topo_queue
, c
);
3832 * This is unfortunate; the initial tips need to be shown
3833 * in the order given from the revision traversal machinery.
3835 if (revs
->sort_order
== REV_SORT_IN_GRAPH_ORDER
)
3836 prio_queue_reverse(&info
->topo_queue
);
3838 if (trace2_is_enabled() && !topo_walk_atexit_registered
) {
3839 atexit(trace2_topo_walk_statistics_atexit
);
3840 topo_walk_atexit_registered
= 1;
3844 static struct commit
*next_topo_commit(struct rev_info
*revs
)
3847 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3849 /* pop next off of topo_queue */
3850 c
= prio_queue_get(&info
->topo_queue
);
3853 *(indegree_slab_at(&info
->indegree
, c
)) = 0;
3858 static void expand_topo_walk(struct rev_info
*revs
, struct commit
*commit
)
3860 struct commit_list
*p
;
3861 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3862 if (process_parents(revs
, commit
, NULL
, NULL
) < 0) {
3863 if (!revs
->ignore_missing_links
)
3864 die("Failed to traverse parents of commit %s",
3865 oid_to_hex(&commit
->object
.oid
));
3868 count_topo_walked
++;
3870 for (p
= commit
->parents
; p
; p
= p
->next
) {
3871 struct commit
*parent
= p
->item
;
3873 timestamp_t generation
;
3875 if (parent
->object
.flags
& UNINTERESTING
)
3878 if (repo_parse_commit_gently(revs
->repo
, parent
, 1) < 0)
3881 generation
= commit_graph_generation(parent
);
3882 if (generation
< info
->min_generation
) {
3883 info
->min_generation
= generation
;
3884 compute_indegrees_to_depth(revs
, info
->min_generation
);
3887 pi
= indegree_slab_at(&info
->indegree
, parent
);
3891 prio_queue_put(&info
->topo_queue
, parent
);
3893 if (revs
->first_parent_only
)
3898 int prepare_revision_walk(struct rev_info
*revs
)
3901 struct object_array old_pending
;
3902 struct commit_list
**next
= &revs
->commits
;
3904 memcpy(&old_pending
, &revs
->pending
, sizeof(old_pending
));
3905 revs
->pending
.nr
= 0;
3906 revs
->pending
.alloc
= 0;
3907 revs
->pending
.objects
= NULL
;
3908 for (i
= 0; i
< old_pending
.nr
; i
++) {
3909 struct object_array_entry
*e
= old_pending
.objects
+ i
;
3910 struct commit
*commit
= handle_commit(revs
, e
);
3912 if (!(commit
->object
.flags
& SEEN
)) {
3913 commit
->object
.flags
|= SEEN
;
3914 next
= commit_list_append(commit
, next
);
3918 object_array_clear(&old_pending
);
3920 /* Signal whether we need per-parent treesame decoration */
3921 if (revs
->simplify_merges
||
3922 (revs
->limited
&& limiting_can_increase_treesame(revs
)))
3923 revs
->treesame
.name
= "treesame";
3925 if (revs
->exclude_promisor_objects
) {
3926 for_each_packed_object(revs
->repo
, mark_uninteresting
, revs
,
3927 FOR_EACH_OBJECT_PROMISOR_ONLY
);
3930 if (!revs
->reflog_info
)
3931 prepare_to_use_bloom_filter(revs
);
3932 if (!revs
->unsorted_input
)
3933 commit_list_sort_by_date(&revs
->commits
);
3936 if (revs
->limited
) {
3937 if (limit_list(revs
) < 0)
3939 if (revs
->topo_order
)
3940 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
3941 } else if (revs
->topo_order
)
3942 init_topo_walk(revs
);
3943 if (revs
->line_level_traverse
&& want_ancestry(revs
))
3945 * At the moment we can only do line-level log with parent
3946 * rewriting by performing this expensive pre-filtering step.
3947 * If parent rewriting is not requested, then we rather
3948 * perform the line-level log filtering during the regular
3949 * history traversal.
3951 line_log_filter(revs
);
3952 if (revs
->simplify_merges
)
3953 simplify_merges(revs
);
3954 if (revs
->children
.name
)
3960 static enum rewrite_result
rewrite_one_1(struct rev_info
*revs
,
3962 struct prio_queue
*queue
)
3965 struct commit
*p
= *pp
;
3967 if (process_parents(revs
, p
, NULL
, queue
) < 0)
3968 return rewrite_one_error
;
3969 if (p
->object
.flags
& UNINTERESTING
)
3970 return rewrite_one_ok
;
3971 if (!(p
->object
.flags
& TREESAME
))
3972 return rewrite_one_ok
;
3974 return rewrite_one_noparents
;
3975 if (!(p
= one_relevant_parent(revs
, p
->parents
)))
3976 return rewrite_one_ok
;
3981 static void merge_queue_into_list(struct prio_queue
*q
, struct commit_list
**list
)
3984 struct commit
*item
= prio_queue_peek(q
);
3985 struct commit_list
*p
= *list
;
3987 if (p
&& p
->item
->date
>= item
->date
)
3990 p
= commit_list_insert(item
, list
);
3991 list
= &p
->next
; /* skip newly added item */
3992 prio_queue_get(q
); /* pop item */
3997 static enum rewrite_result
rewrite_one(struct rev_info
*revs
, struct commit
**pp
)
3999 struct prio_queue queue
= { compare_commits_by_commit_date
};
4000 enum rewrite_result ret
= rewrite_one_1(revs
, pp
, &queue
);
4001 merge_queue_into_list(&queue
, &revs
->commits
);
4002 clear_prio_queue(&queue
);
4006 int rewrite_parents(struct rev_info
*revs
, struct commit
*commit
,
4007 rewrite_parent_fn_t rewrite_parent
)
4009 struct commit_list
**pp
= &commit
->parents
;
4011 struct commit_list
*parent
= *pp
;
4012 switch (rewrite_parent(revs
, &parent
->item
)) {
4013 case rewrite_one_ok
:
4015 case rewrite_one_noparents
:
4019 case rewrite_one_error
:
4024 remove_duplicate_parents(revs
, commit
);
4028 static int commit_match(struct commit
*commit
, struct rev_info
*opt
)
4031 const char *encoding
;
4032 const char *message
;
4033 struct strbuf buf
= STRBUF_INIT
;
4035 if (!opt
->grep_filter
.pattern_list
&& !opt
->grep_filter
.header_list
)
4038 /* Prepend "fake" headers as needed */
4039 if (opt
->grep_filter
.use_reflog_filter
) {
4040 strbuf_addstr(&buf
, "reflog ");
4041 get_reflog_message(&buf
, opt
->reflog_info
);
4042 strbuf_addch(&buf
, '\n');
4046 * We grep in the user's output encoding, under the assumption that it
4047 * is the encoding they are most likely to write their grep pattern
4048 * for. In addition, it means we will match the "notes" encoding below,
4049 * so we will not end up with a buffer that has two different encodings
4052 encoding
= get_log_output_encoding();
4053 message
= repo_logmsg_reencode(the_repository
, commit
, NULL
, encoding
);
4055 /* Copy the commit to temporary if we are using "fake" headers */
4057 strbuf_addstr(&buf
, message
);
4059 if (opt
->grep_filter
.header_list
&& opt
->mailmap
) {
4060 const char *commit_headers
[] = { "author ", "committer ", NULL
};
4063 strbuf_addstr(&buf
, message
);
4065 apply_mailmap_to_header(&buf
, commit_headers
, opt
->mailmap
);
4068 /* Append "fake" message parts as needed */
4069 if (opt
->show_notes
) {
4071 strbuf_addstr(&buf
, message
);
4072 format_display_notes(&commit
->object
.oid
, &buf
, encoding
, 1);
4076 * Find either in the original commit message, or in the temporary.
4077 * Note that we cast away the constness of "message" here. It is
4078 * const because it may come from the cached commit buffer. That's OK,
4079 * because we know that it is modifiable heap memory, and that while
4080 * grep_buffer may modify it for speed, it will restore any
4081 * changes before returning.
4084 retval
= grep_buffer(&opt
->grep_filter
, buf
.buf
, buf
.len
);
4086 retval
= grep_buffer(&opt
->grep_filter
,
4087 (char *)message
, strlen(message
));
4088 strbuf_release(&buf
);
4089 repo_unuse_commit_buffer(the_repository
, commit
, message
);
4093 static inline int want_ancestry(const struct rev_info
*revs
)
4095 return (revs
->rewrite_parents
|| revs
->children
.name
);
4099 * Return a timestamp to be used for --since/--until comparisons for this
4100 * commit, based on the revision options.
4102 static timestamp_t
comparison_date(const struct rev_info
*revs
,
4103 struct commit
*commit
)
4105 return revs
->reflog_info
?
4106 get_reflog_timestamp(revs
->reflog_info
) :
4110 enum commit_action
get_commit_action(struct rev_info
*revs
, struct commit
*commit
)
4112 if (commit
->object
.flags
& SHOWN
)
4113 return commit_ignore
;
4114 if (revs
->unpacked
&& has_object_pack(revs
->repo
, &commit
->object
.oid
))
4115 return commit_ignore
;
4116 if (revs
->no_kept_objects
) {
4117 if (has_object_kept_pack(revs
->repo
, &commit
->object
.oid
,
4118 revs
->keep_pack_cache_flags
))
4119 return commit_ignore
;
4121 if (commit
->object
.flags
& UNINTERESTING
)
4122 return commit_ignore
;
4123 if (revs
->line_level_traverse
&& !want_ancestry(revs
)) {
4125 * In case of line-level log with parent rewriting
4126 * prepare_revision_walk() already took care of all line-level
4127 * log filtering, and there is nothing left to do here.
4129 * If parent rewriting was not requested, then this is the
4130 * place to perform the line-level log filtering. Notably,
4131 * this check, though expensive, must come before the other,
4132 * cheaper filtering conditions, because the tracked line
4133 * ranges must be adjusted even when the commit will end up
4134 * being ignored based on other conditions.
4136 if (!line_log_process_ranges_arbitrary_commit(revs
, commit
))
4137 return commit_ignore
;
4139 if (revs
->min_age
!= -1 &&
4140 comparison_date(revs
, commit
) > revs
->min_age
)
4141 return commit_ignore
;
4142 if (revs
->max_age_as_filter
!= -1 &&
4143 comparison_date(revs
, commit
) < revs
->max_age_as_filter
)
4144 return commit_ignore
;
4145 if (revs
->min_parents
|| (revs
->max_parents
>= 0)) {
4146 int n
= commit_list_count(commit
->parents
);
4147 if ((n
< revs
->min_parents
) ||
4148 ((revs
->max_parents
>= 0) && (n
> revs
->max_parents
)))
4149 return commit_ignore
;
4151 if (!commit_match(commit
, revs
))
4152 return commit_ignore
;
4153 if (revs
->prune
&& revs
->dense
) {
4154 /* Commit without changes? */
4155 if (commit
->object
.flags
& TREESAME
) {
4157 struct commit_list
*p
;
4158 /* drop merges unless we want parenthood */
4159 if (!want_ancestry(revs
))
4160 return commit_ignore
;
4162 if (revs
->show_pulls
&& (commit
->object
.flags
& PULL_MERGE
))
4166 * If we want ancestry, then need to keep any merges
4167 * between relevant commits to tie together topology.
4168 * For consistency with TREESAME and simplification
4169 * use "relevant" here rather than just INTERESTING,
4170 * to treat bottom commit(s) as part of the topology.
4172 for (n
= 0, p
= commit
->parents
; p
; p
= p
->next
)
4173 if (relevant_commit(p
->item
))
4176 return commit_ignore
;
4182 define_commit_slab(saved_parents
, struct commit_list
*);
4184 #define EMPTY_PARENT_LIST ((struct commit_list *)-1)
4187 * You may only call save_parents() once per commit (this is checked
4188 * for non-root commits).
4190 static void save_parents(struct rev_info
*revs
, struct commit
*commit
)
4192 struct commit_list
**pp
;
4194 if (!revs
->saved_parents_slab
) {
4195 revs
->saved_parents_slab
= xmalloc(sizeof(struct saved_parents
));
4196 init_saved_parents(revs
->saved_parents_slab
);
4199 pp
= saved_parents_at(revs
->saved_parents_slab
, commit
);
4202 * When walking with reflogs, we may visit the same commit
4203 * several times: once for each appearance in the reflog.
4205 * In this case, save_parents() will be called multiple times.
4206 * We want to keep only the first set of parents. We need to
4207 * store a sentinel value for an empty (i.e., NULL) parent
4208 * list to distinguish it from a not-yet-saved list, however.
4212 if (commit
->parents
)
4213 *pp
= copy_commit_list(commit
->parents
);
4215 *pp
= EMPTY_PARENT_LIST
;
4218 static void free_saved_parent(struct commit_list
**parents
)
4220 if (*parents
!= EMPTY_PARENT_LIST
)
4221 free_commit_list(*parents
);
4224 static void free_saved_parents(struct rev_info
*revs
)
4226 if (!revs
->saved_parents_slab
)
4228 deep_clear_saved_parents(revs
->saved_parents_slab
, free_saved_parent
);
4229 FREE_AND_NULL(revs
->saved_parents_slab
);
4232 struct commit_list
*get_saved_parents(struct rev_info
*revs
, const struct commit
*commit
)
4234 struct commit_list
*parents
;
4236 if (!revs
->saved_parents_slab
)
4237 return commit
->parents
;
4239 parents
= *saved_parents_at(revs
->saved_parents_slab
, commit
);
4240 if (parents
== EMPTY_PARENT_LIST
)
4245 enum commit_action
simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
4247 enum commit_action action
= get_commit_action(revs
, commit
);
4249 if (action
== commit_show
&&
4250 revs
->prune
&& revs
->dense
&& want_ancestry(revs
)) {
4252 * --full-diff on simplified parents is no good: it
4253 * will show spurious changes from the commits that
4254 * were elided. So we save the parents on the side
4255 * when --full-diff is in effect.
4257 if (revs
->full_diff
)
4258 save_parents(revs
, commit
);
4259 if (rewrite_parents(revs
, commit
, rewrite_one
) < 0)
4260 return commit_error
;
4265 static void track_linear(struct rev_info
*revs
, struct commit
*commit
)
4267 if (revs
->track_first_time
) {
4269 revs
->track_first_time
= 0;
4271 struct commit_list
*p
;
4272 for (p
= revs
->previous_parents
; p
; p
= p
->next
)
4273 if (p
->item
== NULL
|| /* first commit */
4274 oideq(&p
->item
->object
.oid
, &commit
->object
.oid
))
4276 revs
->linear
= p
!= NULL
;
4278 if (revs
->reverse
) {
4280 commit
->object
.flags
|= TRACK_LINEAR
;
4282 free_commit_list(revs
->previous_parents
);
4283 revs
->previous_parents
= copy_commit_list(commit
->parents
);
4286 static struct commit
*get_revision_1(struct rev_info
*revs
)
4289 struct commit
*commit
;
4291 if (revs
->reflog_info
)
4292 commit
= next_reflog_entry(revs
->reflog_info
);
4293 else if (revs
->topo_walk_info
)
4294 commit
= next_topo_commit(revs
);
4296 commit
= pop_commit(&revs
->commits
);
4301 if (revs
->reflog_info
)
4302 commit
->object
.flags
&= ~(ADDED
| SEEN
| SHOWN
);
4305 * If we haven't done the list limiting, we need to look at
4306 * the parents here. We also need to do the date-based limiting
4307 * that we'd otherwise have done in limit_list().
4309 if (!revs
->limited
) {
4310 if (revs
->max_age
!= -1 &&
4311 comparison_date(revs
, commit
) < revs
->max_age
)
4314 if (revs
->reflog_info
)
4315 try_to_simplify_commit(revs
, commit
);
4316 else if (revs
->topo_walk_info
)
4317 expand_topo_walk(revs
, commit
);
4318 else if (process_parents(revs
, commit
, &revs
->commits
, NULL
) < 0) {
4319 if (!revs
->ignore_missing_links
)
4320 die("Failed to traverse parents of commit %s",
4321 oid_to_hex(&commit
->object
.oid
));
4325 switch (simplify_commit(revs
, commit
)) {
4329 die("Failed to simplify parents of commit %s",
4330 oid_to_hex(&commit
->object
.oid
));
4332 if (revs
->track_linear
)
4333 track_linear(revs
, commit
);
4340 * Return true for entries that have not yet been shown. (This is an
4341 * object_array_each_func_t.)
4343 static int entry_unshown(struct object_array_entry
*entry
, void *cb_data UNUSED
)
4345 return !(entry
->item
->flags
& SHOWN
);
4349 * If array is on the verge of a realloc, garbage-collect any entries
4350 * that have already been shown to try to free up some space.
4352 static void gc_boundary(struct object_array
*array
)
4354 if (array
->nr
== array
->alloc
)
4355 object_array_filter(array
, entry_unshown
, NULL
);
4358 static void create_boundary_commit_list(struct rev_info
*revs
)
4362 struct object_array
*array
= &revs
->boundary_commits
;
4363 struct object_array_entry
*objects
= array
->objects
;
4366 * If revs->commits is non-NULL at this point, an error occurred in
4367 * get_revision_1(). Ignore the error and continue printing the
4368 * boundary commits anyway. (This is what the code has always
4371 free_commit_list(revs
->commits
);
4372 revs
->commits
= NULL
;
4375 * Put all of the actual boundary commits from revs->boundary_commits
4376 * into revs->commits
4378 for (i
= 0; i
< array
->nr
; i
++) {
4379 c
= (struct commit
*)(objects
[i
].item
);
4382 if (!(c
->object
.flags
& CHILD_SHOWN
))
4384 if (c
->object
.flags
& (SHOWN
| BOUNDARY
))
4386 c
->object
.flags
|= BOUNDARY
;
4387 commit_list_insert(c
, &revs
->commits
);
4391 * If revs->topo_order is set, sort the boundary commits
4392 * in topological order
4394 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
4397 static struct commit
*get_revision_internal(struct rev_info
*revs
)
4399 struct commit
*c
= NULL
;
4400 struct commit_list
*l
;
4402 if (revs
->boundary
== 2) {
4404 * All of the normal commits have already been returned,
4405 * and we are now returning boundary commits.
4406 * create_boundary_commit_list() has populated
4407 * revs->commits with the remaining commits to return.
4409 c
= pop_commit(&revs
->commits
);
4411 c
->object
.flags
|= SHOWN
;
4416 * If our max_count counter has reached zero, then we are done. We
4417 * don't simply return NULL because we still might need to show
4418 * boundary commits. But we want to avoid calling get_revision_1, which
4419 * might do a considerable amount of work finding the next commit only
4420 * for us to throw it away.
4422 * If it is non-zero, then either we don't have a max_count at all
4423 * (-1), or it is still counting, in which case we decrement.
4425 if (revs
->max_count
) {
4426 c
= get_revision_1(revs
);
4428 while (revs
->skip_count
> 0) {
4430 c
= get_revision_1(revs
);
4433 free_commit_buffer(revs
->repo
->parsed_objects
, c
);
4437 if (revs
->max_count
> 0)
4442 c
->object
.flags
|= SHOWN
;
4444 if (!revs
->boundary
)
4449 * get_revision_1() runs out the commits, and
4450 * we are done computing the boundaries.
4451 * switch to boundary commits output mode.
4456 * Update revs->commits to contain the list of
4459 create_boundary_commit_list(revs
);
4461 return get_revision_internal(revs
);
4465 * boundary commits are the commits that are parents of the
4466 * ones we got from get_revision_1() but they themselves are
4467 * not returned from get_revision_1(). Before returning
4468 * 'c', we need to mark its parents that they could be boundaries.
4471 for (l
= c
->parents
; l
; l
= l
->next
) {
4473 p
= &(l
->item
->object
);
4474 if (p
->flags
& (CHILD_SHOWN
| SHOWN
))
4476 p
->flags
|= CHILD_SHOWN
;
4477 gc_boundary(&revs
->boundary_commits
);
4478 add_object_array(p
, NULL
, &revs
->boundary_commits
);
4484 struct commit
*get_revision(struct rev_info
*revs
)
4487 struct commit_list
*reversed
;
4489 if (revs
->reverse
) {
4491 while ((c
= get_revision_internal(revs
)))
4492 commit_list_insert(c
, &reversed
);
4493 free_commit_list(revs
->commits
);
4494 revs
->commits
= reversed
;
4496 revs
->reverse_output_stage
= 1;
4499 if (revs
->reverse_output_stage
) {
4500 c
= pop_commit(&revs
->commits
);
4501 if (revs
->track_linear
)
4502 revs
->linear
= !!(c
&& c
->object
.flags
& TRACK_LINEAR
);
4506 c
= get_revision_internal(revs
);
4507 if (c
&& revs
->graph
)
4508 graph_update(revs
->graph
, c
);
4510 free_saved_parents(revs
);
4511 free_commit_list(revs
->previous_parents
);
4512 revs
->previous_parents
= NULL
;
4517 const char *get_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
4519 if (commit
->object
.flags
& BOUNDARY
)
4521 else if (commit
->object
.flags
& UNINTERESTING
)
4523 else if (commit
->object
.flags
& PATCHSAME
)
4525 else if (!revs
|| revs
->left_right
) {
4526 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
4530 } else if (revs
->graph
)
4532 else if (revs
->cherry_mark
)
4537 void put_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
4539 const char *mark
= get_revision_mark(revs
, commit
);
4542 fputs(mark
, stdout
);