2 #include "object-store.h"
10 #include "repository.h"
13 #include "reflog-walk.h"
14 #include "patch-ids.h"
17 #include "string-list.h"
20 #include "commit-slab.h"
22 #include "cache-tree.h"
26 #include "argv-array.h"
27 #include "commit-reach.h"
28 #include "commit-graph.h"
29 #include "prio-queue.h"
31 volatile show_early_output_fn_t show_early_output
;
33 static const char *term_bad
;
34 static const char *term_good
;
36 implement_shared_commit_slab(revision_sources
, char *);
38 void show_object_with_name(FILE *out
, struct object
*obj
, const char *name
)
42 fprintf(out
, "%s ", oid_to_hex(&obj
->oid
));
43 for (p
= name
; *p
&& *p
!= '\n'; p
++)
48 static void mark_blob_uninteresting(struct blob
*blob
)
52 if (blob
->object
.flags
& UNINTERESTING
)
54 blob
->object
.flags
|= UNINTERESTING
;
57 static void mark_tree_contents_uninteresting(struct repository
*r
,
60 struct tree_desc desc
;
61 struct name_entry entry
;
63 if (parse_tree_gently(tree
, 1) < 0)
66 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
67 while (tree_entry(&desc
, &entry
)) {
68 switch (object_type(entry
.mode
)) {
70 mark_tree_uninteresting(r
, lookup_tree(r
, entry
.oid
));
73 mark_blob_uninteresting(lookup_blob(r
, entry
.oid
));
76 /* Subproject commit - not in this repository */
82 * We don't care about the tree any more
83 * after it has been marked uninteresting.
85 free_tree_buffer(tree
);
88 void mark_tree_uninteresting(struct repository
*r
, struct tree
*tree
)
96 if (obj
->flags
& UNINTERESTING
)
98 obj
->flags
|= UNINTERESTING
;
99 mark_tree_contents_uninteresting(r
, tree
);
102 void mark_trees_uninteresting_sparse(struct repository
*r
,
103 struct oidset
*trees
)
105 struct object_id
*oid
;
106 struct oidset_iter iter
;
108 oidset_iter_init(trees
, &iter
);
109 while ((oid
= oidset_iter_next(&iter
))) {
110 struct tree
*tree
= lookup_tree(r
, oid
);
115 if (tree
->object
.flags
& UNINTERESTING
) {
117 * Remove the flag so the next call
118 * is not a no-op. The flag is added
119 * in mark_tree_unintersting().
121 tree
->object
.flags
^= UNINTERESTING
;
122 mark_tree_uninteresting(r
, tree
);
127 struct commit_stack
{
128 struct commit
**items
;
131 #define COMMIT_STACK_INIT { NULL, 0, 0 }
133 static void commit_stack_push(struct commit_stack
*stack
, struct commit
*commit
)
135 ALLOC_GROW(stack
->items
, stack
->nr
+ 1, stack
->alloc
);
136 stack
->items
[stack
->nr
++] = commit
;
139 static struct commit
*commit_stack_pop(struct commit_stack
*stack
)
141 return stack
->nr
? stack
->items
[--stack
->nr
] : NULL
;
144 static void commit_stack_clear(struct commit_stack
*stack
)
146 FREE_AND_NULL(stack
->items
);
147 stack
->nr
= stack
->alloc
= 0;
150 static void mark_one_parent_uninteresting(struct commit
*commit
,
151 struct commit_stack
*pending
)
153 struct commit_list
*l
;
155 if (commit
->object
.flags
& UNINTERESTING
)
157 commit
->object
.flags
|= UNINTERESTING
;
160 * Normally we haven't parsed the parent
161 * yet, so we won't have a parent of a parent
162 * here. However, it may turn out that we've
163 * reached this commit some other way (where it
164 * wasn't uninteresting), in which case we need
165 * to mark its parents recursively too..
167 for (l
= commit
->parents
; l
; l
= l
->next
)
168 commit_stack_push(pending
, l
->item
);
171 void mark_parents_uninteresting(struct commit
*commit
)
173 struct commit_stack pending
= COMMIT_STACK_INIT
;
174 struct commit_list
*l
;
176 for (l
= commit
->parents
; l
; l
= l
->next
)
177 mark_one_parent_uninteresting(l
->item
, &pending
);
179 while (pending
.nr
> 0)
180 mark_one_parent_uninteresting(commit_stack_pop(&pending
),
183 commit_stack_clear(&pending
);
186 static void add_pending_object_with_path(struct rev_info
*revs
,
188 const char *name
, unsigned mode
,
193 if (revs
->no_walk
&& (obj
->flags
& UNINTERESTING
))
195 if (revs
->reflog_info
&& obj
->type
== OBJ_COMMIT
) {
196 struct strbuf buf
= STRBUF_INIT
;
197 int len
= interpret_branch_name(name
, 0, &buf
, 0);
199 if (0 < len
&& name
[len
] && buf
.len
)
200 strbuf_addstr(&buf
, name
+ len
);
201 add_reflog_for_walk(revs
->reflog_info
,
202 (struct commit
*)obj
,
203 buf
.buf
[0] ? buf
.buf
: name
);
204 strbuf_release(&buf
);
205 return; /* do not add the commit itself */
207 add_object_array_with_path(obj
, name
, &revs
->pending
, mode
, path
);
210 static void add_pending_object_with_mode(struct rev_info
*revs
,
212 const char *name
, unsigned mode
)
214 add_pending_object_with_path(revs
, obj
, name
, mode
, NULL
);
217 void add_pending_object(struct rev_info
*revs
,
218 struct object
*obj
, const char *name
)
220 add_pending_object_with_mode(revs
, obj
, name
, S_IFINVALID
);
223 void add_head_to_pending(struct rev_info
*revs
)
225 struct object_id oid
;
227 if (get_oid("HEAD", &oid
))
229 obj
= parse_object(revs
->repo
, &oid
);
232 add_pending_object(revs
, obj
, "HEAD");
235 static struct object
*get_reference(struct rev_info
*revs
, const char *name
,
236 const struct object_id
*oid
,
239 struct object
*object
;
241 object
= parse_object(revs
->repo
, oid
);
243 if (revs
->ignore_missing
)
245 if (revs
->exclude_promisor_objects
&& is_promisor_object(oid
))
247 die("bad object %s", name
);
249 object
->flags
|= flags
;
253 void add_pending_oid(struct rev_info
*revs
, const char *name
,
254 const struct object_id
*oid
, unsigned int flags
)
256 struct object
*object
= get_reference(revs
, name
, oid
, flags
);
257 add_pending_object(revs
, object
, name
);
260 static struct commit
*handle_commit(struct rev_info
*revs
,
261 struct object_array_entry
*entry
)
263 struct object
*object
= entry
->item
;
264 const char *name
= entry
->name
;
265 const char *path
= entry
->path
;
266 unsigned int mode
= entry
->mode
;
267 unsigned long flags
= object
->flags
;
270 * Tag object? Look what it points to..
272 while (object
->type
== OBJ_TAG
) {
273 struct tag
*tag
= (struct tag
*) object
;
274 if (revs
->tag_objects
&& !(flags
& UNINTERESTING
))
275 add_pending_object(revs
, object
, tag
->tag
);
278 object
= parse_object(revs
->repo
, &tag
->tagged
->oid
);
280 if (revs
->ignore_missing_links
|| (flags
& UNINTERESTING
))
282 if (revs
->exclude_promisor_objects
&&
283 is_promisor_object(&tag
->tagged
->oid
))
285 die("bad object %s", oid_to_hex(&tag
->tagged
->oid
));
287 object
->flags
|= flags
;
289 * We'll handle the tagged object by looping or dropping
290 * through to the non-tag handlers below. Do not
291 * propagate path data from the tag's pending entry.
298 * Commit object? Just return it, we'll do all the complex
301 if (object
->type
== OBJ_COMMIT
) {
302 struct commit
*commit
= (struct commit
*)object
;
304 if (parse_commit(commit
) < 0)
305 die("unable to parse commit %s", name
);
306 if (flags
& UNINTERESTING
) {
307 mark_parents_uninteresting(commit
);
311 char **slot
= revision_sources_at(revs
->sources
, commit
);
314 *slot
= xstrdup(name
);
320 * Tree object? Either mark it uninteresting, or add it
321 * to the list of objects to look at later..
323 if (object
->type
== OBJ_TREE
) {
324 struct tree
*tree
= (struct tree
*)object
;
325 if (!revs
->tree_objects
)
327 if (flags
& UNINTERESTING
) {
328 mark_tree_contents_uninteresting(revs
->repo
, tree
);
331 add_pending_object_with_path(revs
, object
, name
, mode
, path
);
336 * Blob object? You know the drill by now..
338 if (object
->type
== OBJ_BLOB
) {
339 if (!revs
->blob_objects
)
341 if (flags
& UNINTERESTING
)
343 add_pending_object_with_path(revs
, object
, name
, mode
, path
);
346 die("%s is unknown object", name
);
349 static int everybody_uninteresting(struct commit_list
*orig
,
350 struct commit
**interesting_cache
)
352 struct commit_list
*list
= orig
;
354 if (*interesting_cache
) {
355 struct commit
*commit
= *interesting_cache
;
356 if (!(commit
->object
.flags
& UNINTERESTING
))
361 struct commit
*commit
= list
->item
;
363 if (commit
->object
.flags
& UNINTERESTING
)
366 *interesting_cache
= commit
;
373 * A definition of "relevant" commit that we can use to simplify limited graphs
374 * by eliminating side branches.
376 * A "relevant" commit is one that is !UNINTERESTING (ie we are including it
377 * in our list), or that is a specified BOTTOM commit. Then after computing
378 * a limited list, during processing we can generally ignore boundary merges
379 * coming from outside the graph, (ie from irrelevant parents), and treat
380 * those merges as if they were single-parent. TREESAME is defined to consider
381 * only relevant parents, if any. If we are TREESAME to our on-graph parents,
382 * we don't care if we were !TREESAME to non-graph parents.
384 * Treating bottom commits as relevant ensures that a limited graph's
385 * connection to the actual bottom commit is not viewed as a side branch, but
386 * treated as part of the graph. For example:
388 * ....Z...A---X---o---o---B
392 * When computing "A..B", the A-X connection is at least as important as
393 * Y-X, despite A being flagged UNINTERESTING.
395 * And when computing --ancestry-path "A..B", the A-X connection is more
396 * important than Y-X, despite both A and Y being flagged UNINTERESTING.
398 static inline int relevant_commit(struct commit
*commit
)
400 return (commit
->object
.flags
& (UNINTERESTING
| BOTTOM
)) != UNINTERESTING
;
404 * Return a single relevant commit from a parent list. If we are a TREESAME
405 * commit, and this selects one of our parents, then we can safely simplify to
408 static struct commit
*one_relevant_parent(const struct rev_info
*revs
,
409 struct commit_list
*orig
)
411 struct commit_list
*list
= orig
;
412 struct commit
*relevant
= NULL
;
418 * For 1-parent commits, or if first-parent-only, then return that
419 * first parent (even if not "relevant" by the above definition).
420 * TREESAME will have been set purely on that parent.
422 if (revs
->first_parent_only
|| !orig
->next
)
426 * For multi-parent commits, identify a sole relevant parent, if any.
427 * If we have only one relevant parent, then TREESAME will be set purely
428 * with regard to that parent, and we can simplify accordingly.
430 * If we have more than one relevant parent, or no relevant parents
431 * (and multiple irrelevant ones), then we can't select a parent here
435 struct commit
*commit
= list
->item
;
437 if (relevant_commit(commit
)) {
447 * The goal is to get REV_TREE_NEW as the result only if the
448 * diff consists of all '+' (and no other changes), REV_TREE_OLD
449 * if the whole diff is removal of old data, and otherwise
450 * REV_TREE_DIFFERENT (of course if the trees are the same we
451 * want REV_TREE_SAME).
453 * The only time we care about the distinction is when
454 * remove_empty_trees is in effect, in which case we care only about
455 * whether the whole change is REV_TREE_NEW, or if there's another type
456 * of change. Which means we can stop the diff early in either of these
459 * 1. We're not using remove_empty_trees at all.
461 * 2. We saw anything except REV_TREE_NEW.
463 static int tree_difference
= REV_TREE_SAME
;
465 static void file_add_remove(struct diff_options
*options
,
466 int addremove
, unsigned mode
,
467 const struct object_id
*oid
,
469 const char *fullpath
, unsigned dirty_submodule
)
471 int diff
= addremove
== '+' ? REV_TREE_NEW
: REV_TREE_OLD
;
472 struct rev_info
*revs
= options
->change_fn_data
;
474 tree_difference
|= diff
;
475 if (!revs
->remove_empty_trees
|| tree_difference
!= REV_TREE_NEW
)
476 options
->flags
.has_changes
= 1;
479 static void file_change(struct diff_options
*options
,
480 unsigned old_mode
, unsigned new_mode
,
481 const struct object_id
*old_oid
,
482 const struct object_id
*new_oid
,
483 int old_oid_valid
, int new_oid_valid
,
484 const char *fullpath
,
485 unsigned old_dirty_submodule
, unsigned new_dirty_submodule
)
487 tree_difference
= REV_TREE_DIFFERENT
;
488 options
->flags
.has_changes
= 1;
491 static int rev_compare_tree(struct rev_info
*revs
,
492 struct commit
*parent
, struct commit
*commit
)
494 struct tree
*t1
= get_commit_tree(parent
);
495 struct tree
*t2
= get_commit_tree(commit
);
502 if (revs
->simplify_by_decoration
) {
504 * If we are simplifying by decoration, then the commit
505 * is worth showing if it has a tag pointing at it.
507 if (get_name_decoration(&commit
->object
))
508 return REV_TREE_DIFFERENT
;
510 * A commit that is not pointed by a tag is uninteresting
511 * if we are not limited by path. This means that you will
512 * see the usual "commits that touch the paths" plus any
513 * tagged commit by specifying both --simplify-by-decoration
516 if (!revs
->prune_data
.nr
)
517 return REV_TREE_SAME
;
520 tree_difference
= REV_TREE_SAME
;
521 revs
->pruning
.flags
.has_changes
= 0;
522 if (diff_tree_oid(&t1
->object
.oid
, &t2
->object
.oid
, "",
524 return REV_TREE_DIFFERENT
;
525 return tree_difference
;
528 static int rev_same_tree_as_empty(struct rev_info
*revs
, struct commit
*commit
)
531 struct tree
*t1
= get_commit_tree(commit
);
536 tree_difference
= REV_TREE_SAME
;
537 revs
->pruning
.flags
.has_changes
= 0;
538 retval
= diff_tree_oid(NULL
, &t1
->object
.oid
, "", &revs
->pruning
);
540 return retval
>= 0 && (tree_difference
== REV_TREE_SAME
);
543 struct treesame_state
{
544 unsigned int nparents
;
545 unsigned char treesame
[FLEX_ARRAY
];
548 static struct treesame_state
*initialise_treesame(struct rev_info
*revs
, struct commit
*commit
)
550 unsigned n
= commit_list_count(commit
->parents
);
551 struct treesame_state
*st
= xcalloc(1, st_add(sizeof(*st
), n
));
553 add_decoration(&revs
->treesame
, &commit
->object
, st
);
558 * Must be called immediately after removing the nth_parent from a commit's
559 * parent list, if we are maintaining the per-parent treesame[] decoration.
560 * This does not recalculate the master TREESAME flag - update_treesame()
561 * should be called to update it after a sequence of treesame[] modifications
562 * that may have affected it.
564 static int compact_treesame(struct rev_info
*revs
, struct commit
*commit
, unsigned nth_parent
)
566 struct treesame_state
*st
;
569 if (!commit
->parents
) {
571 * Have just removed the only parent from a non-merge.
572 * Different handling, as we lack decoration.
575 die("compact_treesame %u", nth_parent
);
576 old_same
= !!(commit
->object
.flags
& TREESAME
);
577 if (rev_same_tree_as_empty(revs
, commit
))
578 commit
->object
.flags
|= TREESAME
;
580 commit
->object
.flags
&= ~TREESAME
;
584 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
585 if (!st
|| nth_parent
>= st
->nparents
)
586 die("compact_treesame %u", nth_parent
);
588 old_same
= st
->treesame
[nth_parent
];
589 memmove(st
->treesame
+ nth_parent
,
590 st
->treesame
+ nth_parent
+ 1,
591 st
->nparents
- nth_parent
- 1);
594 * If we've just become a non-merge commit, update TREESAME
595 * immediately, and remove the no-longer-needed decoration.
596 * If still a merge, defer update until update_treesame().
598 if (--st
->nparents
== 1) {
599 if (commit
->parents
->next
)
600 die("compact_treesame parents mismatch");
601 if (st
->treesame
[0] && revs
->dense
)
602 commit
->object
.flags
|= TREESAME
;
604 commit
->object
.flags
&= ~TREESAME
;
605 free(add_decoration(&revs
->treesame
, &commit
->object
, NULL
));
611 static unsigned update_treesame(struct rev_info
*revs
, struct commit
*commit
)
613 if (commit
->parents
&& commit
->parents
->next
) {
615 struct treesame_state
*st
;
616 struct commit_list
*p
;
617 unsigned relevant_parents
;
618 unsigned relevant_change
, irrelevant_change
;
620 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
622 die("update_treesame %s", oid_to_hex(&commit
->object
.oid
));
623 relevant_parents
= 0;
624 relevant_change
= irrelevant_change
= 0;
625 for (p
= commit
->parents
, n
= 0; p
; n
++, p
= p
->next
) {
626 if (relevant_commit(p
->item
)) {
627 relevant_change
|= !st
->treesame
[n
];
630 irrelevant_change
|= !st
->treesame
[n
];
632 if (relevant_parents
? relevant_change
: irrelevant_change
)
633 commit
->object
.flags
&= ~TREESAME
;
635 commit
->object
.flags
|= TREESAME
;
638 return commit
->object
.flags
& TREESAME
;
641 static inline int limiting_can_increase_treesame(const struct rev_info
*revs
)
644 * TREESAME is irrelevant unless prune && dense;
645 * if simplify_history is set, we can't have a mixture of TREESAME and
646 * !TREESAME INTERESTING parents (and we don't have treesame[]
647 * decoration anyway);
648 * if first_parent_only is set, then the TREESAME flag is locked
649 * against the first parent (and again we lack treesame[] decoration).
651 return revs
->prune
&& revs
->dense
&&
652 !revs
->simplify_history
&&
653 !revs
->first_parent_only
;
656 static void try_to_simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
658 struct commit_list
**pp
, *parent
;
659 struct treesame_state
*ts
= NULL
;
660 int relevant_change
= 0, irrelevant_change
= 0;
661 int relevant_parents
, nth_parent
;
664 * If we don't do pruning, everything is interesting
669 if (!get_commit_tree(commit
))
672 if (!commit
->parents
) {
673 if (rev_same_tree_as_empty(revs
, commit
))
674 commit
->object
.flags
|= TREESAME
;
679 * Normal non-merge commit? If we don't want to make the
680 * history dense, we consider it always to be a change..
682 if (!revs
->dense
&& !commit
->parents
->next
)
685 for (pp
= &commit
->parents
, nth_parent
= 0, relevant_parents
= 0;
686 (parent
= *pp
) != NULL
;
687 pp
= &parent
->next
, nth_parent
++) {
688 struct commit
*p
= parent
->item
;
689 if (relevant_commit(p
))
692 if (nth_parent
== 1) {
694 * This our second loop iteration - so we now know
695 * we're dealing with a merge.
697 * Do not compare with later parents when we care only about
698 * the first parent chain, in order to avoid derailing the
699 * traversal to follow a side branch that brought everything
700 * in the path we are limited to by the pathspec.
702 if (revs
->first_parent_only
)
705 * If this will remain a potentially-simplifiable
706 * merge, remember per-parent treesame if needed.
707 * Initialise the array with the comparison from our
710 if (revs
->treesame
.name
&&
711 !revs
->simplify_history
&&
712 !(commit
->object
.flags
& UNINTERESTING
)) {
713 ts
= initialise_treesame(revs
, commit
);
714 if (!(irrelevant_change
|| relevant_change
))
718 if (parse_commit(p
) < 0)
719 die("cannot simplify commit %s (because of %s)",
720 oid_to_hex(&commit
->object
.oid
),
721 oid_to_hex(&p
->object
.oid
));
722 switch (rev_compare_tree(revs
, p
, commit
)) {
724 if (!revs
->simplify_history
|| !relevant_commit(p
)) {
725 /* Even if a merge with an uninteresting
726 * side branch brought the entire change
727 * we are interested in, we do not want
728 * to lose the other branches of this
729 * merge, so we just keep going.
732 ts
->treesame
[nth_parent
] = 1;
736 commit
->parents
= parent
;
737 commit
->object
.flags
|= TREESAME
;
741 if (revs
->remove_empty_trees
&&
742 rev_same_tree_as_empty(revs
, p
)) {
743 /* We are adding all the specified
744 * paths from this parent, so the
745 * history beyond this parent is not
746 * interesting. Remove its parents
747 * (they are grandparents for us).
748 * IOW, we pretend this parent is a
751 if (parse_commit(p
) < 0)
752 die("cannot simplify commit %s (invalid %s)",
753 oid_to_hex(&commit
->object
.oid
),
754 oid_to_hex(&p
->object
.oid
));
759 case REV_TREE_DIFFERENT
:
760 if (relevant_commit(p
))
763 irrelevant_change
= 1;
766 die("bad tree compare for commit %s", oid_to_hex(&commit
->object
.oid
));
770 * TREESAME is straightforward for single-parent commits. For merge
771 * commits, it is most useful to define it so that "irrelevant"
772 * parents cannot make us !TREESAME - if we have any relevant
773 * parents, then we only consider TREESAMEness with respect to them,
774 * allowing irrelevant merges from uninteresting branches to be
775 * simplified away. Only if we have only irrelevant parents do we
776 * base TREESAME on them. Note that this logic is replicated in
777 * update_treesame, which should be kept in sync.
779 if (relevant_parents
? !relevant_change
: !irrelevant_change
)
780 commit
->object
.flags
|= TREESAME
;
783 static void commit_list_insert_by_date_cached(struct commit
*p
, struct commit_list
**head
,
784 struct commit_list
*cached_base
, struct commit_list
**cache
)
786 struct commit_list
*new_entry
;
788 if (cached_base
&& p
->date
< cached_base
->item
->date
)
789 new_entry
= commit_list_insert_by_date(p
, &cached_base
->next
);
791 new_entry
= commit_list_insert_by_date(p
, head
);
793 if (cache
&& (!*cache
|| p
->date
< (*cache
)->item
->date
))
797 static int process_parents(struct rev_info
*revs
, struct commit
*commit
,
798 struct commit_list
**list
, struct commit_list
**cache_ptr
)
800 struct commit_list
*parent
= commit
->parents
;
802 struct commit_list
*cached_base
= cache_ptr
? *cache_ptr
: NULL
;
804 if (commit
->object
.flags
& ADDED
)
806 commit
->object
.flags
|= ADDED
;
808 if (revs
->include_check
&&
809 !revs
->include_check(commit
, revs
->include_check_data
))
813 * If the commit is uninteresting, don't try to
814 * prune parents - we want the maximal uninteresting
817 * Normally we haven't parsed the parent
818 * yet, so we won't have a parent of a parent
819 * here. However, it may turn out that we've
820 * reached this commit some other way (where it
821 * wasn't uninteresting), in which case we need
822 * to mark its parents recursively too..
824 if (commit
->object
.flags
& UNINTERESTING
) {
826 struct commit
*p
= parent
->item
;
827 parent
= parent
->next
;
829 p
->object
.flags
|= UNINTERESTING
;
830 if (parse_commit_gently(p
, 1) < 0)
833 mark_parents_uninteresting(p
);
834 if (p
->object
.flags
& SEEN
)
836 p
->object
.flags
|= SEEN
;
838 commit_list_insert_by_date_cached(p
, list
, cached_base
, cache_ptr
);
844 * Ok, the commit wasn't uninteresting. Try to
845 * simplify the commit history and find the parent
846 * that has no differences in the path set if one exists.
848 try_to_simplify_commit(revs
, commit
);
853 left_flag
= (commit
->object
.flags
& SYMMETRIC_LEFT
);
855 for (parent
= commit
->parents
; parent
; parent
= parent
->next
) {
856 struct commit
*p
= parent
->item
;
857 int gently
= revs
->ignore_missing_links
||
858 revs
->exclude_promisor_objects
;
859 if (parse_commit_gently(p
, gently
) < 0) {
860 if (revs
->exclude_promisor_objects
&&
861 is_promisor_object(&p
->object
.oid
)) {
862 if (revs
->first_parent_only
)
869 char **slot
= revision_sources_at(revs
->sources
, p
);
872 *slot
= *revision_sources_at(revs
->sources
, commit
);
874 p
->object
.flags
|= left_flag
;
875 if (!(p
->object
.flags
& SEEN
)) {
876 p
->object
.flags
|= SEEN
;
878 commit_list_insert_by_date_cached(p
, list
, cached_base
, cache_ptr
);
880 if (revs
->first_parent_only
)
886 static void cherry_pick_list(struct commit_list
*list
, struct rev_info
*revs
)
888 struct commit_list
*p
;
889 int left_count
= 0, right_count
= 0;
891 struct patch_ids ids
;
892 unsigned cherry_flag
;
894 /* First count the commits on the left and on the right */
895 for (p
= list
; p
; p
= p
->next
) {
896 struct commit
*commit
= p
->item
;
897 unsigned flags
= commit
->object
.flags
;
898 if (flags
& BOUNDARY
)
900 else if (flags
& SYMMETRIC_LEFT
)
906 if (!left_count
|| !right_count
)
909 left_first
= left_count
< right_count
;
910 init_patch_ids(revs
->repo
, &ids
);
911 ids
.diffopts
.pathspec
= revs
->diffopt
.pathspec
;
913 /* Compute patch-ids for one side */
914 for (p
= list
; p
; p
= p
->next
) {
915 struct commit
*commit
= p
->item
;
916 unsigned flags
= commit
->object
.flags
;
918 if (flags
& BOUNDARY
)
921 * If we have fewer left, left_first is set and we omit
922 * commits on the right branch in this loop. If we have
923 * fewer right, we skip the left ones.
925 if (left_first
!= !!(flags
& SYMMETRIC_LEFT
))
927 add_commit_patch_id(commit
, &ids
);
930 /* either cherry_mark or cherry_pick are true */
931 cherry_flag
= revs
->cherry_mark
? PATCHSAME
: SHOWN
;
933 /* Check the other side */
934 for (p
= list
; p
; p
= p
->next
) {
935 struct commit
*commit
= p
->item
;
937 unsigned flags
= commit
->object
.flags
;
939 if (flags
& BOUNDARY
)
942 * If we have fewer left, left_first is set and we omit
943 * commits on the left branch in this loop.
945 if (left_first
== !!(flags
& SYMMETRIC_LEFT
))
949 * Have we seen the same patch id?
951 id
= has_commit_patch_id(commit
, &ids
);
955 commit
->object
.flags
|= cherry_flag
;
956 id
->commit
->object
.flags
|= cherry_flag
;
959 free_patch_ids(&ids
);
962 /* How many extra uninteresting commits we want to see.. */
965 static int still_interesting(struct commit_list
*src
, timestamp_t date
, int slop
,
966 struct commit
**interesting_cache
)
969 * No source list at all? We're definitely done..
975 * Does the destination list contain entries with a date
976 * before the source list? Definitely _not_ done.
978 if (date
<= src
->item
->date
)
982 * Does the source list still have interesting commits in
983 * it? Definitely not done..
985 if (!everybody_uninteresting(src
, interesting_cache
))
988 /* Ok, we're closing in.. */
993 * "rev-list --ancestry-path A..B" computes commits that are ancestors
994 * of B but not ancestors of A but further limits the result to those
995 * that are descendants of A. This takes the list of bottom commits and
996 * the result of "A..B" without --ancestry-path, and limits the latter
997 * further to the ones that can reach one of the commits in "bottom".
999 static void limit_to_ancestry(struct commit_list
*bottom
, struct commit_list
*list
)
1001 struct commit_list
*p
;
1002 struct commit_list
*rlist
= NULL
;
1006 * Reverse the list so that it will be likely that we would
1007 * process parents before children.
1009 for (p
= list
; p
; p
= p
->next
)
1010 commit_list_insert(p
->item
, &rlist
);
1012 for (p
= bottom
; p
; p
= p
->next
)
1013 p
->item
->object
.flags
|= TMP_MARK
;
1016 * Mark the ones that can reach bottom commits in "list",
1017 * in a bottom-up fashion.
1021 for (p
= rlist
; p
; p
= p
->next
) {
1022 struct commit
*c
= p
->item
;
1023 struct commit_list
*parents
;
1024 if (c
->object
.flags
& (TMP_MARK
| UNINTERESTING
))
1026 for (parents
= c
->parents
;
1028 parents
= parents
->next
) {
1029 if (!(parents
->item
->object
.flags
& TMP_MARK
))
1031 c
->object
.flags
|= TMP_MARK
;
1036 } while (made_progress
);
1039 * NEEDSWORK: decide if we want to remove parents that are
1040 * not marked with TMP_MARK from commit->parents for commits
1041 * in the resulting list. We may not want to do that, though.
1045 * The ones that are not marked with TMP_MARK are uninteresting
1047 for (p
= list
; p
; p
= p
->next
) {
1048 struct commit
*c
= p
->item
;
1049 if (c
->object
.flags
& TMP_MARK
)
1051 c
->object
.flags
|= UNINTERESTING
;
1054 /* We are done with the TMP_MARK */
1055 for (p
= list
; p
; p
= p
->next
)
1056 p
->item
->object
.flags
&= ~TMP_MARK
;
1057 for (p
= bottom
; p
; p
= p
->next
)
1058 p
->item
->object
.flags
&= ~TMP_MARK
;
1059 free_commit_list(rlist
);
1063 * Before walking the history, keep the set of "negative" refs the
1064 * caller has asked to exclude.
1066 * This is used to compute "rev-list --ancestry-path A..B", as we need
1067 * to filter the result of "A..B" further to the ones that can actually
1070 static struct commit_list
*collect_bottom_commits(struct commit_list
*list
)
1072 struct commit_list
*elem
, *bottom
= NULL
;
1073 for (elem
= list
; elem
; elem
= elem
->next
)
1074 if (elem
->item
->object
.flags
& BOTTOM
)
1075 commit_list_insert(elem
->item
, &bottom
);
1079 /* Assumes either left_only or right_only is set */
1080 static void limit_left_right(struct commit_list
*list
, struct rev_info
*revs
)
1082 struct commit_list
*p
;
1084 for (p
= list
; p
; p
= p
->next
) {
1085 struct commit
*commit
= p
->item
;
1087 if (revs
->right_only
) {
1088 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
1089 commit
->object
.flags
|= SHOWN
;
1090 } else /* revs->left_only is set */
1091 if (!(commit
->object
.flags
& SYMMETRIC_LEFT
))
1092 commit
->object
.flags
|= SHOWN
;
1096 static int limit_list(struct rev_info
*revs
)
1099 timestamp_t date
= TIME_MAX
;
1100 struct commit_list
*list
= revs
->commits
;
1101 struct commit_list
*newlist
= NULL
;
1102 struct commit_list
**p
= &newlist
;
1103 struct commit_list
*bottom
= NULL
;
1104 struct commit
*interesting_cache
= NULL
;
1106 if (revs
->ancestry_path
) {
1107 bottom
= collect_bottom_commits(list
);
1109 die("--ancestry-path given but there are no bottom commits");
1113 struct commit
*commit
= pop_commit(&list
);
1114 struct object
*obj
= &commit
->object
;
1115 show_early_output_fn_t show
;
1117 if (commit
== interesting_cache
)
1118 interesting_cache
= NULL
;
1120 if (revs
->max_age
!= -1 && (commit
->date
< revs
->max_age
))
1121 obj
->flags
|= UNINTERESTING
;
1122 if (process_parents(revs
, commit
, &list
, NULL
) < 0)
1124 if (obj
->flags
& UNINTERESTING
) {
1125 mark_parents_uninteresting(commit
);
1126 slop
= still_interesting(list
, date
, slop
, &interesting_cache
);
1131 if (revs
->min_age
!= -1 && (commit
->date
> revs
->min_age
))
1133 date
= commit
->date
;
1134 p
= &commit_list_insert(commit
, p
)->next
;
1136 show
= show_early_output
;
1140 show(revs
, newlist
);
1141 show_early_output
= NULL
;
1143 if (revs
->cherry_pick
|| revs
->cherry_mark
)
1144 cherry_pick_list(newlist
, revs
);
1146 if (revs
->left_only
|| revs
->right_only
)
1147 limit_left_right(newlist
, revs
);
1150 limit_to_ancestry(bottom
, newlist
);
1151 free_commit_list(bottom
);
1155 * Check if any commits have become TREESAME by some of their parents
1156 * becoming UNINTERESTING.
1158 if (limiting_can_increase_treesame(revs
))
1159 for (list
= newlist
; list
; list
= list
->next
) {
1160 struct commit
*c
= list
->item
;
1161 if (c
->object
.flags
& (UNINTERESTING
| TREESAME
))
1163 update_treesame(revs
, c
);
1166 revs
->commits
= newlist
;
1171 * Add an entry to refs->cmdline with the specified information.
1174 static void add_rev_cmdline(struct rev_info
*revs
,
1175 struct object
*item
,
1180 struct rev_cmdline_info
*info
= &revs
->cmdline
;
1181 unsigned int nr
= info
->nr
;
1183 ALLOC_GROW(info
->rev
, nr
+ 1, info
->alloc
);
1184 info
->rev
[nr
].item
= item
;
1185 info
->rev
[nr
].name
= xstrdup(name
);
1186 info
->rev
[nr
].whence
= whence
;
1187 info
->rev
[nr
].flags
= flags
;
1191 static void add_rev_cmdline_list(struct rev_info
*revs
,
1192 struct commit_list
*commit_list
,
1196 while (commit_list
) {
1197 struct object
*object
= &commit_list
->item
->object
;
1198 add_rev_cmdline(revs
, object
, oid_to_hex(&object
->oid
),
1200 commit_list
= commit_list
->next
;
1204 struct all_refs_cb
{
1206 int warned_bad_reflog
;
1207 struct rev_info
*all_revs
;
1208 const char *name_for_errormsg
;
1209 struct worktree
*wt
;
1212 int ref_excluded(struct string_list
*ref_excludes
, const char *path
)
1214 struct string_list_item
*item
;
1218 for_each_string_list_item(item
, ref_excludes
) {
1219 if (!wildmatch(item
->string
, path
, 0))
1225 static int handle_one_ref(const char *path
, const struct object_id
*oid
,
1226 int flag
, void *cb_data
)
1228 struct all_refs_cb
*cb
= cb_data
;
1229 struct object
*object
;
1231 if (ref_excluded(cb
->all_revs
->ref_excludes
, path
))
1234 object
= get_reference(cb
->all_revs
, path
, oid
, cb
->all_flags
);
1235 add_rev_cmdline(cb
->all_revs
, object
, path
, REV_CMD_REF
, cb
->all_flags
);
1236 add_pending_oid(cb
->all_revs
, path
, oid
, cb
->all_flags
);
1240 static void init_all_refs_cb(struct all_refs_cb
*cb
, struct rev_info
*revs
,
1243 cb
->all_revs
= revs
;
1244 cb
->all_flags
= flags
;
1245 revs
->rev_input_given
= 1;
1249 void clear_ref_exclusion(struct string_list
**ref_excludes_p
)
1251 if (*ref_excludes_p
) {
1252 string_list_clear(*ref_excludes_p
, 0);
1253 free(*ref_excludes_p
);
1255 *ref_excludes_p
= NULL
;
1258 void add_ref_exclusion(struct string_list
**ref_excludes_p
, const char *exclude
)
1260 if (!*ref_excludes_p
) {
1261 *ref_excludes_p
= xcalloc(1, sizeof(**ref_excludes_p
));
1262 (*ref_excludes_p
)->strdup_strings
= 1;
1264 string_list_append(*ref_excludes_p
, exclude
);
1267 static void handle_refs(struct ref_store
*refs
,
1268 struct rev_info
*revs
, unsigned flags
,
1269 int (*for_each
)(struct ref_store
*, each_ref_fn
, void *))
1271 struct all_refs_cb cb
;
1274 /* this could happen with uninitialized submodules */
1278 init_all_refs_cb(&cb
, revs
, flags
);
1279 for_each(refs
, handle_one_ref
, &cb
);
1282 static void handle_one_reflog_commit(struct object_id
*oid
, void *cb_data
)
1284 struct all_refs_cb
*cb
= cb_data
;
1285 if (!is_null_oid(oid
)) {
1286 struct object
*o
= parse_object(cb
->all_revs
->repo
, oid
);
1288 o
->flags
|= cb
->all_flags
;
1289 /* ??? CMDLINEFLAGS ??? */
1290 add_pending_object(cb
->all_revs
, o
, "");
1292 else if (!cb
->warned_bad_reflog
) {
1293 warning("reflog of '%s' references pruned commits",
1294 cb
->name_for_errormsg
);
1295 cb
->warned_bad_reflog
= 1;
1300 static int handle_one_reflog_ent(struct object_id
*ooid
, struct object_id
*noid
,
1301 const char *email
, timestamp_t timestamp
, int tz
,
1302 const char *message
, void *cb_data
)
1304 handle_one_reflog_commit(ooid
, cb_data
);
1305 handle_one_reflog_commit(noid
, cb_data
);
1309 static int handle_one_reflog(const char *refname_in_wt
,
1310 const struct object_id
*oid
,
1311 int flag
, void *cb_data
)
1313 struct all_refs_cb
*cb
= cb_data
;
1314 struct strbuf refname
= STRBUF_INIT
;
1316 cb
->warned_bad_reflog
= 0;
1317 strbuf_worktree_ref(cb
->wt
, &refname
, refname_in_wt
);
1318 cb
->name_for_errormsg
= refname
.buf
;
1319 refs_for_each_reflog_ent(get_main_ref_store(the_repository
),
1321 handle_one_reflog_ent
, cb_data
);
1322 strbuf_release(&refname
);
1326 static void add_other_reflogs_to_pending(struct all_refs_cb
*cb
)
1328 struct worktree
**worktrees
, **p
;
1330 worktrees
= get_worktrees(0);
1331 for (p
= worktrees
; *p
; p
++) {
1332 struct worktree
*wt
= *p
;
1338 refs_for_each_reflog(get_worktree_ref_store(wt
),
1342 free_worktrees(worktrees
);
1345 void add_reflogs_to_pending(struct rev_info
*revs
, unsigned flags
)
1347 struct all_refs_cb cb
;
1350 cb
.all_flags
= flags
;
1352 for_each_reflog(handle_one_reflog
, &cb
);
1354 if (!revs
->single_worktree
)
1355 add_other_reflogs_to_pending(&cb
);
1358 static void add_cache_tree(struct cache_tree
*it
, struct rev_info
*revs
,
1359 struct strbuf
*path
, unsigned int flags
)
1361 size_t baselen
= path
->len
;
1364 if (it
->entry_count
>= 0) {
1365 struct tree
*tree
= lookup_tree(revs
->repo
, &it
->oid
);
1366 tree
->object
.flags
|= flags
;
1367 add_pending_object_with_path(revs
, &tree
->object
, "",
1371 for (i
= 0; i
< it
->subtree_nr
; i
++) {
1372 struct cache_tree_sub
*sub
= it
->down
[i
];
1373 strbuf_addf(path
, "%s%s", baselen
? "/" : "", sub
->name
);
1374 add_cache_tree(sub
->cache_tree
, revs
, path
, flags
);
1375 strbuf_setlen(path
, baselen
);
1380 static void do_add_index_objects_to_pending(struct rev_info
*revs
,
1381 struct index_state
*istate
,
1386 for (i
= 0; i
< istate
->cache_nr
; i
++) {
1387 struct cache_entry
*ce
= istate
->cache
[i
];
1390 if (S_ISGITLINK(ce
->ce_mode
))
1393 blob
= lookup_blob(revs
->repo
, &ce
->oid
);
1395 die("unable to add index blob to traversal");
1396 blob
->object
.flags
|= flags
;
1397 add_pending_object_with_path(revs
, &blob
->object
, "",
1398 ce
->ce_mode
, ce
->name
);
1401 if (istate
->cache_tree
) {
1402 struct strbuf path
= STRBUF_INIT
;
1403 add_cache_tree(istate
->cache_tree
, revs
, &path
, flags
);
1404 strbuf_release(&path
);
1408 void add_index_objects_to_pending(struct rev_info
*revs
, unsigned int flags
)
1410 struct worktree
**worktrees
, **p
;
1412 read_index(revs
->repo
->index
);
1413 do_add_index_objects_to_pending(revs
, revs
->repo
->index
, flags
);
1415 if (revs
->single_worktree
)
1418 worktrees
= get_worktrees(0);
1419 for (p
= worktrees
; *p
; p
++) {
1420 struct worktree
*wt
= *p
;
1421 struct index_state istate
= { NULL
};
1424 continue; /* current index already taken care of */
1426 if (read_index_from(&istate
,
1427 worktree_git_path(wt
, "index"),
1428 get_worktree_git_dir(wt
)) > 0)
1429 do_add_index_objects_to_pending(revs
, &istate
, flags
);
1430 discard_index(&istate
);
1432 free_worktrees(worktrees
);
1435 static int add_parents_only(struct rev_info
*revs
, const char *arg_
, int flags
,
1438 struct object_id oid
;
1440 struct commit
*commit
;
1441 struct commit_list
*parents
;
1443 const char *arg
= arg_
;
1446 flags
^= UNINTERESTING
| BOTTOM
;
1449 if (get_oid_committish(arg
, &oid
))
1452 it
= get_reference(revs
, arg
, &oid
, 0);
1453 if (!it
&& revs
->ignore_missing
)
1455 if (it
->type
!= OBJ_TAG
)
1457 if (!((struct tag
*)it
)->tagged
)
1459 oidcpy(&oid
, &((struct tag
*)it
)->tagged
->oid
);
1461 if (it
->type
!= OBJ_COMMIT
)
1463 commit
= (struct commit
*)it
;
1464 if (exclude_parent
&&
1465 exclude_parent
> commit_list_count(commit
->parents
))
1467 for (parents
= commit
->parents
, parent_number
= 1;
1469 parents
= parents
->next
, parent_number
++) {
1470 if (exclude_parent
&& parent_number
!= exclude_parent
)
1473 it
= &parents
->item
->object
;
1475 add_rev_cmdline(revs
, it
, arg_
, REV_CMD_PARENTS_ONLY
, flags
);
1476 add_pending_object(revs
, it
, arg
);
1481 void repo_init_revisions(struct repository
*r
,
1482 struct rev_info
*revs
,
1485 memset(revs
, 0, sizeof(*revs
));
1488 revs
->abbrev
= DEFAULT_ABBREV
;
1489 revs
->ignore_merges
= 1;
1490 revs
->simplify_history
= 1;
1491 revs
->pruning
.flags
.recursive
= 1;
1492 revs
->pruning
.flags
.quick
= 1;
1493 revs
->pruning
.add_remove
= file_add_remove
;
1494 revs
->pruning
.change
= file_change
;
1495 revs
->pruning
.change_fn_data
= revs
;
1496 revs
->sort_order
= REV_SORT_IN_GRAPH_ORDER
;
1498 revs
->prefix
= prefix
;
1501 revs
->skip_count
= -1;
1502 revs
->max_count
= -1;
1503 revs
->max_parents
= -1;
1504 revs
->expand_tabs_in_log
= -1;
1506 revs
->commit_format
= CMIT_FMT_DEFAULT
;
1507 revs
->expand_tabs_in_log_default
= 8;
1509 init_grep_defaults(revs
->repo
);
1510 grep_init(&revs
->grep_filter
, revs
->repo
, prefix
);
1511 revs
->grep_filter
.status_only
= 1;
1513 repo_diff_setup(revs
->repo
, &revs
->diffopt
);
1514 if (prefix
&& !revs
->diffopt
.prefix
) {
1515 revs
->diffopt
.prefix
= prefix
;
1516 revs
->diffopt
.prefix_length
= strlen(prefix
);
1519 revs
->notes_opt
.use_default_notes
= -1;
1522 static void add_pending_commit_list(struct rev_info
*revs
,
1523 struct commit_list
*commit_list
,
1526 while (commit_list
) {
1527 struct object
*object
= &commit_list
->item
->object
;
1528 object
->flags
|= flags
;
1529 add_pending_object(revs
, object
, oid_to_hex(&object
->oid
));
1530 commit_list
= commit_list
->next
;
1534 static void prepare_show_merge(struct rev_info
*revs
)
1536 struct commit_list
*bases
;
1537 struct commit
*head
, *other
;
1538 struct object_id oid
;
1539 const char **prune
= NULL
;
1540 int i
, prune_num
= 1; /* counting terminating NULL */
1541 struct index_state
*istate
= revs
->repo
->index
;
1543 if (get_oid("HEAD", &oid
))
1544 die("--merge without HEAD?");
1545 head
= lookup_commit_or_die(&oid
, "HEAD");
1546 if (get_oid("MERGE_HEAD", &oid
))
1547 die("--merge without MERGE_HEAD?");
1548 other
= lookup_commit_or_die(&oid
, "MERGE_HEAD");
1549 add_pending_object(revs
, &head
->object
, "HEAD");
1550 add_pending_object(revs
, &other
->object
, "MERGE_HEAD");
1551 bases
= get_merge_bases(head
, other
);
1552 add_rev_cmdline_list(revs
, bases
, REV_CMD_MERGE_BASE
, UNINTERESTING
| BOTTOM
);
1553 add_pending_commit_list(revs
, bases
, UNINTERESTING
| BOTTOM
);
1554 free_commit_list(bases
);
1555 head
->object
.flags
|= SYMMETRIC_LEFT
;
1557 if (!istate
->cache_nr
)
1559 for (i
= 0; i
< istate
->cache_nr
; i
++) {
1560 const struct cache_entry
*ce
= istate
->cache
[i
];
1563 if (ce_path_match(istate
, ce
, &revs
->prune_data
, NULL
)) {
1565 REALLOC_ARRAY(prune
, prune_num
);
1566 prune
[prune_num
-2] = ce
->name
;
1567 prune
[prune_num
-1] = NULL
;
1569 while ((i
+1 < istate
->cache_nr
) &&
1570 ce_same_name(ce
, istate
->cache
[i
+1]))
1573 clear_pathspec(&revs
->prune_data
);
1574 parse_pathspec(&revs
->prune_data
, PATHSPEC_ALL_MAGIC
& ~PATHSPEC_LITERAL
,
1575 PATHSPEC_PREFER_FULL
| PATHSPEC_LITERAL_PATH
, "", prune
);
1579 static int dotdot_missing(const char *arg
, char *dotdot
,
1580 struct rev_info
*revs
, int symmetric
)
1582 if (revs
->ignore_missing
)
1584 /* de-munge so we report the full argument */
1587 ? "Invalid symmetric difference expression %s"
1588 : "Invalid revision range %s", arg
);
1591 static int handle_dotdot_1(const char *arg
, char *dotdot
,
1592 struct rev_info
*revs
, int flags
,
1593 int cant_be_filename
,
1594 struct object_context
*a_oc
,
1595 struct object_context
*b_oc
)
1597 const char *a_name
, *b_name
;
1598 struct object_id a_oid
, b_oid
;
1599 struct object
*a_obj
, *b_obj
;
1600 unsigned int a_flags
, b_flags
;
1602 unsigned int flags_exclude
= flags
^ (UNINTERESTING
| BOTTOM
);
1603 unsigned int oc_flags
= GET_OID_COMMITTISH
| GET_OID_RECORD_PATH
;
1609 b_name
= dotdot
+ 2;
1610 if (*b_name
== '.') {
1617 if (get_oid_with_context(a_name
, oc_flags
, &a_oid
, a_oc
) ||
1618 get_oid_with_context(b_name
, oc_flags
, &b_oid
, b_oc
))
1621 if (!cant_be_filename
) {
1623 verify_non_filename(revs
->prefix
, arg
);
1627 a_obj
= parse_object(revs
->repo
, &a_oid
);
1628 b_obj
= parse_object(revs
->repo
, &b_oid
);
1629 if (!a_obj
|| !b_obj
)
1630 return dotdot_missing(arg
, dotdot
, revs
, symmetric
);
1635 a_flags
= flags_exclude
;
1637 /* A...B -- find merge bases between the two */
1638 struct commit
*a
, *b
;
1639 struct commit_list
*exclude
;
1641 a
= lookup_commit_reference(revs
->repo
, &a_obj
->oid
);
1642 b
= lookup_commit_reference(revs
->repo
, &b_obj
->oid
);
1644 return dotdot_missing(arg
, dotdot
, revs
, symmetric
);
1646 exclude
= get_merge_bases(a
, b
);
1647 add_rev_cmdline_list(revs
, exclude
, REV_CMD_MERGE_BASE
,
1649 add_pending_commit_list(revs
, exclude
, flags_exclude
);
1650 free_commit_list(exclude
);
1653 a_flags
= flags
| SYMMETRIC_LEFT
;
1656 a_obj
->flags
|= a_flags
;
1657 b_obj
->flags
|= b_flags
;
1658 add_rev_cmdline(revs
, a_obj
, a_name
, REV_CMD_LEFT
, a_flags
);
1659 add_rev_cmdline(revs
, b_obj
, b_name
, REV_CMD_RIGHT
, b_flags
);
1660 add_pending_object_with_path(revs
, a_obj
, a_name
, a_oc
->mode
, a_oc
->path
);
1661 add_pending_object_with_path(revs
, b_obj
, b_name
, b_oc
->mode
, b_oc
->path
);
1665 static int handle_dotdot(const char *arg
,
1666 struct rev_info
*revs
, int flags
,
1667 int cant_be_filename
)
1669 struct object_context a_oc
, b_oc
;
1670 char *dotdot
= strstr(arg
, "..");
1676 memset(&a_oc
, 0, sizeof(a_oc
));
1677 memset(&b_oc
, 0, sizeof(b_oc
));
1680 ret
= handle_dotdot_1(arg
, dotdot
, revs
, flags
, cant_be_filename
,
1690 int handle_revision_arg(const char *arg_
, struct rev_info
*revs
, int flags
, unsigned revarg_opt
)
1692 struct object_context oc
;
1694 struct object
*object
;
1695 struct object_id oid
;
1697 const char *arg
= arg_
;
1698 int cant_be_filename
= revarg_opt
& REVARG_CANNOT_BE_FILENAME
;
1699 unsigned get_sha1_flags
= GET_OID_RECORD_PATH
;
1701 flags
= flags
& UNINTERESTING
? flags
| BOTTOM
: flags
& ~BOTTOM
;
1703 if (!cant_be_filename
&& !strcmp(arg
, "..")) {
1705 * Just ".."? That is not a range but the
1706 * pathspec for the parent directory.
1711 if (!handle_dotdot(arg
, revs
, flags
, revarg_opt
))
1714 mark
= strstr(arg
, "^@");
1715 if (mark
&& !mark
[2]) {
1717 if (add_parents_only(revs
, arg
, flags
, 0))
1721 mark
= strstr(arg
, "^!");
1722 if (mark
&& !mark
[2]) {
1724 if (!add_parents_only(revs
, arg
, flags
^ (UNINTERESTING
| BOTTOM
), 0))
1727 mark
= strstr(arg
, "^-");
1729 int exclude_parent
= 1;
1733 exclude_parent
= strtoul(mark
+ 2, &end
, 10);
1734 if (*end
!= '\0' || !exclude_parent
)
1739 if (!add_parents_only(revs
, arg
, flags
^ (UNINTERESTING
| BOTTOM
), exclude_parent
))
1745 local_flags
= UNINTERESTING
| BOTTOM
;
1749 if (revarg_opt
& REVARG_COMMITTISH
)
1750 get_sha1_flags
|= GET_OID_COMMITTISH
;
1752 if (get_oid_with_context(arg
, get_sha1_flags
, &oid
, &oc
))
1753 return revs
->ignore_missing
? 0 : -1;
1754 if (!cant_be_filename
)
1755 verify_non_filename(revs
->prefix
, arg
);
1756 object
= get_reference(revs
, arg
, &oid
, flags
^ local_flags
);
1757 add_rev_cmdline(revs
, object
, arg_
, REV_CMD_REV
, flags
^ local_flags
);
1758 add_pending_object_with_path(revs
, object
, arg
, oc
.mode
, oc
.path
);
1763 static void read_pathspec_from_stdin(struct rev_info
*revs
, struct strbuf
*sb
,
1764 struct argv_array
*prune
)
1766 while (strbuf_getline(sb
, stdin
) != EOF
)
1767 argv_array_push(prune
, sb
->buf
);
1770 static void read_revisions_from_stdin(struct rev_info
*revs
,
1771 struct argv_array
*prune
)
1774 int seen_dashdash
= 0;
1777 save_warning
= warn_on_object_refname_ambiguity
;
1778 warn_on_object_refname_ambiguity
= 0;
1780 strbuf_init(&sb
, 1000);
1781 while (strbuf_getline(&sb
, stdin
) != EOF
) {
1785 if (sb
.buf
[0] == '-') {
1786 if (len
== 2 && sb
.buf
[1] == '-') {
1790 die("options not supported in --stdin mode");
1792 if (handle_revision_arg(sb
.buf
, revs
, 0,
1793 REVARG_CANNOT_BE_FILENAME
))
1794 die("bad revision '%s'", sb
.buf
);
1797 read_pathspec_from_stdin(revs
, &sb
, prune
);
1799 strbuf_release(&sb
);
1800 warn_on_object_refname_ambiguity
= save_warning
;
1803 static void add_grep(struct rev_info
*revs
, const char *ptn
, enum grep_pat_token what
)
1805 append_grep_pattern(&revs
->grep_filter
, ptn
, "command line", 0, what
);
1808 static void add_header_grep(struct rev_info
*revs
, enum grep_header_field field
, const char *pattern
)
1810 append_header_grep_pattern(&revs
->grep_filter
, field
, pattern
);
1813 static void add_message_grep(struct rev_info
*revs
, const char *pattern
)
1815 add_grep(revs
, pattern
, GREP_PATTERN_BODY
);
1818 static int handle_revision_opt(struct rev_info
*revs
, int argc
, const char **argv
,
1819 int *unkc
, const char **unkv
)
1821 const char *arg
= argv
[0];
1824 const unsigned hexsz
= the_hash_algo
->hexsz
;
1826 /* pseudo revision arguments */
1827 if (!strcmp(arg
, "--all") || !strcmp(arg
, "--branches") ||
1828 !strcmp(arg
, "--tags") || !strcmp(arg
, "--remotes") ||
1829 !strcmp(arg
, "--reflog") || !strcmp(arg
, "--not") ||
1830 !strcmp(arg
, "--no-walk") || !strcmp(arg
, "--do-walk") ||
1831 !strcmp(arg
, "--bisect") || starts_with(arg
, "--glob=") ||
1832 !strcmp(arg
, "--indexed-objects") ||
1833 starts_with(arg
, "--exclude=") ||
1834 starts_with(arg
, "--branches=") || starts_with(arg
, "--tags=") ||
1835 starts_with(arg
, "--remotes=") || starts_with(arg
, "--no-walk="))
1837 unkv
[(*unkc
)++] = arg
;
1841 if ((argcount
= parse_long_opt("max-count", argv
, &optarg
))) {
1842 revs
->max_count
= atoi(optarg
);
1845 } else if ((argcount
= parse_long_opt("skip", argv
, &optarg
))) {
1846 revs
->skip_count
= atoi(optarg
);
1848 } else if ((*arg
== '-') && isdigit(arg
[1])) {
1849 /* accept -<digit>, like traditional "head" */
1850 if (strtol_i(arg
+ 1, 10, &revs
->max_count
) < 0 ||
1851 revs
->max_count
< 0)
1852 die("'%s': not a non-negative integer", arg
+ 1);
1854 } else if (!strcmp(arg
, "-n")) {
1856 return error("-n requires an argument");
1857 revs
->max_count
= atoi(argv
[1]);
1860 } else if (skip_prefix(arg
, "-n", &optarg
)) {
1861 revs
->max_count
= atoi(optarg
);
1863 } else if ((argcount
= parse_long_opt("max-age", argv
, &optarg
))) {
1864 revs
->max_age
= atoi(optarg
);
1866 } else if ((argcount
= parse_long_opt("since", argv
, &optarg
))) {
1867 revs
->max_age
= approxidate(optarg
);
1869 } else if ((argcount
= parse_long_opt("after", argv
, &optarg
))) {
1870 revs
->max_age
= approxidate(optarg
);
1872 } else if ((argcount
= parse_long_opt("min-age", argv
, &optarg
))) {
1873 revs
->min_age
= atoi(optarg
);
1875 } else if ((argcount
= parse_long_opt("before", argv
, &optarg
))) {
1876 revs
->min_age
= approxidate(optarg
);
1878 } else if ((argcount
= parse_long_opt("until", argv
, &optarg
))) {
1879 revs
->min_age
= approxidate(optarg
);
1881 } else if (!strcmp(arg
, "--first-parent")) {
1882 revs
->first_parent_only
= 1;
1883 } else if (!strcmp(arg
, "--ancestry-path")) {
1884 revs
->ancestry_path
= 1;
1885 revs
->simplify_history
= 0;
1887 } else if (!strcmp(arg
, "-g") || !strcmp(arg
, "--walk-reflogs")) {
1888 init_reflog_walk(&revs
->reflog_info
);
1889 } else if (!strcmp(arg
, "--default")) {
1891 return error("bad --default argument");
1892 revs
->def
= argv
[1];
1894 } else if (!strcmp(arg
, "--merge")) {
1895 revs
->show_merge
= 1;
1896 } else if (!strcmp(arg
, "--topo-order")) {
1897 revs
->sort_order
= REV_SORT_IN_GRAPH_ORDER
;
1898 revs
->topo_order
= 1;
1899 } else if (!strcmp(arg
, "--simplify-merges")) {
1900 revs
->simplify_merges
= 1;
1901 revs
->topo_order
= 1;
1902 revs
->rewrite_parents
= 1;
1903 revs
->simplify_history
= 0;
1905 } else if (!strcmp(arg
, "--simplify-by-decoration")) {
1906 revs
->simplify_merges
= 1;
1907 revs
->topo_order
= 1;
1908 revs
->rewrite_parents
= 1;
1909 revs
->simplify_history
= 0;
1910 revs
->simplify_by_decoration
= 1;
1913 load_ref_decorations(NULL
, DECORATE_SHORT_REFS
);
1914 } else if (!strcmp(arg
, "--date-order")) {
1915 revs
->sort_order
= REV_SORT_BY_COMMIT_DATE
;
1916 revs
->topo_order
= 1;
1917 } else if (!strcmp(arg
, "--author-date-order")) {
1918 revs
->sort_order
= REV_SORT_BY_AUTHOR_DATE
;
1919 revs
->topo_order
= 1;
1920 } else if (!strcmp(arg
, "--early-output")) {
1921 revs
->early_output
= 100;
1922 revs
->topo_order
= 1;
1923 } else if (skip_prefix(arg
, "--early-output=", &optarg
)) {
1924 if (strtoul_ui(optarg
, 10, &revs
->early_output
) < 0)
1925 die("'%s': not a non-negative integer", optarg
);
1926 revs
->topo_order
= 1;
1927 } else if (!strcmp(arg
, "--parents")) {
1928 revs
->rewrite_parents
= 1;
1929 revs
->print_parents
= 1;
1930 } else if (!strcmp(arg
, "--dense")) {
1932 } else if (!strcmp(arg
, "--sparse")) {
1934 } else if (!strcmp(arg
, "--in-commit-order")) {
1935 revs
->tree_blobs_in_commit_order
= 1;
1936 } else if (!strcmp(arg
, "--remove-empty")) {
1937 revs
->remove_empty_trees
= 1;
1938 } else if (!strcmp(arg
, "--merges")) {
1939 revs
->min_parents
= 2;
1940 } else if (!strcmp(arg
, "--no-merges")) {
1941 revs
->max_parents
= 1;
1942 } else if (skip_prefix(arg
, "--min-parents=", &optarg
)) {
1943 revs
->min_parents
= atoi(optarg
);
1944 } else if (!strcmp(arg
, "--no-min-parents")) {
1945 revs
->min_parents
= 0;
1946 } else if (skip_prefix(arg
, "--max-parents=", &optarg
)) {
1947 revs
->max_parents
= atoi(optarg
);
1948 } else if (!strcmp(arg
, "--no-max-parents")) {
1949 revs
->max_parents
= -1;
1950 } else if (!strcmp(arg
, "--boundary")) {
1952 } else if (!strcmp(arg
, "--left-right")) {
1953 revs
->left_right
= 1;
1954 } else if (!strcmp(arg
, "--left-only")) {
1955 if (revs
->right_only
)
1956 die("--left-only is incompatible with --right-only"
1958 revs
->left_only
= 1;
1959 } else if (!strcmp(arg
, "--right-only")) {
1960 if (revs
->left_only
)
1961 die("--right-only is incompatible with --left-only");
1962 revs
->right_only
= 1;
1963 } else if (!strcmp(arg
, "--cherry")) {
1964 if (revs
->left_only
)
1965 die("--cherry is incompatible with --left-only");
1966 revs
->cherry_mark
= 1;
1967 revs
->right_only
= 1;
1968 revs
->max_parents
= 1;
1970 } else if (!strcmp(arg
, "--count")) {
1972 } else if (!strcmp(arg
, "--cherry-mark")) {
1973 if (revs
->cherry_pick
)
1974 die("--cherry-mark is incompatible with --cherry-pick");
1975 revs
->cherry_mark
= 1;
1976 revs
->limited
= 1; /* needs limit_list() */
1977 } else if (!strcmp(arg
, "--cherry-pick")) {
1978 if (revs
->cherry_mark
)
1979 die("--cherry-pick is incompatible with --cherry-mark");
1980 revs
->cherry_pick
= 1;
1982 } else if (!strcmp(arg
, "--objects")) {
1983 revs
->tag_objects
= 1;
1984 revs
->tree_objects
= 1;
1985 revs
->blob_objects
= 1;
1986 } else if (!strcmp(arg
, "--objects-edge")) {
1987 revs
->tag_objects
= 1;
1988 revs
->tree_objects
= 1;
1989 revs
->blob_objects
= 1;
1990 revs
->edge_hint
= 1;
1991 } else if (!strcmp(arg
, "--objects-edge-aggressive")) {
1992 revs
->tag_objects
= 1;
1993 revs
->tree_objects
= 1;
1994 revs
->blob_objects
= 1;
1995 revs
->edge_hint
= 1;
1996 revs
->edge_hint_aggressive
= 1;
1997 } else if (!strcmp(arg
, "--verify-objects")) {
1998 revs
->tag_objects
= 1;
1999 revs
->tree_objects
= 1;
2000 revs
->blob_objects
= 1;
2001 revs
->verify_objects
= 1;
2002 } else if (!strcmp(arg
, "--unpacked")) {
2004 } else if (starts_with(arg
, "--unpacked=")) {
2005 die("--unpacked=<packfile> no longer supported.");
2006 } else if (!strcmp(arg
, "-r")) {
2008 revs
->diffopt
.flags
.recursive
= 1;
2009 } else if (!strcmp(arg
, "-t")) {
2011 revs
->diffopt
.flags
.recursive
= 1;
2012 revs
->diffopt
.flags
.tree_in_recursive
= 1;
2013 } else if (!strcmp(arg
, "-m")) {
2014 revs
->ignore_merges
= 0;
2015 } else if (!strcmp(arg
, "-c")) {
2017 revs
->dense_combined_merges
= 0;
2018 revs
->combine_merges
= 1;
2019 } else if (!strcmp(arg
, "--cc")) {
2021 revs
->dense_combined_merges
= 1;
2022 revs
->combine_merges
= 1;
2023 } else if (!strcmp(arg
, "-v")) {
2024 revs
->verbose_header
= 1;
2025 } else if (!strcmp(arg
, "--pretty")) {
2026 revs
->verbose_header
= 1;
2027 revs
->pretty_given
= 1;
2028 get_commit_format(NULL
, revs
);
2029 } else if (skip_prefix(arg
, "--pretty=", &optarg
) ||
2030 skip_prefix(arg
, "--format=", &optarg
)) {
2032 * Detached form ("--pretty X" as opposed to "--pretty=X")
2033 * not allowed, since the argument is optional.
2035 revs
->verbose_header
= 1;
2036 revs
->pretty_given
= 1;
2037 get_commit_format(optarg
, revs
);
2038 } else if (!strcmp(arg
, "--expand-tabs")) {
2039 revs
->expand_tabs_in_log
= 8;
2040 } else if (!strcmp(arg
, "--no-expand-tabs")) {
2041 revs
->expand_tabs_in_log
= 0;
2042 } else if (skip_prefix(arg
, "--expand-tabs=", &arg
)) {
2044 if (strtol_i(arg
, 10, &val
) < 0 || val
< 0)
2045 die("'%s': not a non-negative integer", arg
);
2046 revs
->expand_tabs_in_log
= val
;
2047 } else if (!strcmp(arg
, "--show-notes") || !strcmp(arg
, "--notes")) {
2048 revs
->show_notes
= 1;
2049 revs
->show_notes_given
= 1;
2050 revs
->notes_opt
.use_default_notes
= 1;
2051 } else if (!strcmp(arg
, "--show-signature")) {
2052 revs
->show_signature
= 1;
2053 } else if (!strcmp(arg
, "--no-show-signature")) {
2054 revs
->show_signature
= 0;
2055 } else if (!strcmp(arg
, "--show-linear-break")) {
2056 revs
->break_bar
= " ..........";
2057 revs
->track_linear
= 1;
2058 revs
->track_first_time
= 1;
2059 } else if (skip_prefix(arg
, "--show-linear-break=", &optarg
)) {
2060 revs
->break_bar
= xstrdup(optarg
);
2061 revs
->track_linear
= 1;
2062 revs
->track_first_time
= 1;
2063 } else if (skip_prefix(arg
, "--show-notes=", &optarg
) ||
2064 skip_prefix(arg
, "--notes=", &optarg
)) {
2065 struct strbuf buf
= STRBUF_INIT
;
2066 revs
->show_notes
= 1;
2067 revs
->show_notes_given
= 1;
2068 if (starts_with(arg
, "--show-notes=") &&
2069 revs
->notes_opt
.use_default_notes
< 0)
2070 revs
->notes_opt
.use_default_notes
= 1;
2071 strbuf_addstr(&buf
, optarg
);
2072 expand_notes_ref(&buf
);
2073 string_list_append(&revs
->notes_opt
.extra_notes_refs
,
2074 strbuf_detach(&buf
, NULL
));
2075 } else if (!strcmp(arg
, "--no-notes")) {
2076 revs
->show_notes
= 0;
2077 revs
->show_notes_given
= 1;
2078 revs
->notes_opt
.use_default_notes
= -1;
2079 /* we have been strdup'ing ourselves, so trick
2080 * string_list into free()ing strings */
2081 revs
->notes_opt
.extra_notes_refs
.strdup_strings
= 1;
2082 string_list_clear(&revs
->notes_opt
.extra_notes_refs
, 0);
2083 revs
->notes_opt
.extra_notes_refs
.strdup_strings
= 0;
2084 } else if (!strcmp(arg
, "--standard-notes")) {
2085 revs
->show_notes_given
= 1;
2086 revs
->notes_opt
.use_default_notes
= 1;
2087 } else if (!strcmp(arg
, "--no-standard-notes")) {
2088 revs
->notes_opt
.use_default_notes
= 0;
2089 } else if (!strcmp(arg
, "--oneline")) {
2090 revs
->verbose_header
= 1;
2091 get_commit_format("oneline", revs
);
2092 revs
->pretty_given
= 1;
2093 revs
->abbrev_commit
= 1;
2094 } else if (!strcmp(arg
, "--graph")) {
2095 revs
->topo_order
= 1;
2096 revs
->rewrite_parents
= 1;
2097 revs
->graph
= graph_init(revs
);
2098 } else if (!strcmp(arg
, "--root")) {
2099 revs
->show_root_diff
= 1;
2100 } else if (!strcmp(arg
, "--no-commit-id")) {
2101 revs
->no_commit_id
= 1;
2102 } else if (!strcmp(arg
, "--always")) {
2103 revs
->always_show_header
= 1;
2104 } else if (!strcmp(arg
, "--no-abbrev")) {
2106 } else if (!strcmp(arg
, "--abbrev")) {
2107 revs
->abbrev
= DEFAULT_ABBREV
;
2108 } else if (skip_prefix(arg
, "--abbrev=", &optarg
)) {
2109 revs
->abbrev
= strtoul(optarg
, NULL
, 10);
2110 if (revs
->abbrev
< MINIMUM_ABBREV
)
2111 revs
->abbrev
= MINIMUM_ABBREV
;
2112 else if (revs
->abbrev
> hexsz
)
2113 revs
->abbrev
= hexsz
;
2114 } else if (!strcmp(arg
, "--abbrev-commit")) {
2115 revs
->abbrev_commit
= 1;
2116 revs
->abbrev_commit_given
= 1;
2117 } else if (!strcmp(arg
, "--no-abbrev-commit")) {
2118 revs
->abbrev_commit
= 0;
2119 } else if (!strcmp(arg
, "--full-diff")) {
2121 revs
->full_diff
= 1;
2122 } else if (!strcmp(arg
, "--full-history")) {
2123 revs
->simplify_history
= 0;
2124 } else if (!strcmp(arg
, "--relative-date")) {
2125 revs
->date_mode
.type
= DATE_RELATIVE
;
2126 revs
->date_mode_explicit
= 1;
2127 } else if ((argcount
= parse_long_opt("date", argv
, &optarg
))) {
2128 parse_date_format(optarg
, &revs
->date_mode
);
2129 revs
->date_mode_explicit
= 1;
2131 } else if (!strcmp(arg
, "--log-size")) {
2132 revs
->show_log_size
= 1;
2135 * Grepping the commit log
2137 else if ((argcount
= parse_long_opt("author", argv
, &optarg
))) {
2138 add_header_grep(revs
, GREP_HEADER_AUTHOR
, optarg
);
2140 } else if ((argcount
= parse_long_opt("committer", argv
, &optarg
))) {
2141 add_header_grep(revs
, GREP_HEADER_COMMITTER
, optarg
);
2143 } else if ((argcount
= parse_long_opt("grep-reflog", argv
, &optarg
))) {
2144 add_header_grep(revs
, GREP_HEADER_REFLOG
, optarg
);
2146 } else if ((argcount
= parse_long_opt("grep", argv
, &optarg
))) {
2147 add_message_grep(revs
, optarg
);
2149 } else if (!strcmp(arg
, "--grep-debug")) {
2150 revs
->grep_filter
.debug
= 1;
2151 } else if (!strcmp(arg
, "--basic-regexp")) {
2152 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_BRE
;
2153 } else if (!strcmp(arg
, "--extended-regexp") || !strcmp(arg
, "-E")) {
2154 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_ERE
;
2155 } else if (!strcmp(arg
, "--regexp-ignore-case") || !strcmp(arg
, "-i")) {
2156 revs
->grep_filter
.ignore_case
= 1;
2157 revs
->diffopt
.pickaxe_opts
|= DIFF_PICKAXE_IGNORE_CASE
;
2158 } else if (!strcmp(arg
, "--fixed-strings") || !strcmp(arg
, "-F")) {
2159 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_FIXED
;
2160 } else if (!strcmp(arg
, "--perl-regexp") || !strcmp(arg
, "-P")) {
2161 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_PCRE
;
2162 } else if (!strcmp(arg
, "--all-match")) {
2163 revs
->grep_filter
.all_match
= 1;
2164 } else if (!strcmp(arg
, "--invert-grep")) {
2165 revs
->invert_grep
= 1;
2166 } else if ((argcount
= parse_long_opt("encoding", argv
, &optarg
))) {
2167 if (strcmp(optarg
, "none"))
2168 git_log_output_encoding
= xstrdup(optarg
);
2170 git_log_output_encoding
= "";
2172 } else if (!strcmp(arg
, "--reverse")) {
2174 } else if (!strcmp(arg
, "--children")) {
2175 revs
->children
.name
= "children";
2177 } else if (!strcmp(arg
, "--ignore-missing")) {
2178 revs
->ignore_missing
= 1;
2179 } else if (revs
->allow_exclude_promisor_objects_opt
&&
2180 !strcmp(arg
, "--exclude-promisor-objects")) {
2181 if (fetch_if_missing
)
2182 BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0");
2183 revs
->exclude_promisor_objects
= 1;
2185 int opts
= diff_opt_parse(&revs
->diffopt
, argv
, argc
, revs
->prefix
);
2187 unkv
[(*unkc
)++] = arg
;
2190 if (revs
->graph
&& revs
->track_linear
)
2191 die("--show-linear-break and --graph are incompatible");
2196 void parse_revision_opt(struct rev_info
*revs
, struct parse_opt_ctx_t
*ctx
,
2197 const struct option
*options
,
2198 const char * const usagestr
[])
2200 int n
= handle_revision_opt(revs
, ctx
->argc
, ctx
->argv
,
2201 &ctx
->cpidx
, ctx
->out
);
2203 error("unknown option `%s'", ctx
->argv
[0]);
2204 usage_with_options(usagestr
, options
);
2210 static int for_each_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
,
2211 void *cb_data
, const char *term
)
2213 struct strbuf bisect_refs
= STRBUF_INIT
;
2215 strbuf_addf(&bisect_refs
, "refs/bisect/%s", term
);
2216 status
= refs_for_each_fullref_in(refs
, bisect_refs
.buf
, fn
, cb_data
, 0);
2217 strbuf_release(&bisect_refs
);
2221 static int for_each_bad_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
, void *cb_data
)
2223 return for_each_bisect_ref(refs
, fn
, cb_data
, term_bad
);
2226 static int for_each_good_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
, void *cb_data
)
2228 return for_each_bisect_ref(refs
, fn
, cb_data
, term_good
);
2231 static int handle_revision_pseudo_opt(const char *submodule
,
2232 struct rev_info
*revs
,
2233 int argc
, const char **argv
, int *flags
)
2235 const char *arg
= argv
[0];
2237 struct ref_store
*refs
;
2242 * We need some something like get_submodule_worktrees()
2243 * before we can go through all worktrees of a submodule,
2244 * .e.g with adding all HEADs from --all, which is not
2245 * supported right now, so stick to single worktree.
2247 if (!revs
->single_worktree
)
2248 BUG("--single-worktree cannot be used together with submodule");
2249 refs
= get_submodule_ref_store(submodule
);
2251 refs
= get_main_ref_store(revs
->repo
);
2256 * Commands like "git shortlog" will not accept the options below
2257 * unless parse_revision_opt queues them (as opposed to erroring
2260 * When implementing your new pseudo-option, remember to
2261 * register it in the list at the top of handle_revision_opt.
2263 if (!strcmp(arg
, "--all")) {
2264 handle_refs(refs
, revs
, *flags
, refs_for_each_ref
);
2265 handle_refs(refs
, revs
, *flags
, refs_head_ref
);
2266 if (!revs
->single_worktree
) {
2267 struct all_refs_cb cb
;
2269 init_all_refs_cb(&cb
, revs
, *flags
);
2270 other_head_refs(handle_one_ref
, &cb
);
2272 clear_ref_exclusion(&revs
->ref_excludes
);
2273 } else if (!strcmp(arg
, "--branches")) {
2274 handle_refs(refs
, revs
, *flags
, refs_for_each_branch_ref
);
2275 clear_ref_exclusion(&revs
->ref_excludes
);
2276 } else if (!strcmp(arg
, "--bisect")) {
2277 read_bisect_terms(&term_bad
, &term_good
);
2278 handle_refs(refs
, revs
, *flags
, for_each_bad_bisect_ref
);
2279 handle_refs(refs
, revs
, *flags
^ (UNINTERESTING
| BOTTOM
),
2280 for_each_good_bisect_ref
);
2282 } else if (!strcmp(arg
, "--tags")) {
2283 handle_refs(refs
, revs
, *flags
, refs_for_each_tag_ref
);
2284 clear_ref_exclusion(&revs
->ref_excludes
);
2285 } else if (!strcmp(arg
, "--remotes")) {
2286 handle_refs(refs
, revs
, *flags
, refs_for_each_remote_ref
);
2287 clear_ref_exclusion(&revs
->ref_excludes
);
2288 } else if ((argcount
= parse_long_opt("glob", argv
, &optarg
))) {
2289 struct all_refs_cb cb
;
2290 init_all_refs_cb(&cb
, revs
, *flags
);
2291 for_each_glob_ref(handle_one_ref
, optarg
, &cb
);
2292 clear_ref_exclusion(&revs
->ref_excludes
);
2294 } else if ((argcount
= parse_long_opt("exclude", argv
, &optarg
))) {
2295 add_ref_exclusion(&revs
->ref_excludes
, optarg
);
2297 } else if (skip_prefix(arg
, "--branches=", &optarg
)) {
2298 struct all_refs_cb cb
;
2299 init_all_refs_cb(&cb
, revs
, *flags
);
2300 for_each_glob_ref_in(handle_one_ref
, optarg
, "refs/heads/", &cb
);
2301 clear_ref_exclusion(&revs
->ref_excludes
);
2302 } else if (skip_prefix(arg
, "--tags=", &optarg
)) {
2303 struct all_refs_cb cb
;
2304 init_all_refs_cb(&cb
, revs
, *flags
);
2305 for_each_glob_ref_in(handle_one_ref
, optarg
, "refs/tags/", &cb
);
2306 clear_ref_exclusion(&revs
->ref_excludes
);
2307 } else if (skip_prefix(arg
, "--remotes=", &optarg
)) {
2308 struct all_refs_cb cb
;
2309 init_all_refs_cb(&cb
, revs
, *flags
);
2310 for_each_glob_ref_in(handle_one_ref
, optarg
, "refs/remotes/", &cb
);
2311 clear_ref_exclusion(&revs
->ref_excludes
);
2312 } else if (!strcmp(arg
, "--reflog")) {
2313 add_reflogs_to_pending(revs
, *flags
);
2314 } else if (!strcmp(arg
, "--indexed-objects")) {
2315 add_index_objects_to_pending(revs
, *flags
);
2316 } else if (!strcmp(arg
, "--not")) {
2317 *flags
^= UNINTERESTING
| BOTTOM
;
2318 } else if (!strcmp(arg
, "--no-walk")) {
2319 revs
->no_walk
= REVISION_WALK_NO_WALK_SORTED
;
2320 } else if (skip_prefix(arg
, "--no-walk=", &optarg
)) {
2322 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
2323 * not allowed, since the argument is optional.
2325 if (!strcmp(optarg
, "sorted"))
2326 revs
->no_walk
= REVISION_WALK_NO_WALK_SORTED
;
2327 else if (!strcmp(optarg
, "unsorted"))
2328 revs
->no_walk
= REVISION_WALK_NO_WALK_UNSORTED
;
2330 return error("invalid argument to --no-walk");
2331 } else if (!strcmp(arg
, "--do-walk")) {
2333 } else if (!strcmp(arg
, "--single-worktree")) {
2334 revs
->single_worktree
= 1;
2342 static void NORETURN
diagnose_missing_default(const char *def
)
2345 const char *refname
;
2347 refname
= resolve_ref_unsafe(def
, 0, NULL
, &flags
);
2348 if (!refname
|| !(flags
& REF_ISSYMREF
) || (flags
& REF_ISBROKEN
))
2349 die(_("your current branch appears to be broken"));
2351 skip_prefix(refname
, "refs/heads/", &refname
);
2352 die(_("your current branch '%s' does not have any commits yet"),
2357 * Parse revision information, filling in the "rev_info" structure,
2358 * and removing the used arguments from the argument list.
2360 * Returns the number of arguments left that weren't recognized
2361 * (which are also moved to the head of the argument list)
2363 int setup_revisions(int argc
, const char **argv
, struct rev_info
*revs
, struct setup_revision_opt
*opt
)
2365 int i
, flags
, left
, seen_dashdash
, got_rev_arg
= 0, revarg_opt
;
2366 struct argv_array prune_data
= ARGV_ARRAY_INIT
;
2367 const char *submodule
= NULL
;
2370 submodule
= opt
->submodule
;
2372 /* First, search for "--" */
2373 if (opt
&& opt
->assume_dashdash
) {
2377 for (i
= 1; i
< argc
; i
++) {
2378 const char *arg
= argv
[i
];
2379 if (strcmp(arg
, "--"))
2384 argv_array_pushv(&prune_data
, argv
+ i
+ 1);
2390 /* Second, deal with arguments and options */
2392 revarg_opt
= opt
? opt
->revarg_opt
: 0;
2394 revarg_opt
|= REVARG_CANNOT_BE_FILENAME
;
2395 for (left
= i
= 1; i
< argc
; i
++) {
2396 const char *arg
= argv
[i
];
2400 opts
= handle_revision_pseudo_opt(submodule
,
2401 revs
, argc
- i
, argv
+ i
,
2408 if (!strcmp(arg
, "--stdin")) {
2409 if (revs
->disable_stdin
) {
2413 if (revs
->read_from_stdin
++)
2414 die("--stdin given twice?");
2415 read_revisions_from_stdin(revs
, &prune_data
);
2419 opts
= handle_revision_opt(revs
, argc
- i
, argv
+ i
, &left
, argv
);
2430 if (handle_revision_arg(arg
, revs
, flags
, revarg_opt
)) {
2432 if (seen_dashdash
|| *arg
== '^')
2433 die("bad revision '%s'", arg
);
2435 /* If we didn't have a "--":
2436 * (1) all filenames must exist;
2437 * (2) all rev-args must not be interpretable
2438 * as a valid filename.
2439 * but the latter we have checked in the main loop.
2441 for (j
= i
; j
< argc
; j
++)
2442 verify_filename(revs
->prefix
, argv
[j
], j
== i
);
2444 argv_array_pushv(&prune_data
, argv
+ i
);
2451 if (prune_data
.argc
) {
2453 * If we need to introduce the magic "a lone ':' means no
2454 * pathspec whatsoever", here is the place to do so.
2456 * if (prune_data.nr == 1 && !strcmp(prune_data[0], ":")) {
2457 * prune_data.nr = 0;
2458 * prune_data.alloc = 0;
2459 * free(prune_data.path);
2460 * prune_data.path = NULL;
2462 * terminate prune_data.alloc with NULL and
2463 * call init_pathspec() to set revs->prune_data here.
2466 parse_pathspec(&revs
->prune_data
, 0, 0,
2467 revs
->prefix
, prune_data
.argv
);
2469 argv_array_clear(&prune_data
);
2471 if (revs
->def
== NULL
)
2472 revs
->def
= opt
? opt
->def
: NULL
;
2473 if (opt
&& opt
->tweak
)
2474 opt
->tweak(revs
, opt
);
2475 if (revs
->show_merge
)
2476 prepare_show_merge(revs
);
2477 if (revs
->def
&& !revs
->pending
.nr
&& !revs
->rev_input_given
&& !got_rev_arg
) {
2478 struct object_id oid
;
2479 struct object
*object
;
2480 struct object_context oc
;
2481 if (get_oid_with_context(revs
->def
, 0, &oid
, &oc
))
2482 diagnose_missing_default(revs
->def
);
2483 object
= get_reference(revs
, revs
->def
, &oid
, 0);
2484 add_pending_object_with_mode(revs
, object
, revs
->def
, oc
.mode
);
2487 /* Did the user ask for any diff output? Run the diff! */
2488 if (revs
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
)
2491 /* Pickaxe, diff-filter and rename following need diffs */
2492 if ((revs
->diffopt
.pickaxe_opts
& DIFF_PICKAXE_KINDS_MASK
) ||
2493 revs
->diffopt
.filter
||
2494 revs
->diffopt
.flags
.follow_renames
)
2497 if (revs
->diffopt
.objfind
)
2498 revs
->simplify_history
= 0;
2500 if (revs
->topo_order
&& !generation_numbers_enabled(the_repository
))
2503 if (revs
->prune_data
.nr
) {
2504 copy_pathspec(&revs
->pruning
.pathspec
, &revs
->prune_data
);
2505 /* Can't prune commits with rename following: the paths change.. */
2506 if (!revs
->diffopt
.flags
.follow_renames
)
2508 if (!revs
->full_diff
)
2509 copy_pathspec(&revs
->diffopt
.pathspec
,
2512 if (revs
->combine_merges
)
2513 revs
->ignore_merges
= 0;
2514 revs
->diffopt
.abbrev
= revs
->abbrev
;
2516 if (revs
->line_level_traverse
) {
2518 revs
->topo_order
= 1;
2521 diff_setup_done(&revs
->diffopt
);
2523 grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED
,
2524 &revs
->grep_filter
);
2525 compile_grep_patterns(&revs
->grep_filter
);
2527 if (revs
->reverse
&& revs
->reflog_info
)
2528 die("cannot combine --reverse with --walk-reflogs");
2529 if (revs
->reflog_info
&& revs
->limited
)
2530 die("cannot combine --walk-reflogs with history-limiting options");
2531 if (revs
->rewrite_parents
&& revs
->children
.name
)
2532 die("cannot combine --parents and --children");
2535 * Limitations on the graph functionality
2537 if (revs
->reverse
&& revs
->graph
)
2538 die("cannot combine --reverse with --graph");
2540 if (revs
->reflog_info
&& revs
->graph
)
2541 die("cannot combine --walk-reflogs with --graph");
2542 if (revs
->no_walk
&& revs
->graph
)
2543 die("cannot combine --no-walk with --graph");
2544 if (!revs
->reflog_info
&& revs
->grep_filter
.use_reflog_filter
)
2545 die("cannot use --grep-reflog without --walk-reflogs");
2547 if (revs
->first_parent_only
&& revs
->bisect
)
2548 die(_("--first-parent is incompatible with --bisect"));
2550 if (revs
->expand_tabs_in_log
< 0)
2551 revs
->expand_tabs_in_log
= revs
->expand_tabs_in_log_default
;
2556 static void add_child(struct rev_info
*revs
, struct commit
*parent
, struct commit
*child
)
2558 struct commit_list
*l
= xcalloc(1, sizeof(*l
));
2561 l
->next
= add_decoration(&revs
->children
, &parent
->object
, l
);
2564 static int remove_duplicate_parents(struct rev_info
*revs
, struct commit
*commit
)
2566 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
2567 struct commit_list
**pp
, *p
;
2568 int surviving_parents
;
2570 /* Examine existing parents while marking ones we have seen... */
2571 pp
= &commit
->parents
;
2572 surviving_parents
= 0;
2573 while ((p
= *pp
) != NULL
) {
2574 struct commit
*parent
= p
->item
;
2575 if (parent
->object
.flags
& TMP_MARK
) {
2578 compact_treesame(revs
, commit
, surviving_parents
);
2581 parent
->object
.flags
|= TMP_MARK
;
2582 surviving_parents
++;
2585 /* clear the temporary mark */
2586 for (p
= commit
->parents
; p
; p
= p
->next
) {
2587 p
->item
->object
.flags
&= ~TMP_MARK
;
2589 /* no update_treesame() - removing duplicates can't affect TREESAME */
2590 return surviving_parents
;
2593 struct merge_simplify_state
{
2594 struct commit
*simplified
;
2597 static struct merge_simplify_state
*locate_simplify_state(struct rev_info
*revs
, struct commit
*commit
)
2599 struct merge_simplify_state
*st
;
2601 st
= lookup_decoration(&revs
->merge_simplification
, &commit
->object
);
2603 st
= xcalloc(1, sizeof(*st
));
2604 add_decoration(&revs
->merge_simplification
, &commit
->object
, st
);
2609 static int mark_redundant_parents(struct rev_info
*revs
, struct commit
*commit
)
2611 struct commit_list
*h
= reduce_heads(commit
->parents
);
2612 int i
= 0, marked
= 0;
2613 struct commit_list
*po
, *pn
;
2615 /* Want these for sanity-checking only */
2616 int orig_cnt
= commit_list_count(commit
->parents
);
2617 int cnt
= commit_list_count(h
);
2620 * Not ready to remove items yet, just mark them for now, based
2621 * on the output of reduce_heads(). reduce_heads outputs the reduced
2622 * set in its original order, so this isn't too hard.
2624 po
= commit
->parents
;
2627 if (pn
&& po
->item
== pn
->item
) {
2631 po
->item
->object
.flags
|= TMP_MARK
;
2637 if (i
!= cnt
|| cnt
+marked
!= orig_cnt
)
2638 die("mark_redundant_parents %d %d %d %d", orig_cnt
, cnt
, i
, marked
);
2640 free_commit_list(h
);
2645 static int mark_treesame_root_parents(struct rev_info
*revs
, struct commit
*commit
)
2647 struct commit_list
*p
;
2650 for (p
= commit
->parents
; p
; p
= p
->next
) {
2651 struct commit
*parent
= p
->item
;
2652 if (!parent
->parents
&& (parent
->object
.flags
& TREESAME
)) {
2653 parent
->object
.flags
|= TMP_MARK
;
2662 * Awkward naming - this means one parent we are TREESAME to.
2663 * cf mark_treesame_root_parents: root parents that are TREESAME (to an
2664 * empty tree). Better name suggestions?
2666 static int leave_one_treesame_to_parent(struct rev_info
*revs
, struct commit
*commit
)
2668 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
2669 struct commit
*unmarked
= NULL
, *marked
= NULL
;
2670 struct commit_list
*p
;
2673 for (p
= commit
->parents
, n
= 0; p
; p
= p
->next
, n
++) {
2674 if (ts
->treesame
[n
]) {
2675 if (p
->item
->object
.flags
& TMP_MARK
) {
2688 * If we are TREESAME to a marked-for-deletion parent, but not to any
2689 * unmarked parents, unmark the first TREESAME parent. This is the
2690 * parent that the default simplify_history==1 scan would have followed,
2691 * and it doesn't make sense to omit that path when asking for a
2692 * simplified full history. Retaining it improves the chances of
2693 * understanding odd missed merges that took an old version of a file.
2697 * I--------*X A modified the file, but mainline merge X used
2698 * \ / "-s ours", so took the version from I. X is
2699 * `-*A--' TREESAME to I and !TREESAME to A.
2701 * Default log from X would produce "I". Without this check,
2702 * --full-history --simplify-merges would produce "I-A-X", showing
2703 * the merge commit X and that it changed A, but not making clear that
2704 * it had just taken the I version. With this check, the topology above
2707 * Note that it is possible that the simplification chooses a different
2708 * TREESAME parent from the default, in which case this test doesn't
2709 * activate, and we _do_ drop the default parent. Example:
2711 * I------X A modified the file, but it was reverted in B,
2712 * \ / meaning mainline merge X is TREESAME to both
2715 * Default log would produce "I" by following the first parent;
2716 * --full-history --simplify-merges will produce "I-A-B". But this is a
2717 * reasonable result - it presents a logical full history leading from
2718 * I to X, and X is not an important merge.
2720 if (!unmarked
&& marked
) {
2721 marked
->object
.flags
&= ~TMP_MARK
;
2728 static int remove_marked_parents(struct rev_info
*revs
, struct commit
*commit
)
2730 struct commit_list
**pp
, *p
;
2731 int nth_parent
, removed
= 0;
2733 pp
= &commit
->parents
;
2735 while ((p
= *pp
) != NULL
) {
2736 struct commit
*parent
= p
->item
;
2737 if (parent
->object
.flags
& TMP_MARK
) {
2738 parent
->object
.flags
&= ~TMP_MARK
;
2742 compact_treesame(revs
, commit
, nth_parent
);
2749 /* Removing parents can only increase TREESAMEness */
2750 if (removed
&& !(commit
->object
.flags
& TREESAME
))
2751 update_treesame(revs
, commit
);
2756 static struct commit_list
**simplify_one(struct rev_info
*revs
, struct commit
*commit
, struct commit_list
**tail
)
2758 struct commit_list
*p
;
2759 struct commit
*parent
;
2760 struct merge_simplify_state
*st
, *pst
;
2763 st
= locate_simplify_state(revs
, commit
);
2766 * Have we handled this one?
2772 * An UNINTERESTING commit simplifies to itself, so does a
2773 * root commit. We do not rewrite parents of such commit
2776 if ((commit
->object
.flags
& UNINTERESTING
) || !commit
->parents
) {
2777 st
->simplified
= commit
;
2782 * Do we know what commit all of our parents that matter
2783 * should be rewritten to? Otherwise we are not ready to
2784 * rewrite this one yet.
2786 for (cnt
= 0, p
= commit
->parents
; p
; p
= p
->next
) {
2787 pst
= locate_simplify_state(revs
, p
->item
);
2788 if (!pst
->simplified
) {
2789 tail
= &commit_list_insert(p
->item
, tail
)->next
;
2792 if (revs
->first_parent_only
)
2796 tail
= &commit_list_insert(commit
, tail
)->next
;
2801 * Rewrite our list of parents. Note that this cannot
2802 * affect our TREESAME flags in any way - a commit is
2803 * always TREESAME to its simplification.
2805 for (p
= commit
->parents
; p
; p
= p
->next
) {
2806 pst
= locate_simplify_state(revs
, p
->item
);
2807 p
->item
= pst
->simplified
;
2808 if (revs
->first_parent_only
)
2812 if (revs
->first_parent_only
)
2815 cnt
= remove_duplicate_parents(revs
, commit
);
2818 * It is possible that we are a merge and one side branch
2819 * does not have any commit that touches the given paths;
2820 * in such a case, the immediate parent from that branch
2821 * will be rewritten to be the merge base.
2823 * o----X X: the commit we are looking at;
2824 * / / o: a commit that touches the paths;
2827 * Further, a merge of an independent branch that doesn't
2828 * touch the path will reduce to a treesame root parent:
2830 * ----o----X X: the commit we are looking at;
2831 * / o: a commit that touches the paths;
2832 * r r: a root commit not touching the paths
2834 * Detect and simplify both cases.
2837 int marked
= mark_redundant_parents(revs
, commit
);
2838 marked
+= mark_treesame_root_parents(revs
, commit
);
2840 marked
-= leave_one_treesame_to_parent(revs
, commit
);
2842 cnt
= remove_marked_parents(revs
, commit
);
2846 * A commit simplifies to itself if it is a root, if it is
2847 * UNINTERESTING, if it touches the given paths, or if it is a
2848 * merge and its parents don't simplify to one relevant commit
2849 * (the first two cases are already handled at the beginning of
2852 * Otherwise, it simplifies to what its sole relevant parent
2856 (commit
->object
.flags
& UNINTERESTING
) ||
2857 !(commit
->object
.flags
& TREESAME
) ||
2858 (parent
= one_relevant_parent(revs
, commit
->parents
)) == NULL
)
2859 st
->simplified
= commit
;
2861 pst
= locate_simplify_state(revs
, parent
);
2862 st
->simplified
= pst
->simplified
;
2867 static void simplify_merges(struct rev_info
*revs
)
2869 struct commit_list
*list
, *next
;
2870 struct commit_list
*yet_to_do
, **tail
;
2871 struct commit
*commit
;
2876 /* feed the list reversed */
2878 for (list
= revs
->commits
; list
; list
= next
) {
2879 commit
= list
->item
;
2882 * Do not free(list) here yet; the original list
2883 * is used later in this function.
2885 commit_list_insert(commit
, &yet_to_do
);
2892 commit
= pop_commit(&list
);
2893 tail
= simplify_one(revs
, commit
, tail
);
2897 /* clean up the result, removing the simplified ones */
2898 list
= revs
->commits
;
2899 revs
->commits
= NULL
;
2900 tail
= &revs
->commits
;
2902 struct merge_simplify_state
*st
;
2904 commit
= pop_commit(&list
);
2905 st
= locate_simplify_state(revs
, commit
);
2906 if (st
->simplified
== commit
)
2907 tail
= &commit_list_insert(commit
, tail
)->next
;
2911 static void set_children(struct rev_info
*revs
)
2913 struct commit_list
*l
;
2914 for (l
= revs
->commits
; l
; l
= l
->next
) {
2915 struct commit
*commit
= l
->item
;
2916 struct commit_list
*p
;
2918 for (p
= commit
->parents
; p
; p
= p
->next
)
2919 add_child(revs
, p
->item
, commit
);
2923 void reset_revision_walk(void)
2925 clear_object_flags(SEEN
| ADDED
| SHOWN
);
2928 static int mark_uninteresting(const struct object_id
*oid
,
2929 struct packed_git
*pack
,
2933 struct rev_info
*revs
= cb
;
2934 struct object
*o
= parse_object(revs
->repo
, oid
);
2935 o
->flags
|= UNINTERESTING
| SEEN
;
2939 define_commit_slab(indegree_slab
, int);
2940 define_commit_slab(author_date_slab
, timestamp_t
);
2942 struct topo_walk_info
{
2943 uint32_t min_generation
;
2944 struct prio_queue explore_queue
;
2945 struct prio_queue indegree_queue
;
2946 struct prio_queue topo_queue
;
2947 struct indegree_slab indegree
;
2948 struct author_date_slab author_date
;
2951 static inline void test_flag_and_insert(struct prio_queue
*q
, struct commit
*c
, int flag
)
2953 if (c
->object
.flags
& flag
)
2956 c
->object
.flags
|= flag
;
2957 prio_queue_put(q
, c
);
2960 static void explore_walk_step(struct rev_info
*revs
)
2962 struct topo_walk_info
*info
= revs
->topo_walk_info
;
2963 struct commit_list
*p
;
2964 struct commit
*c
= prio_queue_get(&info
->explore_queue
);
2969 if (parse_commit_gently(c
, 1) < 0)
2972 if (revs
->sort_order
== REV_SORT_BY_AUTHOR_DATE
)
2973 record_author_date(&info
->author_date
, c
);
2975 if (revs
->max_age
!= -1 && (c
->date
< revs
->max_age
))
2976 c
->object
.flags
|= UNINTERESTING
;
2978 if (process_parents(revs
, c
, NULL
, NULL
) < 0)
2981 if (c
->object
.flags
& UNINTERESTING
)
2982 mark_parents_uninteresting(c
);
2984 for (p
= c
->parents
; p
; p
= p
->next
)
2985 test_flag_and_insert(&info
->explore_queue
, p
->item
, TOPO_WALK_EXPLORED
);
2988 static void explore_to_depth(struct rev_info
*revs
,
2989 uint32_t gen_cutoff
)
2991 struct topo_walk_info
*info
= revs
->topo_walk_info
;
2993 while ((c
= prio_queue_peek(&info
->explore_queue
)) &&
2994 c
->generation
>= gen_cutoff
)
2995 explore_walk_step(revs
);
2998 static void indegree_walk_step(struct rev_info
*revs
)
3000 struct commit_list
*p
;
3001 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3002 struct commit
*c
= prio_queue_get(&info
->indegree_queue
);
3007 if (parse_commit_gently(c
, 1) < 0)
3010 explore_to_depth(revs
, c
->generation
);
3012 for (p
= c
->parents
; p
; p
= p
->next
) {
3013 struct commit
*parent
= p
->item
;
3014 int *pi
= indegree_slab_at(&info
->indegree
, parent
);
3021 test_flag_and_insert(&info
->indegree_queue
, parent
, TOPO_WALK_INDEGREE
);
3023 if (revs
->first_parent_only
)
3028 static void compute_indegrees_to_depth(struct rev_info
*revs
,
3029 uint32_t gen_cutoff
)
3031 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3033 while ((c
= prio_queue_peek(&info
->indegree_queue
)) &&
3034 c
->generation
>= gen_cutoff
)
3035 indegree_walk_step(revs
);
3038 static void init_topo_walk(struct rev_info
*revs
)
3040 struct topo_walk_info
*info
;
3041 struct commit_list
*list
;
3042 revs
->topo_walk_info
= xmalloc(sizeof(struct topo_walk_info
));
3043 info
= revs
->topo_walk_info
;
3044 memset(info
, 0, sizeof(struct topo_walk_info
));
3046 init_indegree_slab(&info
->indegree
);
3047 memset(&info
->explore_queue
, 0, sizeof(info
->explore_queue
));
3048 memset(&info
->indegree_queue
, 0, sizeof(info
->indegree_queue
));
3049 memset(&info
->topo_queue
, 0, sizeof(info
->topo_queue
));
3051 switch (revs
->sort_order
) {
3052 default: /* REV_SORT_IN_GRAPH_ORDER */
3053 info
->topo_queue
.compare
= NULL
;
3055 case REV_SORT_BY_COMMIT_DATE
:
3056 info
->topo_queue
.compare
= compare_commits_by_commit_date
;
3058 case REV_SORT_BY_AUTHOR_DATE
:
3059 init_author_date_slab(&info
->author_date
);
3060 info
->topo_queue
.compare
= compare_commits_by_author_date
;
3061 info
->topo_queue
.cb_data
= &info
->author_date
;
3065 info
->explore_queue
.compare
= compare_commits_by_gen_then_commit_date
;
3066 info
->indegree_queue
.compare
= compare_commits_by_gen_then_commit_date
;
3068 info
->min_generation
= GENERATION_NUMBER_INFINITY
;
3069 for (list
= revs
->commits
; list
; list
= list
->next
) {
3070 struct commit
*c
= list
->item
;
3072 if (parse_commit_gently(c
, 1))
3075 test_flag_and_insert(&info
->explore_queue
, c
, TOPO_WALK_EXPLORED
);
3076 test_flag_and_insert(&info
->indegree_queue
, c
, TOPO_WALK_INDEGREE
);
3078 if (c
->generation
< info
->min_generation
)
3079 info
->min_generation
= c
->generation
;
3081 *(indegree_slab_at(&info
->indegree
, c
)) = 1;
3083 if (revs
->sort_order
== REV_SORT_BY_AUTHOR_DATE
)
3084 record_author_date(&info
->author_date
, c
);
3086 compute_indegrees_to_depth(revs
, info
->min_generation
);
3088 for (list
= revs
->commits
; list
; list
= list
->next
) {
3089 struct commit
*c
= list
->item
;
3091 if (*(indegree_slab_at(&info
->indegree
, c
)) == 1)
3092 prio_queue_put(&info
->topo_queue
, c
);
3096 * This is unfortunate; the initial tips need to be shown
3097 * in the order given from the revision traversal machinery.
3099 if (revs
->sort_order
== REV_SORT_IN_GRAPH_ORDER
)
3100 prio_queue_reverse(&info
->topo_queue
);
3103 static struct commit
*next_topo_commit(struct rev_info
*revs
)
3106 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3108 /* pop next off of topo_queue */
3109 c
= prio_queue_get(&info
->topo_queue
);
3112 *(indegree_slab_at(&info
->indegree
, c
)) = 0;
3117 static void expand_topo_walk(struct rev_info
*revs
, struct commit
*commit
)
3119 struct commit_list
*p
;
3120 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3121 if (process_parents(revs
, commit
, NULL
, NULL
) < 0) {
3122 if (!revs
->ignore_missing_links
)
3123 die("Failed to traverse parents of commit %s",
3124 oid_to_hex(&commit
->object
.oid
));
3127 for (p
= commit
->parents
; p
; p
= p
->next
) {
3128 struct commit
*parent
= p
->item
;
3131 if (parse_commit_gently(parent
, 1) < 0)
3134 if (parent
->generation
< info
->min_generation
) {
3135 info
->min_generation
= parent
->generation
;
3136 compute_indegrees_to_depth(revs
, info
->min_generation
);
3139 pi
= indegree_slab_at(&info
->indegree
, parent
);
3143 prio_queue_put(&info
->topo_queue
, parent
);
3145 if (revs
->first_parent_only
)
3150 int prepare_revision_walk(struct rev_info
*revs
)
3153 struct object_array old_pending
;
3154 struct commit_list
**next
= &revs
->commits
;
3156 memcpy(&old_pending
, &revs
->pending
, sizeof(old_pending
));
3157 revs
->pending
.nr
= 0;
3158 revs
->pending
.alloc
= 0;
3159 revs
->pending
.objects
= NULL
;
3160 for (i
= 0; i
< old_pending
.nr
; i
++) {
3161 struct object_array_entry
*e
= old_pending
.objects
+ i
;
3162 struct commit
*commit
= handle_commit(revs
, e
);
3164 if (!(commit
->object
.flags
& SEEN
)) {
3165 commit
->object
.flags
|= SEEN
;
3166 next
= commit_list_append(commit
, next
);
3170 object_array_clear(&old_pending
);
3172 /* Signal whether we need per-parent treesame decoration */
3173 if (revs
->simplify_merges
||
3174 (revs
->limited
&& limiting_can_increase_treesame(revs
)))
3175 revs
->treesame
.name
= "treesame";
3177 if (revs
->exclude_promisor_objects
) {
3178 for_each_packed_object(mark_uninteresting
, revs
,
3179 FOR_EACH_OBJECT_PROMISOR_ONLY
);
3182 if (revs
->no_walk
!= REVISION_WALK_NO_WALK_UNSORTED
)
3183 commit_list_sort_by_date(&revs
->commits
);
3186 if (revs
->limited
) {
3187 if (limit_list(revs
) < 0)
3189 if (revs
->topo_order
)
3190 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
3191 } else if (revs
->topo_order
)
3192 init_topo_walk(revs
);
3193 if (revs
->line_level_traverse
)
3194 line_log_filter(revs
);
3195 if (revs
->simplify_merges
)
3196 simplify_merges(revs
);
3197 if (revs
->children
.name
)
3202 static enum rewrite_result
rewrite_one(struct rev_info
*revs
, struct commit
**pp
)
3204 struct commit_list
*cache
= NULL
;
3207 struct commit
*p
= *pp
;
3209 if (process_parents(revs
, p
, &revs
->commits
, &cache
) < 0)
3210 return rewrite_one_error
;
3211 if (p
->object
.flags
& UNINTERESTING
)
3212 return rewrite_one_ok
;
3213 if (!(p
->object
.flags
& TREESAME
))
3214 return rewrite_one_ok
;
3216 return rewrite_one_noparents
;
3217 if ((p
= one_relevant_parent(revs
, p
->parents
)) == NULL
)
3218 return rewrite_one_ok
;
3223 int rewrite_parents(struct rev_info
*revs
, struct commit
*commit
,
3224 rewrite_parent_fn_t rewrite_parent
)
3226 struct commit_list
**pp
= &commit
->parents
;
3228 struct commit_list
*parent
= *pp
;
3229 switch (rewrite_parent(revs
, &parent
->item
)) {
3230 case rewrite_one_ok
:
3232 case rewrite_one_noparents
:
3235 case rewrite_one_error
:
3240 remove_duplicate_parents(revs
, commit
);
3244 static int commit_rewrite_person(struct strbuf
*buf
, const char *what
, struct string_list
*mailmap
)
3246 char *person
, *endp
;
3247 size_t len
, namelen
, maillen
;
3250 struct ident_split ident
;
3252 person
= strstr(buf
->buf
, what
);
3256 person
+= strlen(what
);
3257 endp
= strchr(person
, '\n');
3261 len
= endp
- person
;
3263 if (split_ident_line(&ident
, person
, len
))
3266 mail
= ident
.mail_begin
;
3267 maillen
= ident
.mail_end
- ident
.mail_begin
;
3268 name
= ident
.name_begin
;
3269 namelen
= ident
.name_end
- ident
.name_begin
;
3271 if (map_user(mailmap
, &mail
, &maillen
, &name
, &namelen
)) {
3272 struct strbuf namemail
= STRBUF_INIT
;
3274 strbuf_addf(&namemail
, "%.*s <%.*s>",
3275 (int)namelen
, name
, (int)maillen
, mail
);
3277 strbuf_splice(buf
, ident
.name_begin
- buf
->buf
,
3278 ident
.mail_end
- ident
.name_begin
+ 1,
3279 namemail
.buf
, namemail
.len
);
3281 strbuf_release(&namemail
);
3289 static int commit_match(struct commit
*commit
, struct rev_info
*opt
)
3292 const char *encoding
;
3293 const char *message
;
3294 struct strbuf buf
= STRBUF_INIT
;
3296 if (!opt
->grep_filter
.pattern_list
&& !opt
->grep_filter
.header_list
)
3299 /* Prepend "fake" headers as needed */
3300 if (opt
->grep_filter
.use_reflog_filter
) {
3301 strbuf_addstr(&buf
, "reflog ");
3302 get_reflog_message(&buf
, opt
->reflog_info
);
3303 strbuf_addch(&buf
, '\n');
3307 * We grep in the user's output encoding, under the assumption that it
3308 * is the encoding they are most likely to write their grep pattern
3309 * for. In addition, it means we will match the "notes" encoding below,
3310 * so we will not end up with a buffer that has two different encodings
3313 encoding
= get_log_output_encoding();
3314 message
= logmsg_reencode(commit
, NULL
, encoding
);
3316 /* Copy the commit to temporary if we are using "fake" headers */
3318 strbuf_addstr(&buf
, message
);
3320 if (opt
->grep_filter
.header_list
&& opt
->mailmap
) {
3322 strbuf_addstr(&buf
, message
);
3324 commit_rewrite_person(&buf
, "\nauthor ", opt
->mailmap
);
3325 commit_rewrite_person(&buf
, "\ncommitter ", opt
->mailmap
);
3328 /* Append "fake" message parts as needed */
3329 if (opt
->show_notes
) {
3331 strbuf_addstr(&buf
, message
);
3332 format_display_notes(&commit
->object
.oid
, &buf
, encoding
, 1);
3336 * Find either in the original commit message, or in the temporary.
3337 * Note that we cast away the constness of "message" here. It is
3338 * const because it may come from the cached commit buffer. That's OK,
3339 * because we know that it is modifiable heap memory, and that while
3340 * grep_buffer may modify it for speed, it will restore any
3341 * changes before returning.
3344 retval
= grep_buffer(&opt
->grep_filter
, buf
.buf
, buf
.len
);
3346 retval
= grep_buffer(&opt
->grep_filter
,
3347 (char *)message
, strlen(message
));
3348 strbuf_release(&buf
);
3349 unuse_commit_buffer(commit
, message
);
3350 return opt
->invert_grep
? !retval
: retval
;
3353 static inline int want_ancestry(const struct rev_info
*revs
)
3355 return (revs
->rewrite_parents
|| revs
->children
.name
);
3359 * Return a timestamp to be used for --since/--until comparisons for this
3360 * commit, based on the revision options.
3362 static timestamp_t
comparison_date(const struct rev_info
*revs
,
3363 struct commit
*commit
)
3365 return revs
->reflog_info
?
3366 get_reflog_timestamp(revs
->reflog_info
) :
3370 enum commit_action
get_commit_action(struct rev_info
*revs
, struct commit
*commit
)
3372 if (commit
->object
.flags
& SHOWN
)
3373 return commit_ignore
;
3374 if (revs
->unpacked
&& has_object_pack(&commit
->object
.oid
))
3375 return commit_ignore
;
3376 if (commit
->object
.flags
& UNINTERESTING
)
3377 return commit_ignore
;
3378 if (revs
->min_age
!= -1 &&
3379 comparison_date(revs
, commit
) > revs
->min_age
)
3380 return commit_ignore
;
3381 if (revs
->min_parents
|| (revs
->max_parents
>= 0)) {
3382 int n
= commit_list_count(commit
->parents
);
3383 if ((n
< revs
->min_parents
) ||
3384 ((revs
->max_parents
>= 0) && (n
> revs
->max_parents
)))
3385 return commit_ignore
;
3387 if (!commit_match(commit
, revs
))
3388 return commit_ignore
;
3389 if (revs
->prune
&& revs
->dense
) {
3390 /* Commit without changes? */
3391 if (commit
->object
.flags
& TREESAME
) {
3393 struct commit_list
*p
;
3394 /* drop merges unless we want parenthood */
3395 if (!want_ancestry(revs
))
3396 return commit_ignore
;
3398 * If we want ancestry, then need to keep any merges
3399 * between relevant commits to tie together topology.
3400 * For consistency with TREESAME and simplification
3401 * use "relevant" here rather than just INTERESTING,
3402 * to treat bottom commit(s) as part of the topology.
3404 for (n
= 0, p
= commit
->parents
; p
; p
= p
->next
)
3405 if (relevant_commit(p
->item
))
3408 return commit_ignore
;
3414 define_commit_slab(saved_parents
, struct commit_list
*);
3416 #define EMPTY_PARENT_LIST ((struct commit_list *)-1)
3419 * You may only call save_parents() once per commit (this is checked
3420 * for non-root commits).
3422 static void save_parents(struct rev_info
*revs
, struct commit
*commit
)
3424 struct commit_list
**pp
;
3426 if (!revs
->saved_parents_slab
) {
3427 revs
->saved_parents_slab
= xmalloc(sizeof(struct saved_parents
));
3428 init_saved_parents(revs
->saved_parents_slab
);
3431 pp
= saved_parents_at(revs
->saved_parents_slab
, commit
);
3434 * When walking with reflogs, we may visit the same commit
3435 * several times: once for each appearance in the reflog.
3437 * In this case, save_parents() will be called multiple times.
3438 * We want to keep only the first set of parents. We need to
3439 * store a sentinel value for an empty (i.e., NULL) parent
3440 * list to distinguish it from a not-yet-saved list, however.
3444 if (commit
->parents
)
3445 *pp
= copy_commit_list(commit
->parents
);
3447 *pp
= EMPTY_PARENT_LIST
;
3450 static void free_saved_parents(struct rev_info
*revs
)
3452 if (revs
->saved_parents_slab
)
3453 clear_saved_parents(revs
->saved_parents_slab
);
3456 struct commit_list
*get_saved_parents(struct rev_info
*revs
, const struct commit
*commit
)
3458 struct commit_list
*parents
;
3460 if (!revs
->saved_parents_slab
)
3461 return commit
->parents
;
3463 parents
= *saved_parents_at(revs
->saved_parents_slab
, commit
);
3464 if (parents
== EMPTY_PARENT_LIST
)
3469 enum commit_action
simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
3471 enum commit_action action
= get_commit_action(revs
, commit
);
3473 if (action
== commit_show
&&
3474 revs
->prune
&& revs
->dense
&& want_ancestry(revs
)) {
3476 * --full-diff on simplified parents is no good: it
3477 * will show spurious changes from the commits that
3478 * were elided. So we save the parents on the side
3479 * when --full-diff is in effect.
3481 if (revs
->full_diff
)
3482 save_parents(revs
, commit
);
3483 if (rewrite_parents(revs
, commit
, rewrite_one
) < 0)
3484 return commit_error
;
3489 static void track_linear(struct rev_info
*revs
, struct commit
*commit
)
3491 if (revs
->track_first_time
) {
3493 revs
->track_first_time
= 0;
3495 struct commit_list
*p
;
3496 for (p
= revs
->previous_parents
; p
; p
= p
->next
)
3497 if (p
->item
== NULL
|| /* first commit */
3498 oideq(&p
->item
->object
.oid
, &commit
->object
.oid
))
3500 revs
->linear
= p
!= NULL
;
3502 if (revs
->reverse
) {
3504 commit
->object
.flags
|= TRACK_LINEAR
;
3506 free_commit_list(revs
->previous_parents
);
3507 revs
->previous_parents
= copy_commit_list(commit
->parents
);
3510 static struct commit
*get_revision_1(struct rev_info
*revs
)
3513 struct commit
*commit
;
3515 if (revs
->reflog_info
)
3516 commit
= next_reflog_entry(revs
->reflog_info
);
3517 else if (revs
->topo_walk_info
)
3518 commit
= next_topo_commit(revs
);
3520 commit
= pop_commit(&revs
->commits
);
3525 if (revs
->reflog_info
)
3526 commit
->object
.flags
&= ~(ADDED
| SEEN
| SHOWN
);
3529 * If we haven't done the list limiting, we need to look at
3530 * the parents here. We also need to do the date-based limiting
3531 * that we'd otherwise have done in limit_list().
3533 if (!revs
->limited
) {
3534 if (revs
->max_age
!= -1 &&
3535 comparison_date(revs
, commit
) < revs
->max_age
)
3538 if (revs
->reflog_info
)
3539 try_to_simplify_commit(revs
, commit
);
3540 else if (revs
->topo_walk_info
)
3541 expand_topo_walk(revs
, commit
);
3542 else if (process_parents(revs
, commit
, &revs
->commits
, NULL
) < 0) {
3543 if (!revs
->ignore_missing_links
)
3544 die("Failed to traverse parents of commit %s",
3545 oid_to_hex(&commit
->object
.oid
));
3549 switch (simplify_commit(revs
, commit
)) {
3553 die("Failed to simplify parents of commit %s",
3554 oid_to_hex(&commit
->object
.oid
));
3556 if (revs
->track_linear
)
3557 track_linear(revs
, commit
);
3564 * Return true for entries that have not yet been shown. (This is an
3565 * object_array_each_func_t.)
3567 static int entry_unshown(struct object_array_entry
*entry
, void *cb_data_unused
)
3569 return !(entry
->item
->flags
& SHOWN
);
3573 * If array is on the verge of a realloc, garbage-collect any entries
3574 * that have already been shown to try to free up some space.
3576 static void gc_boundary(struct object_array
*array
)
3578 if (array
->nr
== array
->alloc
)
3579 object_array_filter(array
, entry_unshown
, NULL
);
3582 static void create_boundary_commit_list(struct rev_info
*revs
)
3586 struct object_array
*array
= &revs
->boundary_commits
;
3587 struct object_array_entry
*objects
= array
->objects
;
3590 * If revs->commits is non-NULL at this point, an error occurred in
3591 * get_revision_1(). Ignore the error and continue printing the
3592 * boundary commits anyway. (This is what the code has always
3595 if (revs
->commits
) {
3596 free_commit_list(revs
->commits
);
3597 revs
->commits
= NULL
;
3601 * Put all of the actual boundary commits from revs->boundary_commits
3602 * into revs->commits
3604 for (i
= 0; i
< array
->nr
; i
++) {
3605 c
= (struct commit
*)(objects
[i
].item
);
3608 if (!(c
->object
.flags
& CHILD_SHOWN
))
3610 if (c
->object
.flags
& (SHOWN
| BOUNDARY
))
3612 c
->object
.flags
|= BOUNDARY
;
3613 commit_list_insert(c
, &revs
->commits
);
3617 * If revs->topo_order is set, sort the boundary commits
3618 * in topological order
3620 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
3623 static struct commit
*get_revision_internal(struct rev_info
*revs
)
3625 struct commit
*c
= NULL
;
3626 struct commit_list
*l
;
3628 if (revs
->boundary
== 2) {
3630 * All of the normal commits have already been returned,
3631 * and we are now returning boundary commits.
3632 * create_boundary_commit_list() has populated
3633 * revs->commits with the remaining commits to return.
3635 c
= pop_commit(&revs
->commits
);
3637 c
->object
.flags
|= SHOWN
;
3642 * If our max_count counter has reached zero, then we are done. We
3643 * don't simply return NULL because we still might need to show
3644 * boundary commits. But we want to avoid calling get_revision_1, which
3645 * might do a considerable amount of work finding the next commit only
3646 * for us to throw it away.
3648 * If it is non-zero, then either we don't have a max_count at all
3649 * (-1), or it is still counting, in which case we decrement.
3651 if (revs
->max_count
) {
3652 c
= get_revision_1(revs
);
3654 while (revs
->skip_count
> 0) {
3656 c
= get_revision_1(revs
);
3662 if (revs
->max_count
> 0)
3667 c
->object
.flags
|= SHOWN
;
3669 if (!revs
->boundary
)
3674 * get_revision_1() runs out the commits, and
3675 * we are done computing the boundaries.
3676 * switch to boundary commits output mode.
3681 * Update revs->commits to contain the list of
3684 create_boundary_commit_list(revs
);
3686 return get_revision_internal(revs
);
3690 * boundary commits are the commits that are parents of the
3691 * ones we got from get_revision_1() but they themselves are
3692 * not returned from get_revision_1(). Before returning
3693 * 'c', we need to mark its parents that they could be boundaries.
3696 for (l
= c
->parents
; l
; l
= l
->next
) {
3698 p
= &(l
->item
->object
);
3699 if (p
->flags
& (CHILD_SHOWN
| SHOWN
))
3701 p
->flags
|= CHILD_SHOWN
;
3702 gc_boundary(&revs
->boundary_commits
);
3703 add_object_array(p
, NULL
, &revs
->boundary_commits
);
3709 struct commit
*get_revision(struct rev_info
*revs
)
3712 struct commit_list
*reversed
;
3714 if (revs
->reverse
) {
3716 while ((c
= get_revision_internal(revs
)))
3717 commit_list_insert(c
, &reversed
);
3718 revs
->commits
= reversed
;
3720 revs
->reverse_output_stage
= 1;
3723 if (revs
->reverse_output_stage
) {
3724 c
= pop_commit(&revs
->commits
);
3725 if (revs
->track_linear
)
3726 revs
->linear
= !!(c
&& c
->object
.flags
& TRACK_LINEAR
);
3730 c
= get_revision_internal(revs
);
3731 if (c
&& revs
->graph
)
3732 graph_update(revs
->graph
, c
);
3734 free_saved_parents(revs
);
3735 if (revs
->previous_parents
) {
3736 free_commit_list(revs
->previous_parents
);
3737 revs
->previous_parents
= NULL
;
3743 char *get_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
3745 if (commit
->object
.flags
& BOUNDARY
)
3747 else if (commit
->object
.flags
& UNINTERESTING
)
3749 else if (commit
->object
.flags
& PATCHSAME
)
3751 else if (!revs
|| revs
->left_right
) {
3752 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
3756 } else if (revs
->graph
)
3758 else if (revs
->cherry_mark
)
3763 void put_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
3765 char *mark
= get_revision_mark(revs
, commit
);
3768 fputs(mark
, stdout
);