11 #include "reflog-walk.h"
12 #include "patch-ids.h"
15 #include "string-list.h"
18 #include "commit-slab.h"
20 volatile show_early_output_fn_t show_early_output
;
22 char *path_name(const struct name_path
*path
, const char *name
)
24 const struct name_path
*p
;
26 int nlen
= strlen(name
);
29 for (p
= path
; p
; p
= p
->up
) {
31 len
+= p
->elem_len
+ 1;
34 m
= n
+ len
- (nlen
+ 1);
36 for (p
= path
; p
; p
= p
->up
) {
39 memcpy(m
, p
->elem
, p
->elem_len
);
46 static int show_path_component_truncated(FILE *out
, const char *name
, int len
)
49 for (cnt
= 0; cnt
< len
; cnt
++) {
51 if (!ch
|| ch
== '\n')
58 static int show_path_truncated(FILE *out
, const struct name_path
*path
)
64 emitted
= show_path_truncated(out
, path
->up
);
69 ours
= show_path_component_truncated(out
, path
->elem
, path
->elem_len
);
72 return ours
|| emitted
;
75 void show_object_with_name(FILE *out
, struct object
*obj
,
76 const struct name_path
*path
, const char *component
)
78 struct name_path leaf
;
79 leaf
.up
= (struct name_path
*)path
;
80 leaf
.elem
= component
;
81 leaf
.elem_len
= strlen(component
);
83 fprintf(out
, "%s ", sha1_to_hex(obj
->sha1
));
84 show_path_truncated(out
, &leaf
);
88 void add_object(struct object
*obj
,
89 struct object_array
*p
,
90 struct name_path
*path
,
93 char *pn
= path_name(path
, name
);
94 add_object_array(obj
, pn
, p
);
98 static void mark_blob_uninteresting(struct blob
*blob
)
102 if (blob
->object
.flags
& UNINTERESTING
)
104 blob
->object
.flags
|= UNINTERESTING
;
107 void mark_tree_uninteresting(struct tree
*tree
)
109 struct tree_desc desc
;
110 struct name_entry entry
;
111 struct object
*obj
= &tree
->object
;
115 if (obj
->flags
& UNINTERESTING
)
117 obj
->flags
|= UNINTERESTING
;
118 if (!has_sha1_file(obj
->sha1
))
120 if (parse_tree(tree
) < 0)
121 die("bad tree %s", sha1_to_hex(obj
->sha1
));
123 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
124 while (tree_entry(&desc
, &entry
)) {
125 switch (object_type(entry
.mode
)) {
127 mark_tree_uninteresting(lookup_tree(entry
.sha1
));
130 mark_blob_uninteresting(lookup_blob(entry
.sha1
));
133 /* Subproject commit - not in this repository */
139 * We don't care about the tree any more
140 * after it has been marked uninteresting.
146 void mark_parents_uninteresting(struct commit
*commit
)
148 struct commit_list
*parents
= NULL
, *l
;
150 for (l
= commit
->parents
; l
; l
= l
->next
)
151 commit_list_insert(l
->item
, &parents
);
154 struct commit
*commit
= parents
->item
;
156 parents
= parents
->next
;
161 * A missing commit is ok iff its parent is marked
164 * We just mark such a thing parsed, so that when
165 * it is popped next time around, we won't be trying
166 * to parse it and get an error.
168 if (!has_sha1_file(commit
->object
.sha1
))
169 commit
->object
.parsed
= 1;
171 if (commit
->object
.flags
& UNINTERESTING
)
174 commit
->object
.flags
|= UNINTERESTING
;
177 * Normally we haven't parsed the parent
178 * yet, so we won't have a parent of a parent
179 * here. However, it may turn out that we've
180 * reached this commit some other way (where it
181 * wasn't uninteresting), in which case we need
182 * to mark its parents recursively too..
184 if (!commit
->parents
)
187 for (l
= commit
->parents
->next
; l
; l
= l
->next
)
188 commit_list_insert(l
->item
, &parents
);
189 commit
= commit
->parents
->item
;
194 static void add_pending_object_with_mode(struct rev_info
*revs
,
196 const char *name
, unsigned mode
)
200 if (revs
->no_walk
&& (obj
->flags
& UNINTERESTING
))
202 if (revs
->reflog_info
&& obj
->type
== OBJ_COMMIT
) {
203 struct strbuf buf
= STRBUF_INIT
;
204 int len
= interpret_branch_name(name
, &buf
);
207 if (0 < len
&& name
[len
] && buf
.len
)
208 strbuf_addstr(&buf
, name
+ len
);
209 st
= add_reflog_for_walk(revs
->reflog_info
,
210 (struct commit
*)obj
,
211 buf
.buf
[0] ? buf
.buf
: name
);
212 strbuf_release(&buf
);
216 add_object_array_with_mode(obj
, name
, &revs
->pending
, mode
);
219 void add_pending_object(struct rev_info
*revs
,
220 struct object
*obj
, const char *name
)
222 add_pending_object_with_mode(revs
, obj
, name
, S_IFINVALID
);
225 void add_head_to_pending(struct rev_info
*revs
)
227 unsigned char sha1
[20];
229 if (get_sha1("HEAD", sha1
))
231 obj
= parse_object(sha1
);
234 add_pending_object(revs
, obj
, "HEAD");
237 static struct object
*get_reference(struct rev_info
*revs
, const char *name
,
238 const unsigned char *sha1
,
241 struct object
*object
;
243 object
= parse_object(sha1
);
245 if (revs
->ignore_missing
)
247 die("bad object %s", name
);
249 object
->flags
|= flags
;
253 void add_pending_sha1(struct rev_info
*revs
, const char *name
,
254 const unsigned char *sha1
, unsigned int flags
)
256 struct object
*object
= get_reference(revs
, name
, sha1
, flags
);
257 add_pending_object(revs
, object
, name
);
260 static struct commit
*handle_commit(struct rev_info
*revs
,
261 struct object
*object
, const char *name
)
263 unsigned long flags
= object
->flags
;
266 * Tag object? Look what it points to..
268 while (object
->type
== OBJ_TAG
) {
269 struct tag
*tag
= (struct tag
*) object
;
270 if (revs
->tag_objects
&& !(flags
& UNINTERESTING
))
271 add_pending_object(revs
, object
, tag
->tag
);
274 object
= parse_object(tag
->tagged
->sha1
);
276 if (flags
& UNINTERESTING
)
278 die("bad object %s", sha1_to_hex(tag
->tagged
->sha1
));
283 * Commit object? Just return it, we'll do all the complex
286 if (object
->type
== OBJ_COMMIT
) {
287 struct commit
*commit
= (struct commit
*)object
;
288 if (parse_commit(commit
) < 0)
289 die("unable to parse commit %s", name
);
290 if (flags
& UNINTERESTING
) {
291 commit
->object
.flags
|= UNINTERESTING
;
292 mark_parents_uninteresting(commit
);
295 if (revs
->show_source
&& !commit
->util
)
296 commit
->util
= (void *) name
;
301 * Tree object? Either mark it uninteresting, or add it
302 * to the list of objects to look at later..
304 if (object
->type
== OBJ_TREE
) {
305 struct tree
*tree
= (struct tree
*)object
;
306 if (!revs
->tree_objects
)
308 if (flags
& UNINTERESTING
) {
309 mark_tree_uninteresting(tree
);
312 add_pending_object(revs
, object
, "");
317 * Blob object? You know the drill by now..
319 if (object
->type
== OBJ_BLOB
) {
320 struct blob
*blob
= (struct blob
*)object
;
321 if (!revs
->blob_objects
)
323 if (flags
& UNINTERESTING
) {
324 mark_blob_uninteresting(blob
);
327 add_pending_object(revs
, object
, "");
330 die("%s is unknown object", name
);
333 static int everybody_uninteresting(struct commit_list
*orig
)
335 struct commit_list
*list
= orig
;
337 struct commit
*commit
= list
->item
;
339 if (commit
->object
.flags
& UNINTERESTING
)
347 * A definition of "relevant" commit that we can use to simplify limited graphs
348 * by eliminating side branches.
350 * A "relevant" commit is one that is !UNINTERESTING (ie we are including it
351 * in our list), or that is a specified BOTTOM commit. Then after computing
352 * a limited list, during processing we can generally ignore boundary merges
353 * coming from outside the graph, (ie from irrelevant parents), and treat
354 * those merges as if they were single-parent. TREESAME is defined to consider
355 * only relevant parents, if any. If we are TREESAME to our on-graph parents,
356 * we don't care if we were !TREESAME to non-graph parents.
358 * Treating bottom commits as relevant ensures that a limited graph's
359 * connection to the actual bottom commit is not viewed as a side branch, but
360 * treated as part of the graph. For example:
362 * ....Z...A---X---o---o---B
366 * When computing "A..B", the A-X connection is at least as important as
367 * Y-X, despite A being flagged UNINTERESTING.
369 * And when computing --ancestry-path "A..B", the A-X connection is more
370 * important than Y-X, despite both A and Y being flagged UNINTERESTING.
372 static inline int relevant_commit(struct commit
*commit
)
374 return (commit
->object
.flags
& (UNINTERESTING
| BOTTOM
)) != UNINTERESTING
;
378 * Return a single relevant commit from a parent list. If we are a TREESAME
379 * commit, and this selects one of our parents, then we can safely simplify to
382 static struct commit
*one_relevant_parent(const struct rev_info
*revs
,
383 struct commit_list
*orig
)
385 struct commit_list
*list
= orig
;
386 struct commit
*relevant
= NULL
;
392 * For 1-parent commits, or if first-parent-only, then return that
393 * first parent (even if not "relevant" by the above definition).
394 * TREESAME will have been set purely on that parent.
396 if (revs
->first_parent_only
|| !orig
->next
)
400 * For multi-parent commits, identify a sole relevant parent, if any.
401 * If we have only one relevant parent, then TREESAME will be set purely
402 * with regard to that parent, and we can simplify accordingly.
404 * If we have more than one relevant parent, or no relevant parents
405 * (and multiple irrelevant ones), then we can't select a parent here
409 struct commit
*commit
= list
->item
;
411 if (relevant_commit(commit
)) {
421 * The goal is to get REV_TREE_NEW as the result only if the
422 * diff consists of all '+' (and no other changes), REV_TREE_OLD
423 * if the whole diff is removal of old data, and otherwise
424 * REV_TREE_DIFFERENT (of course if the trees are the same we
425 * want REV_TREE_SAME).
426 * That means that once we get to REV_TREE_DIFFERENT, we do not
427 * have to look any further.
429 static int tree_difference
= REV_TREE_SAME
;
431 static void file_add_remove(struct diff_options
*options
,
432 int addremove
, unsigned mode
,
433 const unsigned char *sha1
,
435 const char *fullpath
, unsigned dirty_submodule
)
437 int diff
= addremove
== '+' ? REV_TREE_NEW
: REV_TREE_OLD
;
439 tree_difference
|= diff
;
440 if (tree_difference
== REV_TREE_DIFFERENT
)
441 DIFF_OPT_SET(options
, HAS_CHANGES
);
444 static void file_change(struct diff_options
*options
,
445 unsigned old_mode
, unsigned new_mode
,
446 const unsigned char *old_sha1
,
447 const unsigned char *new_sha1
,
448 int old_sha1_valid
, int new_sha1_valid
,
449 const char *fullpath
,
450 unsigned old_dirty_submodule
, unsigned new_dirty_submodule
)
452 tree_difference
= REV_TREE_DIFFERENT
;
453 DIFF_OPT_SET(options
, HAS_CHANGES
);
456 static int rev_compare_tree(struct rev_info
*revs
,
457 struct commit
*parent
, struct commit
*commit
)
459 struct tree
*t1
= parent
->tree
;
460 struct tree
*t2
= commit
->tree
;
467 if (revs
->simplify_by_decoration
) {
469 * If we are simplifying by decoration, then the commit
470 * is worth showing if it has a tag pointing at it.
472 if (lookup_decoration(&name_decoration
, &commit
->object
))
473 return REV_TREE_DIFFERENT
;
475 * A commit that is not pointed by a tag is uninteresting
476 * if we are not limited by path. This means that you will
477 * see the usual "commits that touch the paths" plus any
478 * tagged commit by specifying both --simplify-by-decoration
481 if (!revs
->prune_data
.nr
)
482 return REV_TREE_SAME
;
485 tree_difference
= REV_TREE_SAME
;
486 DIFF_OPT_CLR(&revs
->pruning
, HAS_CHANGES
);
487 if (diff_tree_sha1(t1
->object
.sha1
, t2
->object
.sha1
, "",
489 return REV_TREE_DIFFERENT
;
490 return tree_difference
;
493 static int rev_same_tree_as_empty(struct rev_info
*revs
, struct commit
*commit
)
498 struct tree_desc empty
, real
;
499 struct tree
*t1
= commit
->tree
;
504 tree
= read_object_with_reference(t1
->object
.sha1
, tree_type
, &size
, NULL
);
507 init_tree_desc(&real
, tree
, size
);
508 init_tree_desc(&empty
, "", 0);
510 tree_difference
= REV_TREE_SAME
;
511 DIFF_OPT_CLR(&revs
->pruning
, HAS_CHANGES
);
512 retval
= diff_tree(&empty
, &real
, "", &revs
->pruning
);
515 return retval
>= 0 && (tree_difference
== REV_TREE_SAME
);
518 struct treesame_state
{
519 unsigned int nparents
;
520 unsigned char treesame
[FLEX_ARRAY
];
523 static struct treesame_state
*initialise_treesame(struct rev_info
*revs
, struct commit
*commit
)
525 unsigned n
= commit_list_count(commit
->parents
);
526 struct treesame_state
*st
= xcalloc(1, sizeof(*st
) + n
);
528 add_decoration(&revs
->treesame
, &commit
->object
, st
);
533 * Must be called immediately after removing the nth_parent from a commit's
534 * parent list, if we are maintaining the per-parent treesame[] decoration.
535 * This does not recalculate the master TREESAME flag - update_treesame()
536 * should be called to update it after a sequence of treesame[] modifications
537 * that may have affected it.
539 static int compact_treesame(struct rev_info
*revs
, struct commit
*commit
, unsigned nth_parent
)
541 struct treesame_state
*st
;
544 if (!commit
->parents
) {
546 * Have just removed the only parent from a non-merge.
547 * Different handling, as we lack decoration.
550 die("compact_treesame %u", nth_parent
);
551 old_same
= !!(commit
->object
.flags
& TREESAME
);
552 if (rev_same_tree_as_empty(revs
, commit
))
553 commit
->object
.flags
|= TREESAME
;
555 commit
->object
.flags
&= ~TREESAME
;
559 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
560 if (!st
|| nth_parent
>= st
->nparents
)
561 die("compact_treesame %u", nth_parent
);
563 old_same
= st
->treesame
[nth_parent
];
564 memmove(st
->treesame
+ nth_parent
,
565 st
->treesame
+ nth_parent
+ 1,
566 st
->nparents
- nth_parent
- 1);
569 * If we've just become a non-merge commit, update TREESAME
570 * immediately, and remove the no-longer-needed decoration.
571 * If still a merge, defer update until update_treesame().
573 if (--st
->nparents
== 1) {
574 if (commit
->parents
->next
)
575 die("compact_treesame parents mismatch");
576 if (st
->treesame
[0] && revs
->dense
)
577 commit
->object
.flags
|= TREESAME
;
579 commit
->object
.flags
&= ~TREESAME
;
580 free(add_decoration(&revs
->treesame
, &commit
->object
, NULL
));
586 static unsigned update_treesame(struct rev_info
*revs
, struct commit
*commit
)
588 if (commit
->parents
&& commit
->parents
->next
) {
590 struct treesame_state
*st
;
591 struct commit_list
*p
;
592 unsigned relevant_parents
;
593 unsigned relevant_change
, irrelevant_change
;
595 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
597 die("update_treesame %s", sha1_to_hex(commit
->object
.sha1
));
598 relevant_parents
= 0;
599 relevant_change
= irrelevant_change
= 0;
600 for (p
= commit
->parents
, n
= 0; p
; n
++, p
= p
->next
) {
601 if (relevant_commit(p
->item
)) {
602 relevant_change
|= !st
->treesame
[n
];
605 irrelevant_change
|= !st
->treesame
[n
];
607 if (relevant_parents
? relevant_change
: irrelevant_change
)
608 commit
->object
.flags
&= ~TREESAME
;
610 commit
->object
.flags
|= TREESAME
;
613 return commit
->object
.flags
& TREESAME
;
616 static inline int limiting_can_increase_treesame(const struct rev_info
*revs
)
619 * TREESAME is irrelevant unless prune && dense;
620 * if simplify_history is set, we can't have a mixture of TREESAME and
621 * !TREESAME INTERESTING parents (and we don't have treesame[]
622 * decoration anyway);
623 * if first_parent_only is set, then the TREESAME flag is locked
624 * against the first parent (and again we lack treesame[] decoration).
626 return revs
->prune
&& revs
->dense
&&
627 !revs
->simplify_history
&&
628 !revs
->first_parent_only
;
631 static void try_to_simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
633 struct commit_list
**pp
, *parent
;
634 struct treesame_state
*ts
= NULL
;
635 int relevant_change
= 0, irrelevant_change
= 0;
636 int relevant_parents
, nth_parent
;
639 * If we don't do pruning, everything is interesting
647 if (!commit
->parents
) {
648 if (rev_same_tree_as_empty(revs
, commit
))
649 commit
->object
.flags
|= TREESAME
;
654 * Normal non-merge commit? If we don't want to make the
655 * history dense, we consider it always to be a change..
657 if (!revs
->dense
&& !commit
->parents
->next
)
660 for (pp
= &commit
->parents
, nth_parent
= 0, relevant_parents
= 0;
661 (parent
= *pp
) != NULL
;
662 pp
= &parent
->next
, nth_parent
++) {
663 struct commit
*p
= parent
->item
;
664 if (relevant_commit(p
))
667 if (nth_parent
== 1) {
669 * This our second loop iteration - so we now know
670 * we're dealing with a merge.
672 * Do not compare with later parents when we care only about
673 * the first parent chain, in order to avoid derailing the
674 * traversal to follow a side branch that brought everything
675 * in the path we are limited to by the pathspec.
677 if (revs
->first_parent_only
)
680 * If this will remain a potentially-simplifiable
681 * merge, remember per-parent treesame if needed.
682 * Initialise the array with the comparison from our
685 if (revs
->treesame
.name
&&
686 !revs
->simplify_history
&&
687 !(commit
->object
.flags
& UNINTERESTING
)) {
688 ts
= initialise_treesame(revs
, commit
);
689 if (!(irrelevant_change
|| relevant_change
))
693 if (parse_commit(p
) < 0)
694 die("cannot simplify commit %s (because of %s)",
695 sha1_to_hex(commit
->object
.sha1
),
696 sha1_to_hex(p
->object
.sha1
));
697 switch (rev_compare_tree(revs
, p
, commit
)) {
699 if (!revs
->simplify_history
|| !relevant_commit(p
)) {
700 /* Even if a merge with an uninteresting
701 * side branch brought the entire change
702 * we are interested in, we do not want
703 * to lose the other branches of this
704 * merge, so we just keep going.
707 ts
->treesame
[nth_parent
] = 1;
711 commit
->parents
= parent
;
712 commit
->object
.flags
|= TREESAME
;
716 if (revs
->remove_empty_trees
&&
717 rev_same_tree_as_empty(revs
, p
)) {
718 /* We are adding all the specified
719 * paths from this parent, so the
720 * history beyond this parent is not
721 * interesting. Remove its parents
722 * (they are grandparents for us).
723 * IOW, we pretend this parent is a
726 if (parse_commit(p
) < 0)
727 die("cannot simplify commit %s (invalid %s)",
728 sha1_to_hex(commit
->object
.sha1
),
729 sha1_to_hex(p
->object
.sha1
));
734 case REV_TREE_DIFFERENT
:
735 if (relevant_commit(p
))
738 irrelevant_change
= 1;
741 die("bad tree compare for commit %s", sha1_to_hex(commit
->object
.sha1
));
745 * TREESAME is straightforward for single-parent commits. For merge
746 * commits, it is most useful to define it so that "irrelevant"
747 * parents cannot make us !TREESAME - if we have any relevant
748 * parents, then we only consider TREESAMEness with respect to them,
749 * allowing irrelevant merges from uninteresting branches to be
750 * simplified away. Only if we have only irrelevant parents do we
751 * base TREESAME on them. Note that this logic is replicated in
752 * update_treesame, which should be kept in sync.
754 if (relevant_parents
? !relevant_change
: !irrelevant_change
)
755 commit
->object
.flags
|= TREESAME
;
758 static void commit_list_insert_by_date_cached(struct commit
*p
, struct commit_list
**head
,
759 struct commit_list
*cached_base
, struct commit_list
**cache
)
761 struct commit_list
*new_entry
;
763 if (cached_base
&& p
->date
< cached_base
->item
->date
)
764 new_entry
= commit_list_insert_by_date(p
, &cached_base
->next
);
766 new_entry
= commit_list_insert_by_date(p
, head
);
768 if (cache
&& (!*cache
|| p
->date
< (*cache
)->item
->date
))
772 static int add_parents_to_list(struct rev_info
*revs
, struct commit
*commit
,
773 struct commit_list
**list
, struct commit_list
**cache_ptr
)
775 struct commit_list
*parent
= commit
->parents
;
777 struct commit_list
*cached_base
= cache_ptr
? *cache_ptr
: NULL
;
779 if (commit
->object
.flags
& ADDED
)
781 commit
->object
.flags
|= ADDED
;
784 * If the commit is uninteresting, don't try to
785 * prune parents - we want the maximal uninteresting
788 * Normally we haven't parsed the parent
789 * yet, so we won't have a parent of a parent
790 * here. However, it may turn out that we've
791 * reached this commit some other way (where it
792 * wasn't uninteresting), in which case we need
793 * to mark its parents recursively too..
795 if (commit
->object
.flags
& UNINTERESTING
) {
797 struct commit
*p
= parent
->item
;
798 parent
= parent
->next
;
800 p
->object
.flags
|= UNINTERESTING
;
801 if (parse_commit(p
) < 0)
804 mark_parents_uninteresting(p
);
805 if (p
->object
.flags
& SEEN
)
807 p
->object
.flags
|= SEEN
;
808 commit_list_insert_by_date_cached(p
, list
, cached_base
, cache_ptr
);
814 * Ok, the commit wasn't uninteresting. Try to
815 * simplify the commit history and find the parent
816 * that has no differences in the path set if one exists.
818 try_to_simplify_commit(revs
, commit
);
823 left_flag
= (commit
->object
.flags
& SYMMETRIC_LEFT
);
825 for (parent
= commit
->parents
; parent
; parent
= parent
->next
) {
826 struct commit
*p
= parent
->item
;
828 if (parse_commit(p
) < 0)
830 if (revs
->show_source
&& !p
->util
)
831 p
->util
= commit
->util
;
832 p
->object
.flags
|= left_flag
;
833 if (!(p
->object
.flags
& SEEN
)) {
834 p
->object
.flags
|= SEEN
;
835 commit_list_insert_by_date_cached(p
, list
, cached_base
, cache_ptr
);
837 if (revs
->first_parent_only
)
843 static void cherry_pick_list(struct commit_list
*list
, struct rev_info
*revs
)
845 struct commit_list
*p
;
846 int left_count
= 0, right_count
= 0;
848 struct patch_ids ids
;
849 unsigned cherry_flag
;
851 /* First count the commits on the left and on the right */
852 for (p
= list
; p
; p
= p
->next
) {
853 struct commit
*commit
= p
->item
;
854 unsigned flags
= commit
->object
.flags
;
855 if (flags
& BOUNDARY
)
857 else if (flags
& SYMMETRIC_LEFT
)
863 if (!left_count
|| !right_count
)
866 left_first
= left_count
< right_count
;
867 init_patch_ids(&ids
);
868 ids
.diffopts
.pathspec
= revs
->diffopt
.pathspec
;
870 /* Compute patch-ids for one side */
871 for (p
= list
; p
; p
= p
->next
) {
872 struct commit
*commit
= p
->item
;
873 unsigned flags
= commit
->object
.flags
;
875 if (flags
& BOUNDARY
)
878 * If we have fewer left, left_first is set and we omit
879 * commits on the right branch in this loop. If we have
880 * fewer right, we skip the left ones.
882 if (left_first
!= !!(flags
& SYMMETRIC_LEFT
))
884 commit
->util
= add_commit_patch_id(commit
, &ids
);
887 /* either cherry_mark or cherry_pick are true */
888 cherry_flag
= revs
->cherry_mark
? PATCHSAME
: SHOWN
;
890 /* Check the other side */
891 for (p
= list
; p
; p
= p
->next
) {
892 struct commit
*commit
= p
->item
;
894 unsigned flags
= commit
->object
.flags
;
896 if (flags
& BOUNDARY
)
899 * If we have fewer left, left_first is set and we omit
900 * commits on the left branch in this loop.
902 if (left_first
== !!(flags
& SYMMETRIC_LEFT
))
906 * Have we seen the same patch id?
908 id
= has_commit_patch_id(commit
, &ids
);
912 commit
->object
.flags
|= cherry_flag
;
915 /* Now check the original side for seen ones */
916 for (p
= list
; p
; p
= p
->next
) {
917 struct commit
*commit
= p
->item
;
918 struct patch_id
*ent
;
924 commit
->object
.flags
|= cherry_flag
;
928 free_patch_ids(&ids
);
931 /* How many extra uninteresting commits we want to see.. */
934 static int still_interesting(struct commit_list
*src
, unsigned long date
, int slop
)
937 * No source list at all? We're definitely done..
943 * Does the destination list contain entries with a date
944 * before the source list? Definitely _not_ done.
946 if (date
<= src
->item
->date
)
950 * Does the source list still have interesting commits in
951 * it? Definitely not done..
953 if (!everybody_uninteresting(src
))
956 /* Ok, we're closing in.. */
961 * "rev-list --ancestry-path A..B" computes commits that are ancestors
962 * of B but not ancestors of A but further limits the result to those
963 * that are descendants of A. This takes the list of bottom commits and
964 * the result of "A..B" without --ancestry-path, and limits the latter
965 * further to the ones that can reach one of the commits in "bottom".
967 static void limit_to_ancestry(struct commit_list
*bottom
, struct commit_list
*list
)
969 struct commit_list
*p
;
970 struct commit_list
*rlist
= NULL
;
974 * Reverse the list so that it will be likely that we would
975 * process parents before children.
977 for (p
= list
; p
; p
= p
->next
)
978 commit_list_insert(p
->item
, &rlist
);
980 for (p
= bottom
; p
; p
= p
->next
)
981 p
->item
->object
.flags
|= TMP_MARK
;
984 * Mark the ones that can reach bottom commits in "list",
985 * in a bottom-up fashion.
989 for (p
= rlist
; p
; p
= p
->next
) {
990 struct commit
*c
= p
->item
;
991 struct commit_list
*parents
;
992 if (c
->object
.flags
& (TMP_MARK
| UNINTERESTING
))
994 for (parents
= c
->parents
;
996 parents
= parents
->next
) {
997 if (!(parents
->item
->object
.flags
& TMP_MARK
))
999 c
->object
.flags
|= TMP_MARK
;
1004 } while (made_progress
);
1007 * NEEDSWORK: decide if we want to remove parents that are
1008 * not marked with TMP_MARK from commit->parents for commits
1009 * in the resulting list. We may not want to do that, though.
1013 * The ones that are not marked with TMP_MARK are uninteresting
1015 for (p
= list
; p
; p
= p
->next
) {
1016 struct commit
*c
= p
->item
;
1017 if (c
->object
.flags
& TMP_MARK
)
1019 c
->object
.flags
|= UNINTERESTING
;
1022 /* We are done with the TMP_MARK */
1023 for (p
= list
; p
; p
= p
->next
)
1024 p
->item
->object
.flags
&= ~TMP_MARK
;
1025 for (p
= bottom
; p
; p
= p
->next
)
1026 p
->item
->object
.flags
&= ~TMP_MARK
;
1027 free_commit_list(rlist
);
1031 * Before walking the history, keep the set of "negative" refs the
1032 * caller has asked to exclude.
1034 * This is used to compute "rev-list --ancestry-path A..B", as we need
1035 * to filter the result of "A..B" further to the ones that can actually
1038 static struct commit_list
*collect_bottom_commits(struct commit_list
*list
)
1040 struct commit_list
*elem
, *bottom
= NULL
;
1041 for (elem
= list
; elem
; elem
= elem
->next
)
1042 if (elem
->item
->object
.flags
& BOTTOM
)
1043 commit_list_insert(elem
->item
, &bottom
);
1047 /* Assumes either left_only or right_only is set */
1048 static void limit_left_right(struct commit_list
*list
, struct rev_info
*revs
)
1050 struct commit_list
*p
;
1052 for (p
= list
; p
; p
= p
->next
) {
1053 struct commit
*commit
= p
->item
;
1055 if (revs
->right_only
) {
1056 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
1057 commit
->object
.flags
|= SHOWN
;
1058 } else /* revs->left_only is set */
1059 if (!(commit
->object
.flags
& SYMMETRIC_LEFT
))
1060 commit
->object
.flags
|= SHOWN
;
1064 static int limit_list(struct rev_info
*revs
)
1067 unsigned long date
= ~0ul;
1068 struct commit_list
*list
= revs
->commits
;
1069 struct commit_list
*newlist
= NULL
;
1070 struct commit_list
**p
= &newlist
;
1071 struct commit_list
*bottom
= NULL
;
1073 if (revs
->ancestry_path
) {
1074 bottom
= collect_bottom_commits(list
);
1076 die("--ancestry-path given but there are no bottom commits");
1080 struct commit_list
*entry
= list
;
1081 struct commit
*commit
= list
->item
;
1082 struct object
*obj
= &commit
->object
;
1083 show_early_output_fn_t show
;
1088 if (revs
->max_age
!= -1 && (commit
->date
< revs
->max_age
))
1089 obj
->flags
|= UNINTERESTING
;
1090 if (add_parents_to_list(revs
, commit
, &list
, NULL
) < 0)
1092 if (obj
->flags
& UNINTERESTING
) {
1093 mark_parents_uninteresting(commit
);
1095 p
= &commit_list_insert(commit
, p
)->next
;
1096 slop
= still_interesting(list
, date
, slop
);
1099 /* If showing all, add the whole pending list to the end */
1104 if (revs
->min_age
!= -1 && (commit
->date
> revs
->min_age
))
1106 date
= commit
->date
;
1107 p
= &commit_list_insert(commit
, p
)->next
;
1109 show
= show_early_output
;
1113 show(revs
, newlist
);
1114 show_early_output
= NULL
;
1116 if (revs
->cherry_pick
|| revs
->cherry_mark
)
1117 cherry_pick_list(newlist
, revs
);
1119 if (revs
->left_only
|| revs
->right_only
)
1120 limit_left_right(newlist
, revs
);
1123 limit_to_ancestry(bottom
, newlist
);
1124 free_commit_list(bottom
);
1128 * Check if any commits have become TREESAME by some of their parents
1129 * becoming UNINTERESTING.
1131 if (limiting_can_increase_treesame(revs
))
1132 for (list
= newlist
; list
; list
= list
->next
) {
1133 struct commit
*c
= list
->item
;
1134 if (c
->object
.flags
& (UNINTERESTING
| TREESAME
))
1136 update_treesame(revs
, c
);
1139 revs
->commits
= newlist
;
1144 * Add an entry to refs->cmdline with the specified information.
1147 static void add_rev_cmdline(struct rev_info
*revs
,
1148 struct object
*item
,
1153 struct rev_cmdline_info
*info
= &revs
->cmdline
;
1156 ALLOC_GROW(info
->rev
, nr
+ 1, info
->alloc
);
1157 info
->rev
[nr
].item
= item
;
1158 info
->rev
[nr
].name
= xstrdup(name
);
1159 info
->rev
[nr
].whence
= whence
;
1160 info
->rev
[nr
].flags
= flags
;
1164 static void add_rev_cmdline_list(struct rev_info
*revs
,
1165 struct commit_list
*commit_list
,
1169 while (commit_list
) {
1170 struct object
*object
= &commit_list
->item
->object
;
1171 add_rev_cmdline(revs
, object
, sha1_to_hex(object
->sha1
),
1173 commit_list
= commit_list
->next
;
1177 struct all_refs_cb
{
1179 int warned_bad_reflog
;
1180 struct rev_info
*all_revs
;
1181 const char *name_for_errormsg
;
1184 static int handle_one_ref(const char *path
, const unsigned char *sha1
, int flag
, void *cb_data
)
1186 struct all_refs_cb
*cb
= cb_data
;
1187 struct object
*object
= get_reference(cb
->all_revs
, path
, sha1
,
1189 add_rev_cmdline(cb
->all_revs
, object
, path
, REV_CMD_REF
, cb
->all_flags
);
1190 add_pending_sha1(cb
->all_revs
, path
, sha1
, cb
->all_flags
);
1194 static void init_all_refs_cb(struct all_refs_cb
*cb
, struct rev_info
*revs
,
1197 cb
->all_revs
= revs
;
1198 cb
->all_flags
= flags
;
1201 static void handle_refs(const char *submodule
, struct rev_info
*revs
, unsigned flags
,
1202 int (*for_each
)(const char *, each_ref_fn
, void *))
1204 struct all_refs_cb cb
;
1205 init_all_refs_cb(&cb
, revs
, flags
);
1206 for_each(submodule
, handle_one_ref
, &cb
);
1209 static void handle_one_reflog_commit(unsigned char *sha1
, void *cb_data
)
1211 struct all_refs_cb
*cb
= cb_data
;
1212 if (!is_null_sha1(sha1
)) {
1213 struct object
*o
= parse_object(sha1
);
1215 o
->flags
|= cb
->all_flags
;
1216 /* ??? CMDLINEFLAGS ??? */
1217 add_pending_object(cb
->all_revs
, o
, "");
1219 else if (!cb
->warned_bad_reflog
) {
1220 warning("reflog of '%s' references pruned commits",
1221 cb
->name_for_errormsg
);
1222 cb
->warned_bad_reflog
= 1;
1227 static int handle_one_reflog_ent(unsigned char *osha1
, unsigned char *nsha1
,
1228 const char *email
, unsigned long timestamp
, int tz
,
1229 const char *message
, void *cb_data
)
1231 handle_one_reflog_commit(osha1
, cb_data
);
1232 handle_one_reflog_commit(nsha1
, cb_data
);
1236 static int handle_one_reflog(const char *path
, const unsigned char *sha1
, int flag
, void *cb_data
)
1238 struct all_refs_cb
*cb
= cb_data
;
1239 cb
->warned_bad_reflog
= 0;
1240 cb
->name_for_errormsg
= path
;
1241 for_each_reflog_ent(path
, handle_one_reflog_ent
, cb_data
);
1245 static void handle_reflog(struct rev_info
*revs
, unsigned flags
)
1247 struct all_refs_cb cb
;
1249 cb
.all_flags
= flags
;
1250 for_each_reflog(handle_one_reflog
, &cb
);
1253 static int add_parents_only(struct rev_info
*revs
, const char *arg_
, int flags
)
1255 unsigned char sha1
[20];
1257 struct commit
*commit
;
1258 struct commit_list
*parents
;
1259 const char *arg
= arg_
;
1262 flags
^= UNINTERESTING
| BOTTOM
;
1265 if (get_sha1_committish(arg
, sha1
))
1268 it
= get_reference(revs
, arg
, sha1
, 0);
1269 if (!it
&& revs
->ignore_missing
)
1271 if (it
->type
!= OBJ_TAG
)
1273 if (!((struct tag
*)it
)->tagged
)
1275 hashcpy(sha1
, ((struct tag
*)it
)->tagged
->sha1
);
1277 if (it
->type
!= OBJ_COMMIT
)
1279 commit
= (struct commit
*)it
;
1280 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
1281 it
= &parents
->item
->object
;
1283 add_rev_cmdline(revs
, it
, arg_
, REV_CMD_PARENTS_ONLY
, flags
);
1284 add_pending_object(revs
, it
, arg
);
1289 void init_revisions(struct rev_info
*revs
, const char *prefix
)
1291 memset(revs
, 0, sizeof(*revs
));
1293 revs
->abbrev
= DEFAULT_ABBREV
;
1294 revs
->ignore_merges
= 1;
1295 revs
->simplify_history
= 1;
1296 DIFF_OPT_SET(&revs
->pruning
, RECURSIVE
);
1297 DIFF_OPT_SET(&revs
->pruning
, QUICK
);
1298 revs
->pruning
.add_remove
= file_add_remove
;
1299 revs
->pruning
.change
= file_change
;
1300 revs
->sort_order
= REV_SORT_IN_GRAPH_ORDER
;
1302 revs
->prefix
= prefix
;
1305 revs
->skip_count
= -1;
1306 revs
->max_count
= -1;
1307 revs
->max_parents
= -1;
1309 revs
->commit_format
= CMIT_FMT_DEFAULT
;
1311 init_grep_defaults();
1312 grep_init(&revs
->grep_filter
, prefix
);
1313 revs
->grep_filter
.status_only
= 1;
1314 revs
->grep_filter
.regflags
= REG_NEWLINE
;
1316 diff_setup(&revs
->diffopt
);
1317 if (prefix
&& !revs
->diffopt
.prefix
) {
1318 revs
->diffopt
.prefix
= prefix
;
1319 revs
->diffopt
.prefix_length
= strlen(prefix
);
1322 revs
->notes_opt
.use_default_notes
= -1;
1325 static void add_pending_commit_list(struct rev_info
*revs
,
1326 struct commit_list
*commit_list
,
1329 while (commit_list
) {
1330 struct object
*object
= &commit_list
->item
->object
;
1331 object
->flags
|= flags
;
1332 add_pending_object(revs
, object
, sha1_to_hex(object
->sha1
));
1333 commit_list
= commit_list
->next
;
1337 static void prepare_show_merge(struct rev_info
*revs
)
1339 struct commit_list
*bases
;
1340 struct commit
*head
, *other
;
1341 unsigned char sha1
[20];
1342 const char **prune
= NULL
;
1343 int i
, prune_num
= 1; /* counting terminating NULL */
1345 if (get_sha1("HEAD", sha1
))
1346 die("--merge without HEAD?");
1347 head
= lookup_commit_or_die(sha1
, "HEAD");
1348 if (get_sha1("MERGE_HEAD", sha1
))
1349 die("--merge without MERGE_HEAD?");
1350 other
= lookup_commit_or_die(sha1
, "MERGE_HEAD");
1351 add_pending_object(revs
, &head
->object
, "HEAD");
1352 add_pending_object(revs
, &other
->object
, "MERGE_HEAD");
1353 bases
= get_merge_bases(head
, other
, 1);
1354 add_rev_cmdline_list(revs
, bases
, REV_CMD_MERGE_BASE
, UNINTERESTING
| BOTTOM
);
1355 add_pending_commit_list(revs
, bases
, UNINTERESTING
| BOTTOM
);
1356 free_commit_list(bases
);
1357 head
->object
.flags
|= SYMMETRIC_LEFT
;
1361 for (i
= 0; i
< active_nr
; i
++) {
1362 const struct cache_entry
*ce
= active_cache
[i
];
1365 if (ce_path_match(ce
, &revs
->prune_data
)) {
1367 prune
= xrealloc(prune
, sizeof(*prune
) * prune_num
);
1368 prune
[prune_num
-2] = ce
->name
;
1369 prune
[prune_num
-1] = NULL
;
1371 while ((i
+1 < active_nr
) &&
1372 ce_same_name(ce
, active_cache
[i
+1]))
1375 free_pathspec(&revs
->prune_data
);
1376 init_pathspec(&revs
->prune_data
, prune
);
1380 int handle_revision_arg(const char *arg_
, struct rev_info
*revs
, int flags
, unsigned revarg_opt
)
1382 struct object_context oc
;
1384 struct object
*object
;
1385 unsigned char sha1
[20];
1387 const char *arg
= arg_
;
1388 int cant_be_filename
= revarg_opt
& REVARG_CANNOT_BE_FILENAME
;
1389 unsigned get_sha1_flags
= 0;
1391 flags
= flags
& UNINTERESTING
? flags
| BOTTOM
: flags
& ~BOTTOM
;
1393 dotdot
= strstr(arg
, "..");
1395 unsigned char from_sha1
[20];
1396 const char *next
= dotdot
+ 2;
1397 const char *this = arg
;
1398 int symmetric
= *next
== '.';
1399 unsigned int flags_exclude
= flags
^ (UNINTERESTING
| BOTTOM
);
1400 static const char head_by_default
[] = "HEAD";
1401 unsigned int a_flags
;
1407 next
= head_by_default
;
1409 this = head_by_default
;
1410 if (this == head_by_default
&& next
== head_by_default
&&
1413 * Just ".."? That is not a range but the
1414 * pathspec for the parent directory.
1416 if (!cant_be_filename
) {
1421 if (!get_sha1_committish(this, from_sha1
) &&
1422 !get_sha1_committish(next
, sha1
)) {
1423 struct commit
*a
, *b
;
1424 struct commit_list
*exclude
;
1426 a
= lookup_commit_reference(from_sha1
);
1427 b
= lookup_commit_reference(sha1
);
1429 if (revs
->ignore_missing
)
1432 "Invalid symmetric difference expression %s...%s" :
1433 "Invalid revision range %s..%s",
1437 if (!cant_be_filename
) {
1439 verify_non_filename(revs
->prefix
, arg
);
1443 exclude
= get_merge_bases(a
, b
, 1);
1444 add_rev_cmdline_list(revs
, exclude
,
1447 add_pending_commit_list(revs
, exclude
,
1449 free_commit_list(exclude
);
1450 a_flags
= flags
| SYMMETRIC_LEFT
;
1452 a_flags
= flags_exclude
;
1453 a
->object
.flags
|= a_flags
;
1454 b
->object
.flags
|= flags
;
1455 add_rev_cmdline(revs
, &a
->object
, this,
1456 REV_CMD_LEFT
, a_flags
);
1457 add_rev_cmdline(revs
, &b
->object
, next
,
1458 REV_CMD_RIGHT
, flags
);
1459 add_pending_object(revs
, &a
->object
, this);
1460 add_pending_object(revs
, &b
->object
, next
);
1465 dotdot
= strstr(arg
, "^@");
1466 if (dotdot
&& !dotdot
[2]) {
1468 if (add_parents_only(revs
, arg
, flags
))
1472 dotdot
= strstr(arg
, "^!");
1473 if (dotdot
&& !dotdot
[2]) {
1475 if (!add_parents_only(revs
, arg
, flags
^ (UNINTERESTING
| BOTTOM
)))
1481 local_flags
= UNINTERESTING
| BOTTOM
;
1485 if (revarg_opt
& REVARG_COMMITTISH
)
1486 get_sha1_flags
= GET_SHA1_COMMITTISH
;
1488 if (get_sha1_with_context(arg
, get_sha1_flags
, sha1
, &oc
))
1489 return revs
->ignore_missing
? 0 : -1;
1490 if (!cant_be_filename
)
1491 verify_non_filename(revs
->prefix
, arg
);
1492 object
= get_reference(revs
, arg
, sha1
, flags
^ local_flags
);
1493 add_rev_cmdline(revs
, object
, arg_
, REV_CMD_REV
, flags
^ local_flags
);
1494 add_pending_object_with_mode(revs
, object
, arg
, oc
.mode
);
1498 struct cmdline_pathspec
{
1504 static void append_prune_data(struct cmdline_pathspec
*prune
, const char **av
)
1507 ALLOC_GROW(prune
->path
, prune
->nr
+1, prune
->alloc
);
1508 prune
->path
[prune
->nr
++] = *(av
++);
1512 static void read_pathspec_from_stdin(struct rev_info
*revs
, struct strbuf
*sb
,
1513 struct cmdline_pathspec
*prune
)
1515 while (strbuf_getwholeline(sb
, stdin
, '\n') != EOF
) {
1517 if (len
&& sb
->buf
[len
- 1] == '\n')
1518 sb
->buf
[--len
] = '\0';
1519 ALLOC_GROW(prune
->path
, prune
->nr
+1, prune
->alloc
);
1520 prune
->path
[prune
->nr
++] = xstrdup(sb
->buf
);
1524 static void read_revisions_from_stdin(struct rev_info
*revs
,
1525 struct cmdline_pathspec
*prune
)
1528 int seen_dashdash
= 0;
1530 strbuf_init(&sb
, 1000);
1531 while (strbuf_getwholeline(&sb
, stdin
, '\n') != EOF
) {
1533 if (len
&& sb
.buf
[len
- 1] == '\n')
1534 sb
.buf
[--len
] = '\0';
1537 if (sb
.buf
[0] == '-') {
1538 if (len
== 2 && sb
.buf
[1] == '-') {
1542 die("options not supported in --stdin mode");
1544 if (handle_revision_arg(sb
.buf
, revs
, 0,
1545 REVARG_CANNOT_BE_FILENAME
))
1546 die("bad revision '%s'", sb
.buf
);
1549 read_pathspec_from_stdin(revs
, &sb
, prune
);
1550 strbuf_release(&sb
);
1553 static void add_grep(struct rev_info
*revs
, const char *ptn
, enum grep_pat_token what
)
1555 append_grep_pattern(&revs
->grep_filter
, ptn
, "command line", 0, what
);
1558 static void add_header_grep(struct rev_info
*revs
, enum grep_header_field field
, const char *pattern
)
1560 append_header_grep_pattern(&revs
->grep_filter
, field
, pattern
);
1563 static void add_message_grep(struct rev_info
*revs
, const char *pattern
)
1565 add_grep(revs
, pattern
, GREP_PATTERN_BODY
);
1568 static int handle_revision_opt(struct rev_info
*revs
, int argc
, const char **argv
,
1569 int *unkc
, const char **unkv
)
1571 const char *arg
= argv
[0];
1575 /* pseudo revision arguments */
1576 if (!strcmp(arg
, "--all") || !strcmp(arg
, "--branches") ||
1577 !strcmp(arg
, "--tags") || !strcmp(arg
, "--remotes") ||
1578 !strcmp(arg
, "--reflog") || !strcmp(arg
, "--not") ||
1579 !strcmp(arg
, "--no-walk") || !strcmp(arg
, "--do-walk") ||
1580 !strcmp(arg
, "--bisect") || !prefixcmp(arg
, "--glob=") ||
1581 !prefixcmp(arg
, "--branches=") || !prefixcmp(arg
, "--tags=") ||
1582 !prefixcmp(arg
, "--remotes=") || !prefixcmp(arg
, "--no-walk="))
1584 unkv
[(*unkc
)++] = arg
;
1588 if ((argcount
= parse_long_opt("max-count", argv
, &optarg
))) {
1589 revs
->max_count
= atoi(optarg
);
1592 } else if ((argcount
= parse_long_opt("skip", argv
, &optarg
))) {
1593 revs
->skip_count
= atoi(optarg
);
1595 } else if ((*arg
== '-') && isdigit(arg
[1])) {
1596 /* accept -<digit>, like traditional "head" */
1597 revs
->max_count
= atoi(arg
+ 1);
1599 } else if (!strcmp(arg
, "-n")) {
1601 return error("-n requires an argument");
1602 revs
->max_count
= atoi(argv
[1]);
1605 } else if (!prefixcmp(arg
, "-n")) {
1606 revs
->max_count
= atoi(arg
+ 2);
1608 } else if ((argcount
= parse_long_opt("max-age", argv
, &optarg
))) {
1609 revs
->max_age
= atoi(optarg
);
1611 } else if ((argcount
= parse_long_opt("since", argv
, &optarg
))) {
1612 revs
->max_age
= approxidate(optarg
);
1614 } else if ((argcount
= parse_long_opt("after", argv
, &optarg
))) {
1615 revs
->max_age
= approxidate(optarg
);
1617 } else if ((argcount
= parse_long_opt("min-age", argv
, &optarg
))) {
1618 revs
->min_age
= atoi(optarg
);
1620 } else if ((argcount
= parse_long_opt("before", argv
, &optarg
))) {
1621 revs
->min_age
= approxidate(optarg
);
1623 } else if ((argcount
= parse_long_opt("until", argv
, &optarg
))) {
1624 revs
->min_age
= approxidate(optarg
);
1626 } else if (!strcmp(arg
, "--first-parent")) {
1627 revs
->first_parent_only
= 1;
1628 } else if (!strcmp(arg
, "--ancestry-path")) {
1629 revs
->ancestry_path
= 1;
1630 revs
->simplify_history
= 0;
1632 } else if (!strcmp(arg
, "-g") || !strcmp(arg
, "--walk-reflogs")) {
1633 init_reflog_walk(&revs
->reflog_info
);
1634 } else if (!strcmp(arg
, "--default")) {
1636 return error("bad --default argument");
1637 revs
->def
= argv
[1];
1639 } else if (!strcmp(arg
, "--merge")) {
1640 revs
->show_merge
= 1;
1641 } else if (!strcmp(arg
, "--topo-order")) {
1642 revs
->sort_order
= REV_SORT_IN_GRAPH_ORDER
;
1643 revs
->topo_order
= 1;
1644 } else if (!strcmp(arg
, "--simplify-merges")) {
1645 revs
->simplify_merges
= 1;
1646 revs
->topo_order
= 1;
1647 revs
->rewrite_parents
= 1;
1648 revs
->simplify_history
= 0;
1650 } else if (!strcmp(arg
, "--simplify-by-decoration")) {
1651 revs
->simplify_merges
= 1;
1652 revs
->topo_order
= 1;
1653 revs
->rewrite_parents
= 1;
1654 revs
->simplify_history
= 0;
1655 revs
->simplify_by_decoration
= 1;
1658 load_ref_decorations(DECORATE_SHORT_REFS
);
1659 } else if (!strcmp(arg
, "--date-order")) {
1660 revs
->sort_order
= REV_SORT_BY_COMMIT_DATE
;
1661 revs
->topo_order
= 1;
1662 } else if (!strcmp(arg
, "--author-date-order")) {
1663 revs
->sort_order
= REV_SORT_BY_AUTHOR_DATE
;
1664 revs
->topo_order
= 1;
1665 } else if (!prefixcmp(arg
, "--early-output")) {
1669 count
= atoi(arg
+15);
1672 revs
->topo_order
= 1;
1673 revs
->early_output
= count
;
1675 } else if (!strcmp(arg
, "--parents")) {
1676 revs
->rewrite_parents
= 1;
1677 revs
->print_parents
= 1;
1678 } else if (!strcmp(arg
, "--dense")) {
1680 } else if (!strcmp(arg
, "--sparse")) {
1682 } else if (!strcmp(arg
, "--show-all")) {
1684 } else if (!strcmp(arg
, "--remove-empty")) {
1685 revs
->remove_empty_trees
= 1;
1686 } else if (!strcmp(arg
, "--merges")) {
1687 revs
->min_parents
= 2;
1688 } else if (!strcmp(arg
, "--no-merges")) {
1689 revs
->max_parents
= 1;
1690 } else if (!prefixcmp(arg
, "--min-parents=")) {
1691 revs
->min_parents
= atoi(arg
+14);
1692 } else if (!prefixcmp(arg
, "--no-min-parents")) {
1693 revs
->min_parents
= 0;
1694 } else if (!prefixcmp(arg
, "--max-parents=")) {
1695 revs
->max_parents
= atoi(arg
+14);
1696 } else if (!prefixcmp(arg
, "--no-max-parents")) {
1697 revs
->max_parents
= -1;
1698 } else if (!strcmp(arg
, "--boundary")) {
1700 } else if (!strcmp(arg
, "--left-right")) {
1701 revs
->left_right
= 1;
1702 } else if (!strcmp(arg
, "--left-only")) {
1703 if (revs
->right_only
)
1704 die("--left-only is incompatible with --right-only"
1706 revs
->left_only
= 1;
1707 } else if (!strcmp(arg
, "--right-only")) {
1708 if (revs
->left_only
)
1709 die("--right-only is incompatible with --left-only");
1710 revs
->right_only
= 1;
1711 } else if (!strcmp(arg
, "--cherry")) {
1712 if (revs
->left_only
)
1713 die("--cherry is incompatible with --left-only");
1714 revs
->cherry_mark
= 1;
1715 revs
->right_only
= 1;
1716 revs
->max_parents
= 1;
1718 } else if (!strcmp(arg
, "--count")) {
1720 } else if (!strcmp(arg
, "--cherry-mark")) {
1721 if (revs
->cherry_pick
)
1722 die("--cherry-mark is incompatible with --cherry-pick");
1723 revs
->cherry_mark
= 1;
1724 revs
->limited
= 1; /* needs limit_list() */
1725 } else if (!strcmp(arg
, "--cherry-pick")) {
1726 if (revs
->cherry_mark
)
1727 die("--cherry-pick is incompatible with --cherry-mark");
1728 revs
->cherry_pick
= 1;
1730 } else if (!strcmp(arg
, "--objects")) {
1731 revs
->tag_objects
= 1;
1732 revs
->tree_objects
= 1;
1733 revs
->blob_objects
= 1;
1734 } else if (!strcmp(arg
, "--objects-edge")) {
1735 revs
->tag_objects
= 1;
1736 revs
->tree_objects
= 1;
1737 revs
->blob_objects
= 1;
1738 revs
->edge_hint
= 1;
1739 } else if (!strcmp(arg
, "--verify-objects")) {
1740 revs
->tag_objects
= 1;
1741 revs
->tree_objects
= 1;
1742 revs
->blob_objects
= 1;
1743 revs
->verify_objects
= 1;
1744 } else if (!strcmp(arg
, "--unpacked")) {
1746 } else if (!prefixcmp(arg
, "--unpacked=")) {
1747 die("--unpacked=<packfile> no longer supported.");
1748 } else if (!strcmp(arg
, "-r")) {
1750 DIFF_OPT_SET(&revs
->diffopt
, RECURSIVE
);
1751 } else if (!strcmp(arg
, "-t")) {
1753 DIFF_OPT_SET(&revs
->diffopt
, RECURSIVE
);
1754 DIFF_OPT_SET(&revs
->diffopt
, TREE_IN_RECURSIVE
);
1755 } else if (!strcmp(arg
, "-m")) {
1756 revs
->ignore_merges
= 0;
1757 } else if (!strcmp(arg
, "-c")) {
1759 revs
->dense_combined_merges
= 0;
1760 revs
->combine_merges
= 1;
1761 } else if (!strcmp(arg
, "--cc")) {
1763 revs
->dense_combined_merges
= 1;
1764 revs
->combine_merges
= 1;
1765 } else if (!strcmp(arg
, "-v")) {
1766 revs
->verbose_header
= 1;
1767 } else if (!strcmp(arg
, "--pretty")) {
1768 revs
->verbose_header
= 1;
1769 revs
->pretty_given
= 1;
1770 get_commit_format(arg
+8, revs
);
1771 } else if (!prefixcmp(arg
, "--pretty=") || !prefixcmp(arg
, "--format=")) {
1773 * Detached form ("--pretty X" as opposed to "--pretty=X")
1774 * not allowed, since the argument is optional.
1776 revs
->verbose_header
= 1;
1777 revs
->pretty_given
= 1;
1778 get_commit_format(arg
+9, revs
);
1779 } else if (!strcmp(arg
, "--show-notes") || !strcmp(arg
, "--notes")) {
1780 revs
->show_notes
= 1;
1781 revs
->show_notes_given
= 1;
1782 revs
->notes_opt
.use_default_notes
= 1;
1783 } else if (!strcmp(arg
, "--show-signature")) {
1784 revs
->show_signature
= 1;
1785 } else if (!prefixcmp(arg
, "--show-notes=") ||
1786 !prefixcmp(arg
, "--notes=")) {
1787 struct strbuf buf
= STRBUF_INIT
;
1788 revs
->show_notes
= 1;
1789 revs
->show_notes_given
= 1;
1790 if (!prefixcmp(arg
, "--show-notes")) {
1791 if (revs
->notes_opt
.use_default_notes
< 0)
1792 revs
->notes_opt
.use_default_notes
= 1;
1793 strbuf_addstr(&buf
, arg
+13);
1796 strbuf_addstr(&buf
, arg
+8);
1797 expand_notes_ref(&buf
);
1798 string_list_append(&revs
->notes_opt
.extra_notes_refs
,
1799 strbuf_detach(&buf
, NULL
));
1800 } else if (!strcmp(arg
, "--no-notes")) {
1801 revs
->show_notes
= 0;
1802 revs
->show_notes_given
= 1;
1803 revs
->notes_opt
.use_default_notes
= -1;
1804 /* we have been strdup'ing ourselves, so trick
1805 * string_list into free()ing strings */
1806 revs
->notes_opt
.extra_notes_refs
.strdup_strings
= 1;
1807 string_list_clear(&revs
->notes_opt
.extra_notes_refs
, 0);
1808 revs
->notes_opt
.extra_notes_refs
.strdup_strings
= 0;
1809 } else if (!strcmp(arg
, "--standard-notes")) {
1810 revs
->show_notes_given
= 1;
1811 revs
->notes_opt
.use_default_notes
= 1;
1812 } else if (!strcmp(arg
, "--no-standard-notes")) {
1813 revs
->notes_opt
.use_default_notes
= 0;
1814 } else if (!strcmp(arg
, "--oneline")) {
1815 revs
->verbose_header
= 1;
1816 get_commit_format("oneline", revs
);
1817 revs
->pretty_given
= 1;
1818 revs
->abbrev_commit
= 1;
1819 } else if (!strcmp(arg
, "--graph")) {
1820 revs
->topo_order
= 1;
1821 revs
->rewrite_parents
= 1;
1822 revs
->graph
= graph_init(revs
);
1823 } else if (!strcmp(arg
, "--root")) {
1824 revs
->show_root_diff
= 1;
1825 } else if (!strcmp(arg
, "--no-commit-id")) {
1826 revs
->no_commit_id
= 1;
1827 } else if (!strcmp(arg
, "--always")) {
1828 revs
->always_show_header
= 1;
1829 } else if (!strcmp(arg
, "--no-abbrev")) {
1831 } else if (!strcmp(arg
, "--abbrev")) {
1832 revs
->abbrev
= DEFAULT_ABBREV
;
1833 } else if (!prefixcmp(arg
, "--abbrev=")) {
1834 revs
->abbrev
= strtoul(arg
+ 9, NULL
, 10);
1835 if (revs
->abbrev
< MINIMUM_ABBREV
)
1836 revs
->abbrev
= MINIMUM_ABBREV
;
1837 else if (revs
->abbrev
> 40)
1839 } else if (!strcmp(arg
, "--abbrev-commit")) {
1840 revs
->abbrev_commit
= 1;
1841 revs
->abbrev_commit_given
= 1;
1842 } else if (!strcmp(arg
, "--no-abbrev-commit")) {
1843 revs
->abbrev_commit
= 0;
1844 } else if (!strcmp(arg
, "--full-diff")) {
1846 revs
->full_diff
= 1;
1847 } else if (!strcmp(arg
, "--full-history")) {
1848 revs
->simplify_history
= 0;
1849 } else if (!strcmp(arg
, "--relative-date")) {
1850 revs
->date_mode
= DATE_RELATIVE
;
1851 revs
->date_mode_explicit
= 1;
1852 } else if ((argcount
= parse_long_opt("date", argv
, &optarg
))) {
1853 revs
->date_mode
= parse_date_format(optarg
);
1854 revs
->date_mode_explicit
= 1;
1856 } else if (!strcmp(arg
, "--log-size")) {
1857 revs
->show_log_size
= 1;
1860 * Grepping the commit log
1862 else if ((argcount
= parse_long_opt("author", argv
, &optarg
))) {
1863 add_header_grep(revs
, GREP_HEADER_AUTHOR
, optarg
);
1865 } else if ((argcount
= parse_long_opt("committer", argv
, &optarg
))) {
1866 add_header_grep(revs
, GREP_HEADER_COMMITTER
, optarg
);
1868 } else if ((argcount
= parse_long_opt("grep-reflog", argv
, &optarg
))) {
1869 add_header_grep(revs
, GREP_HEADER_REFLOG
, optarg
);
1871 } else if ((argcount
= parse_long_opt("grep", argv
, &optarg
))) {
1872 add_message_grep(revs
, optarg
);
1874 } else if (!strcmp(arg
, "--grep-debug")) {
1875 revs
->grep_filter
.debug
= 1;
1876 } else if (!strcmp(arg
, "--basic-regexp")) {
1877 grep_set_pattern_type_option(GREP_PATTERN_TYPE_BRE
, &revs
->grep_filter
);
1878 } else if (!strcmp(arg
, "--extended-regexp") || !strcmp(arg
, "-E")) {
1879 grep_set_pattern_type_option(GREP_PATTERN_TYPE_ERE
, &revs
->grep_filter
);
1880 } else if (!strcmp(arg
, "--regexp-ignore-case") || !strcmp(arg
, "-i")) {
1881 revs
->grep_filter
.regflags
|= REG_ICASE
;
1882 DIFF_OPT_SET(&revs
->diffopt
, PICKAXE_IGNORE_CASE
);
1883 } else if (!strcmp(arg
, "--fixed-strings") || !strcmp(arg
, "-F")) {
1884 grep_set_pattern_type_option(GREP_PATTERN_TYPE_FIXED
, &revs
->grep_filter
);
1885 } else if (!strcmp(arg
, "--perl-regexp")) {
1886 grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE
, &revs
->grep_filter
);
1887 } else if (!strcmp(arg
, "--all-match")) {
1888 revs
->grep_filter
.all_match
= 1;
1889 } else if ((argcount
= parse_long_opt("encoding", argv
, &optarg
))) {
1890 if (strcmp(optarg
, "none"))
1891 git_log_output_encoding
= xstrdup(optarg
);
1893 git_log_output_encoding
= "";
1895 } else if (!strcmp(arg
, "--reverse")) {
1897 } else if (!strcmp(arg
, "--children")) {
1898 revs
->children
.name
= "children";
1900 } else if (!strcmp(arg
, "--ignore-missing")) {
1901 revs
->ignore_missing
= 1;
1903 int opts
= diff_opt_parse(&revs
->diffopt
, argv
, argc
);
1905 unkv
[(*unkc
)++] = arg
;
1912 void parse_revision_opt(struct rev_info
*revs
, struct parse_opt_ctx_t
*ctx
,
1913 const struct option
*options
,
1914 const char * const usagestr
[])
1916 int n
= handle_revision_opt(revs
, ctx
->argc
, ctx
->argv
,
1917 &ctx
->cpidx
, ctx
->out
);
1919 error("unknown option `%s'", ctx
->argv
[0]);
1920 usage_with_options(usagestr
, options
);
1926 static int for_each_bad_bisect_ref(const char *submodule
, each_ref_fn fn
, void *cb_data
)
1928 return for_each_ref_in_submodule(submodule
, "refs/bisect/bad", fn
, cb_data
);
1931 static int for_each_good_bisect_ref(const char *submodule
, each_ref_fn fn
, void *cb_data
)
1933 return for_each_ref_in_submodule(submodule
, "refs/bisect/good", fn
, cb_data
);
1936 static int handle_revision_pseudo_opt(const char *submodule
,
1937 struct rev_info
*revs
,
1938 int argc
, const char **argv
, int *flags
)
1940 const char *arg
= argv
[0];
1947 * Commands like "git shortlog" will not accept the options below
1948 * unless parse_revision_opt queues them (as opposed to erroring
1951 * When implementing your new pseudo-option, remember to
1952 * register it in the list at the top of handle_revision_opt.
1954 if (!strcmp(arg
, "--all")) {
1955 handle_refs(submodule
, revs
, *flags
, for_each_ref_submodule
);
1956 handle_refs(submodule
, revs
, *flags
, head_ref_submodule
);
1957 } else if (!strcmp(arg
, "--branches")) {
1958 handle_refs(submodule
, revs
, *flags
, for_each_branch_ref_submodule
);
1959 } else if (!strcmp(arg
, "--bisect")) {
1960 handle_refs(submodule
, revs
, *flags
, for_each_bad_bisect_ref
);
1961 handle_refs(submodule
, revs
, *flags
^ (UNINTERESTING
| BOTTOM
), for_each_good_bisect_ref
);
1963 } else if (!strcmp(arg
, "--tags")) {
1964 handle_refs(submodule
, revs
, *flags
, for_each_tag_ref_submodule
);
1965 } else if (!strcmp(arg
, "--remotes")) {
1966 handle_refs(submodule
, revs
, *flags
, for_each_remote_ref_submodule
);
1967 } else if ((argcount
= parse_long_opt("glob", argv
, &optarg
))) {
1968 struct all_refs_cb cb
;
1969 init_all_refs_cb(&cb
, revs
, *flags
);
1970 for_each_glob_ref(handle_one_ref
, optarg
, &cb
);
1972 } else if (!prefixcmp(arg
, "--branches=")) {
1973 struct all_refs_cb cb
;
1974 init_all_refs_cb(&cb
, revs
, *flags
);
1975 for_each_glob_ref_in(handle_one_ref
, arg
+ 11, "refs/heads/", &cb
);
1976 } else if (!prefixcmp(arg
, "--tags=")) {
1977 struct all_refs_cb cb
;
1978 init_all_refs_cb(&cb
, revs
, *flags
);
1979 for_each_glob_ref_in(handle_one_ref
, arg
+ 7, "refs/tags/", &cb
);
1980 } else if (!prefixcmp(arg
, "--remotes=")) {
1981 struct all_refs_cb cb
;
1982 init_all_refs_cb(&cb
, revs
, *flags
);
1983 for_each_glob_ref_in(handle_one_ref
, arg
+ 10, "refs/remotes/", &cb
);
1984 } else if (!strcmp(arg
, "--reflog")) {
1985 handle_reflog(revs
, *flags
);
1986 } else if (!strcmp(arg
, "--not")) {
1987 *flags
^= UNINTERESTING
| BOTTOM
;
1988 } else if (!strcmp(arg
, "--no-walk")) {
1989 revs
->no_walk
= REVISION_WALK_NO_WALK_SORTED
;
1990 } else if (!prefixcmp(arg
, "--no-walk=")) {
1992 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
1993 * not allowed, since the argument is optional.
1995 if (!strcmp(arg
+ 10, "sorted"))
1996 revs
->no_walk
= REVISION_WALK_NO_WALK_SORTED
;
1997 else if (!strcmp(arg
+ 10, "unsorted"))
1998 revs
->no_walk
= REVISION_WALK_NO_WALK_UNSORTED
;
2000 return error("invalid argument to --no-walk");
2001 } else if (!strcmp(arg
, "--do-walk")) {
2011 * Parse revision information, filling in the "rev_info" structure,
2012 * and removing the used arguments from the argument list.
2014 * Returns the number of arguments left that weren't recognized
2015 * (which are also moved to the head of the argument list)
2017 int setup_revisions(int argc
, const char **argv
, struct rev_info
*revs
, struct setup_revision_opt
*opt
)
2019 int i
, flags
, left
, seen_dashdash
, read_from_stdin
, got_rev_arg
= 0, revarg_opt
;
2020 struct cmdline_pathspec prune_data
;
2021 const char *submodule
= NULL
;
2023 memset(&prune_data
, 0, sizeof(prune_data
));
2025 submodule
= opt
->submodule
;
2027 /* First, search for "--" */
2028 if (opt
&& opt
->assume_dashdash
) {
2032 for (i
= 1; i
< argc
; i
++) {
2033 const char *arg
= argv
[i
];
2034 if (strcmp(arg
, "--"))
2039 append_prune_data(&prune_data
, argv
+ i
+ 1);
2045 /* Second, deal with arguments and options */
2047 revarg_opt
= opt
? opt
->revarg_opt
: 0;
2049 revarg_opt
|= REVARG_CANNOT_BE_FILENAME
;
2050 read_from_stdin
= 0;
2051 for (left
= i
= 1; i
< argc
; i
++) {
2052 const char *arg
= argv
[i
];
2056 opts
= handle_revision_pseudo_opt(submodule
,
2057 revs
, argc
- i
, argv
+ i
,
2064 if (!strcmp(arg
, "--stdin")) {
2065 if (revs
->disable_stdin
) {
2069 if (read_from_stdin
++)
2070 die("--stdin given twice?");
2071 read_revisions_from_stdin(revs
, &prune_data
);
2075 opts
= handle_revision_opt(revs
, argc
- i
, argv
+ i
, &left
, argv
);
2086 if (handle_revision_arg(arg
, revs
, flags
, revarg_opt
)) {
2088 if (seen_dashdash
|| *arg
== '^')
2089 die("bad revision '%s'", arg
);
2091 /* If we didn't have a "--":
2092 * (1) all filenames must exist;
2093 * (2) all rev-args must not be interpretable
2094 * as a valid filename.
2095 * but the latter we have checked in the main loop.
2097 for (j
= i
; j
< argc
; j
++)
2098 verify_filename(revs
->prefix
, argv
[j
], j
== i
);
2100 append_prune_data(&prune_data
, argv
+ i
);
2107 if (prune_data
.nr
) {
2109 * If we need to introduce the magic "a lone ':' means no
2110 * pathspec whatsoever", here is the place to do so.
2112 * if (prune_data.nr == 1 && !strcmp(prune_data[0], ":")) {
2113 * prune_data.nr = 0;
2114 * prune_data.alloc = 0;
2115 * free(prune_data.path);
2116 * prune_data.path = NULL;
2118 * terminate prune_data.alloc with NULL and
2119 * call init_pathspec() to set revs->prune_data here.
2122 ALLOC_GROW(prune_data
.path
, prune_data
.nr
+1, prune_data
.alloc
);
2123 prune_data
.path
[prune_data
.nr
++] = NULL
;
2124 init_pathspec(&revs
->prune_data
,
2125 get_pathspec(revs
->prefix
, prune_data
.path
));
2128 if (revs
->def
== NULL
)
2129 revs
->def
= opt
? opt
->def
: NULL
;
2130 if (opt
&& opt
->tweak
)
2131 opt
->tweak(revs
, opt
);
2132 if (revs
->show_merge
)
2133 prepare_show_merge(revs
);
2134 if (revs
->def
&& !revs
->pending
.nr
&& !got_rev_arg
) {
2135 unsigned char sha1
[20];
2136 struct object
*object
;
2137 struct object_context oc
;
2138 if (get_sha1_with_context(revs
->def
, 0, sha1
, &oc
))
2139 die("bad default revision '%s'", revs
->def
);
2140 object
= get_reference(revs
, revs
->def
, sha1
, 0);
2141 add_pending_object_with_mode(revs
, object
, revs
->def
, oc
.mode
);
2144 /* Did the user ask for any diff output? Run the diff! */
2145 if (revs
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
)
2148 /* Pickaxe, diff-filter and rename following need diffs */
2149 if (revs
->diffopt
.pickaxe
||
2150 revs
->diffopt
.filter
||
2151 DIFF_OPT_TST(&revs
->diffopt
, FOLLOW_RENAMES
))
2154 if (revs
->topo_order
)
2157 if (revs
->prune_data
.nr
) {
2158 diff_tree_setup_paths(revs
->prune_data
.raw
, &revs
->pruning
);
2159 /* Can't prune commits with rename following: the paths change.. */
2160 if (!DIFF_OPT_TST(&revs
->diffopt
, FOLLOW_RENAMES
))
2162 if (!revs
->full_diff
)
2163 diff_tree_setup_paths(revs
->prune_data
.raw
, &revs
->diffopt
);
2165 if (revs
->combine_merges
)
2166 revs
->ignore_merges
= 0;
2167 revs
->diffopt
.abbrev
= revs
->abbrev
;
2169 if (revs
->line_level_traverse
) {
2171 revs
->topo_order
= 1;
2174 diff_setup_done(&revs
->diffopt
);
2176 grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED
,
2177 &revs
->grep_filter
);
2178 compile_grep_patterns(&revs
->grep_filter
);
2180 if (revs
->reverse
&& revs
->reflog_info
)
2181 die("cannot combine --reverse with --walk-reflogs");
2182 if (revs
->rewrite_parents
&& revs
->children
.name
)
2183 die("cannot combine --parents and --children");
2186 * Limitations on the graph functionality
2188 if (revs
->reverse
&& revs
->graph
)
2189 die("cannot combine --reverse with --graph");
2191 if (revs
->reflog_info
&& revs
->graph
)
2192 die("cannot combine --walk-reflogs with --graph");
2193 if (!revs
->reflog_info
&& revs
->grep_filter
.use_reflog_filter
)
2194 die("cannot use --grep-reflog without --walk-reflogs");
2199 static void add_child(struct rev_info
*revs
, struct commit
*parent
, struct commit
*child
)
2201 struct commit_list
*l
= xcalloc(1, sizeof(*l
));
2204 l
->next
= add_decoration(&revs
->children
, &parent
->object
, l
);
2207 static int remove_duplicate_parents(struct rev_info
*revs
, struct commit
*commit
)
2209 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
2210 struct commit_list
**pp
, *p
;
2211 int surviving_parents
;
2213 /* Examine existing parents while marking ones we have seen... */
2214 pp
= &commit
->parents
;
2215 surviving_parents
= 0;
2216 while ((p
= *pp
) != NULL
) {
2217 struct commit
*parent
= p
->item
;
2218 if (parent
->object
.flags
& TMP_MARK
) {
2221 compact_treesame(revs
, commit
, surviving_parents
);
2224 parent
->object
.flags
|= TMP_MARK
;
2225 surviving_parents
++;
2228 /* clear the temporary mark */
2229 for (p
= commit
->parents
; p
; p
= p
->next
) {
2230 p
->item
->object
.flags
&= ~TMP_MARK
;
2232 /* no update_treesame() - removing duplicates can't affect TREESAME */
2233 return surviving_parents
;
2236 struct merge_simplify_state
{
2237 struct commit
*simplified
;
2240 static struct merge_simplify_state
*locate_simplify_state(struct rev_info
*revs
, struct commit
*commit
)
2242 struct merge_simplify_state
*st
;
2244 st
= lookup_decoration(&revs
->merge_simplification
, &commit
->object
);
2246 st
= xcalloc(1, sizeof(*st
));
2247 add_decoration(&revs
->merge_simplification
, &commit
->object
, st
);
2252 static int mark_redundant_parents(struct rev_info
*revs
, struct commit
*commit
)
2254 struct commit_list
*h
= reduce_heads(commit
->parents
);
2255 int i
= 0, marked
= 0;
2256 struct commit_list
*po
, *pn
;
2258 /* Want these for sanity-checking only */
2259 int orig_cnt
= commit_list_count(commit
->parents
);
2260 int cnt
= commit_list_count(h
);
2263 * Not ready to remove items yet, just mark them for now, based
2264 * on the output of reduce_heads(). reduce_heads outputs the reduced
2265 * set in its original order, so this isn't too hard.
2267 po
= commit
->parents
;
2270 if (pn
&& po
->item
== pn
->item
) {
2274 po
->item
->object
.flags
|= TMP_MARK
;
2280 if (i
!= cnt
|| cnt
+marked
!= orig_cnt
)
2281 die("mark_redundant_parents %d %d %d %d", orig_cnt
, cnt
, i
, marked
);
2283 free_commit_list(h
);
2288 static int mark_treesame_root_parents(struct rev_info
*revs
, struct commit
*commit
)
2290 struct commit_list
*p
;
2293 for (p
= commit
->parents
; p
; p
= p
->next
) {
2294 struct commit
*parent
= p
->item
;
2295 if (!parent
->parents
&& (parent
->object
.flags
& TREESAME
)) {
2296 parent
->object
.flags
|= TMP_MARK
;
2305 * Awkward naming - this means one parent we are TREESAME to.
2306 * cf mark_treesame_root_parents: root parents that are TREESAME (to an
2307 * empty tree). Better name suggestions?
2309 static int leave_one_treesame_to_parent(struct rev_info
*revs
, struct commit
*commit
)
2311 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
2312 struct commit
*unmarked
= NULL
, *marked
= NULL
;
2313 struct commit_list
*p
;
2316 for (p
= commit
->parents
, n
= 0; p
; p
= p
->next
, n
++) {
2317 if (ts
->treesame
[n
]) {
2318 if (p
->item
->object
.flags
& TMP_MARK
) {
2331 * If we are TREESAME to a marked-for-deletion parent, but not to any
2332 * unmarked parents, unmark the first TREESAME parent. This is the
2333 * parent that the default simplify_history==1 scan would have followed,
2334 * and it doesn't make sense to omit that path when asking for a
2335 * simplified full history. Retaining it improves the chances of
2336 * understanding odd missed merges that took an old version of a file.
2340 * I--------*X A modified the file, but mainline merge X used
2341 * \ / "-s ours", so took the version from I. X is
2342 * `-*A--' TREESAME to I and !TREESAME to A.
2344 * Default log from X would produce "I". Without this check,
2345 * --full-history --simplify-merges would produce "I-A-X", showing
2346 * the merge commit X and that it changed A, but not making clear that
2347 * it had just taken the I version. With this check, the topology above
2350 * Note that it is possible that the simplification chooses a different
2351 * TREESAME parent from the default, in which case this test doesn't
2352 * activate, and we _do_ drop the default parent. Example:
2354 * I------X A modified the file, but it was reverted in B,
2355 * \ / meaning mainline merge X is TREESAME to both
2358 * Default log would produce "I" by following the first parent;
2359 * --full-history --simplify-merges will produce "I-A-B". But this is a
2360 * reasonable result - it presents a logical full history leading from
2361 * I to X, and X is not an important merge.
2363 if (!unmarked
&& marked
) {
2364 marked
->object
.flags
&= ~TMP_MARK
;
2371 static int remove_marked_parents(struct rev_info
*revs
, struct commit
*commit
)
2373 struct commit_list
**pp
, *p
;
2374 int nth_parent
, removed
= 0;
2376 pp
= &commit
->parents
;
2378 while ((p
= *pp
) != NULL
) {
2379 struct commit
*parent
= p
->item
;
2380 if (parent
->object
.flags
& TMP_MARK
) {
2381 parent
->object
.flags
&= ~TMP_MARK
;
2385 compact_treesame(revs
, commit
, nth_parent
);
2392 /* Removing parents can only increase TREESAMEness */
2393 if (removed
&& !(commit
->object
.flags
& TREESAME
))
2394 update_treesame(revs
, commit
);
2399 static struct commit_list
**simplify_one(struct rev_info
*revs
, struct commit
*commit
, struct commit_list
**tail
)
2401 struct commit_list
*p
;
2402 struct commit
*parent
;
2403 struct merge_simplify_state
*st
, *pst
;
2406 st
= locate_simplify_state(revs
, commit
);
2409 * Have we handled this one?
2415 * An UNINTERESTING commit simplifies to itself, so does a
2416 * root commit. We do not rewrite parents of such commit
2419 if ((commit
->object
.flags
& UNINTERESTING
) || !commit
->parents
) {
2420 st
->simplified
= commit
;
2425 * Do we know what commit all of our parents that matter
2426 * should be rewritten to? Otherwise we are not ready to
2427 * rewrite this one yet.
2429 for (cnt
= 0, p
= commit
->parents
; p
; p
= p
->next
) {
2430 pst
= locate_simplify_state(revs
, p
->item
);
2431 if (!pst
->simplified
) {
2432 tail
= &commit_list_insert(p
->item
, tail
)->next
;
2435 if (revs
->first_parent_only
)
2439 tail
= &commit_list_insert(commit
, tail
)->next
;
2444 * Rewrite our list of parents. Note that this cannot
2445 * affect our TREESAME flags in any way - a commit is
2446 * always TREESAME to its simplification.
2448 for (p
= commit
->parents
; p
; p
= p
->next
) {
2449 pst
= locate_simplify_state(revs
, p
->item
);
2450 p
->item
= pst
->simplified
;
2451 if (revs
->first_parent_only
)
2455 if (revs
->first_parent_only
)
2458 cnt
= remove_duplicate_parents(revs
, commit
);
2461 * It is possible that we are a merge and one side branch
2462 * does not have any commit that touches the given paths;
2463 * in such a case, the immediate parent from that branch
2464 * will be rewritten to be the merge base.
2466 * o----X X: the commit we are looking at;
2467 * / / o: a commit that touches the paths;
2470 * Further, a merge of an independent branch that doesn't
2471 * touch the path will reduce to a treesame root parent:
2473 * ----o----X X: the commit we are looking at;
2474 * / o: a commit that touches the paths;
2475 * r r: a root commit not touching the paths
2477 * Detect and simplify both cases.
2480 int marked
= mark_redundant_parents(revs
, commit
);
2481 marked
+= mark_treesame_root_parents(revs
, commit
);
2483 marked
-= leave_one_treesame_to_parent(revs
, commit
);
2485 cnt
= remove_marked_parents(revs
, commit
);
2489 * A commit simplifies to itself if it is a root, if it is
2490 * UNINTERESTING, if it touches the given paths, or if it is a
2491 * merge and its parents don't simplify to one relevant commit
2492 * (the first two cases are already handled at the beginning of
2495 * Otherwise, it simplifies to what its sole relevant parent
2499 (commit
->object
.flags
& UNINTERESTING
) ||
2500 !(commit
->object
.flags
& TREESAME
) ||
2501 (parent
= one_relevant_parent(revs
, commit
->parents
)) == NULL
)
2502 st
->simplified
= commit
;
2504 pst
= locate_simplify_state(revs
, parent
);
2505 st
->simplified
= pst
->simplified
;
2510 static void simplify_merges(struct rev_info
*revs
)
2512 struct commit_list
*list
, *next
;
2513 struct commit_list
*yet_to_do
, **tail
;
2514 struct commit
*commit
;
2519 /* feed the list reversed */
2521 for (list
= revs
->commits
; list
; list
= next
) {
2522 commit
= list
->item
;
2525 * Do not free(list) here yet; the original list
2526 * is used later in this function.
2528 commit_list_insert(commit
, &yet_to_do
);
2535 commit
= list
->item
;
2539 tail
= simplify_one(revs
, commit
, tail
);
2543 /* clean up the result, removing the simplified ones */
2544 list
= revs
->commits
;
2545 revs
->commits
= NULL
;
2546 tail
= &revs
->commits
;
2548 struct merge_simplify_state
*st
;
2550 commit
= list
->item
;
2554 st
= locate_simplify_state(revs
, commit
);
2555 if (st
->simplified
== commit
)
2556 tail
= &commit_list_insert(commit
, tail
)->next
;
2560 static void set_children(struct rev_info
*revs
)
2562 struct commit_list
*l
;
2563 for (l
= revs
->commits
; l
; l
= l
->next
) {
2564 struct commit
*commit
= l
->item
;
2565 struct commit_list
*p
;
2567 for (p
= commit
->parents
; p
; p
= p
->next
)
2568 add_child(revs
, p
->item
, commit
);
2572 void reset_revision_walk(void)
2574 clear_object_flags(SEEN
| ADDED
| SHOWN
);
2577 int prepare_revision_walk(struct rev_info
*revs
)
2579 int nr
= revs
->pending
.nr
;
2580 struct object_array_entry
*e
, *list
;
2581 struct commit_list
**next
= &revs
->commits
;
2583 e
= list
= revs
->pending
.objects
;
2584 revs
->pending
.nr
= 0;
2585 revs
->pending
.alloc
= 0;
2586 revs
->pending
.objects
= NULL
;
2588 struct commit
*commit
= handle_commit(revs
, e
->item
, e
->name
);
2590 if (!(commit
->object
.flags
& SEEN
)) {
2591 commit
->object
.flags
|= SEEN
;
2592 next
= commit_list_append(commit
, next
);
2597 if (!revs
->leak_pending
)
2600 /* Signal whether we need per-parent treesame decoration */
2601 if (revs
->simplify_merges
||
2602 (revs
->limited
&& limiting_can_increase_treesame(revs
)))
2603 revs
->treesame
.name
= "treesame";
2605 if (revs
->no_walk
!= REVISION_WALK_NO_WALK_UNSORTED
)
2606 commit_list_sort_by_date(&revs
->commits
);
2610 if (limit_list(revs
) < 0)
2612 if (revs
->topo_order
)
2613 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
2614 if (revs
->line_level_traverse
)
2615 line_log_filter(revs
);
2616 if (revs
->simplify_merges
)
2617 simplify_merges(revs
);
2618 if (revs
->children
.name
)
2623 static enum rewrite_result
rewrite_one(struct rev_info
*revs
, struct commit
**pp
)
2625 struct commit_list
*cache
= NULL
;
2628 struct commit
*p
= *pp
;
2630 if (add_parents_to_list(revs
, p
, &revs
->commits
, &cache
) < 0)
2631 return rewrite_one_error
;
2632 if (p
->object
.flags
& UNINTERESTING
)
2633 return rewrite_one_ok
;
2634 if (!(p
->object
.flags
& TREESAME
))
2635 return rewrite_one_ok
;
2637 return rewrite_one_noparents
;
2638 if ((p
= one_relevant_parent(revs
, p
->parents
)) == NULL
)
2639 return rewrite_one_ok
;
2644 int rewrite_parents(struct rev_info
*revs
, struct commit
*commit
,
2645 rewrite_parent_fn_t rewrite_parent
)
2647 struct commit_list
**pp
= &commit
->parents
;
2649 struct commit_list
*parent
= *pp
;
2650 switch (rewrite_parent(revs
, &parent
->item
)) {
2651 case rewrite_one_ok
:
2653 case rewrite_one_noparents
:
2656 case rewrite_one_error
:
2661 remove_duplicate_parents(revs
, commit
);
2665 static int commit_rewrite_person(struct strbuf
*buf
, const char *what
, struct string_list
*mailmap
)
2667 char *person
, *endp
;
2668 size_t len
, namelen
, maillen
;
2671 struct ident_split ident
;
2673 person
= strstr(buf
->buf
, what
);
2677 person
+= strlen(what
);
2678 endp
= strchr(person
, '\n');
2682 len
= endp
- person
;
2684 if (split_ident_line(&ident
, person
, len
))
2687 mail
= ident
.mail_begin
;
2688 maillen
= ident
.mail_end
- ident
.mail_begin
;
2689 name
= ident
.name_begin
;
2690 namelen
= ident
.name_end
- ident
.name_begin
;
2692 if (map_user(mailmap
, &mail
, &maillen
, &name
, &namelen
)) {
2693 struct strbuf namemail
= STRBUF_INIT
;
2695 strbuf_addf(&namemail
, "%.*s <%.*s>",
2696 (int)namelen
, name
, (int)maillen
, mail
);
2698 strbuf_splice(buf
, ident
.name_begin
- buf
->buf
,
2699 ident
.mail_end
- ident
.name_begin
+ 1,
2700 namemail
.buf
, namemail
.len
);
2702 strbuf_release(&namemail
);
2710 static int commit_match(struct commit
*commit
, struct rev_info
*opt
)
2713 const char *encoding
;
2715 struct strbuf buf
= STRBUF_INIT
;
2717 if (!opt
->grep_filter
.pattern_list
&& !opt
->grep_filter
.header_list
)
2720 /* Prepend "fake" headers as needed */
2721 if (opt
->grep_filter
.use_reflog_filter
) {
2722 strbuf_addstr(&buf
, "reflog ");
2723 get_reflog_message(&buf
, opt
->reflog_info
);
2724 strbuf_addch(&buf
, '\n');
2728 * We grep in the user's output encoding, under the assumption that it
2729 * is the encoding they are most likely to write their grep pattern
2730 * for. In addition, it means we will match the "notes" encoding below,
2731 * so we will not end up with a buffer that has two different encodings
2734 encoding
= get_log_output_encoding();
2735 message
= logmsg_reencode(commit
, NULL
, encoding
);
2737 /* Copy the commit to temporary if we are using "fake" headers */
2739 strbuf_addstr(&buf
, message
);
2741 if (opt
->grep_filter
.header_list
&& opt
->mailmap
) {
2743 strbuf_addstr(&buf
, message
);
2745 commit_rewrite_person(&buf
, "\nauthor ", opt
->mailmap
);
2746 commit_rewrite_person(&buf
, "\ncommitter ", opt
->mailmap
);
2749 /* Append "fake" message parts as needed */
2750 if (opt
->show_notes
) {
2752 strbuf_addstr(&buf
, message
);
2753 format_display_notes(commit
->object
.sha1
, &buf
, encoding
, 1);
2756 /* Find either in the original commit message, or in the temporary */
2758 retval
= grep_buffer(&opt
->grep_filter
, buf
.buf
, buf
.len
);
2760 retval
= grep_buffer(&opt
->grep_filter
,
2761 message
, strlen(message
));
2762 strbuf_release(&buf
);
2763 logmsg_free(message
, commit
);
2767 static inline int want_ancestry(const struct rev_info
*revs
)
2769 return (revs
->rewrite_parents
|| revs
->children
.name
);
2772 enum commit_action
get_commit_action(struct rev_info
*revs
, struct commit
*commit
)
2774 if (commit
->object
.flags
& SHOWN
)
2775 return commit_ignore
;
2776 if (revs
->unpacked
&& has_sha1_pack(commit
->object
.sha1
))
2777 return commit_ignore
;
2780 if (commit
->object
.flags
& UNINTERESTING
)
2781 return commit_ignore
;
2782 if (revs
->min_age
!= -1 && (commit
->date
> revs
->min_age
))
2783 return commit_ignore
;
2784 if (revs
->min_parents
|| (revs
->max_parents
>= 0)) {
2785 int n
= commit_list_count(commit
->parents
);
2786 if ((n
< revs
->min_parents
) ||
2787 ((revs
->max_parents
>= 0) && (n
> revs
->max_parents
)))
2788 return commit_ignore
;
2790 if (!commit_match(commit
, revs
))
2791 return commit_ignore
;
2792 if (revs
->prune
&& revs
->dense
) {
2793 /* Commit without changes? */
2794 if (commit
->object
.flags
& TREESAME
) {
2796 struct commit_list
*p
;
2797 /* drop merges unless we want parenthood */
2798 if (!want_ancestry(revs
))
2799 return commit_ignore
;
2801 * If we want ancestry, then need to keep any merges
2802 * between relevant commits to tie together topology.
2803 * For consistency with TREESAME and simplification
2804 * use "relevant" here rather than just INTERESTING,
2805 * to treat bottom commit(s) as part of the topology.
2807 for (n
= 0, p
= commit
->parents
; p
; p
= p
->next
)
2808 if (relevant_commit(p
->item
))
2811 return commit_ignore
;
2817 enum commit_action
simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
2819 enum commit_action action
= get_commit_action(revs
, commit
);
2821 if (action
== commit_show
&&
2823 revs
->prune
&& revs
->dense
&& want_ancestry(revs
)) {
2825 * --full-diff on simplified parents is no good: it
2826 * will show spurious changes from the commits that
2827 * were elided. So we save the parents on the side
2828 * when --full-diff is in effect.
2830 if (revs
->full_diff
)
2831 save_parents(revs
, commit
);
2832 if (rewrite_parents(revs
, commit
, rewrite_one
) < 0)
2833 return commit_error
;
2838 static struct commit
*get_revision_1(struct rev_info
*revs
)
2844 struct commit_list
*entry
= revs
->commits
;
2845 struct commit
*commit
= entry
->item
;
2847 revs
->commits
= entry
->next
;
2850 if (revs
->reflog_info
) {
2851 save_parents(revs
, commit
);
2852 fake_reflog_parent(revs
->reflog_info
, commit
);
2853 commit
->object
.flags
&= ~(ADDED
| SEEN
| SHOWN
);
2857 * If we haven't done the list limiting, we need to look at
2858 * the parents here. We also need to do the date-based limiting
2859 * that we'd otherwise have done in limit_list().
2861 if (!revs
->limited
) {
2862 if (revs
->max_age
!= -1 &&
2863 (commit
->date
< revs
->max_age
))
2865 if (add_parents_to_list(revs
, commit
, &revs
->commits
, NULL
) < 0)
2866 die("Failed to traverse parents of commit %s",
2867 sha1_to_hex(commit
->object
.sha1
));
2870 switch (simplify_commit(revs
, commit
)) {
2874 die("Failed to simplify parents of commit %s",
2875 sha1_to_hex(commit
->object
.sha1
));
2879 } while (revs
->commits
);
2884 * Return true for entries that have not yet been shown. (This is an
2885 * object_array_each_func_t.)
2887 static int entry_unshown(struct object_array_entry
*entry
, void *cb_data_unused
)
2889 return !(entry
->item
->flags
& SHOWN
);
2893 * If array is on the verge of a realloc, garbage-collect any entries
2894 * that have already been shown to try to free up some space.
2896 static void gc_boundary(struct object_array
*array
)
2898 if (array
->nr
== array
->alloc
)
2899 object_array_filter(array
, entry_unshown
, NULL
);
2902 static void create_boundary_commit_list(struct rev_info
*revs
)
2906 struct object_array
*array
= &revs
->boundary_commits
;
2907 struct object_array_entry
*objects
= array
->objects
;
2910 * If revs->commits is non-NULL at this point, an error occurred in
2911 * get_revision_1(). Ignore the error and continue printing the
2912 * boundary commits anyway. (This is what the code has always
2915 if (revs
->commits
) {
2916 free_commit_list(revs
->commits
);
2917 revs
->commits
= NULL
;
2921 * Put all of the actual boundary commits from revs->boundary_commits
2922 * into revs->commits
2924 for (i
= 0; i
< array
->nr
; i
++) {
2925 c
= (struct commit
*)(objects
[i
].item
);
2928 if (!(c
->object
.flags
& CHILD_SHOWN
))
2930 if (c
->object
.flags
& (SHOWN
| BOUNDARY
))
2932 c
->object
.flags
|= BOUNDARY
;
2933 commit_list_insert(c
, &revs
->commits
);
2937 * If revs->topo_order is set, sort the boundary commits
2938 * in topological order
2940 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
2943 static struct commit
*get_revision_internal(struct rev_info
*revs
)
2945 struct commit
*c
= NULL
;
2946 struct commit_list
*l
;
2948 if (revs
->boundary
== 2) {
2950 * All of the normal commits have already been returned,
2951 * and we are now returning boundary commits.
2952 * create_boundary_commit_list() has populated
2953 * revs->commits with the remaining commits to return.
2955 c
= pop_commit(&revs
->commits
);
2957 c
->object
.flags
|= SHOWN
;
2962 * If our max_count counter has reached zero, then we are done. We
2963 * don't simply return NULL because we still might need to show
2964 * boundary commits. But we want to avoid calling get_revision_1, which
2965 * might do a considerable amount of work finding the next commit only
2966 * for us to throw it away.
2968 * If it is non-zero, then either we don't have a max_count at all
2969 * (-1), or it is still counting, in which case we decrement.
2971 if (revs
->max_count
) {
2972 c
= get_revision_1(revs
);
2974 while (0 < revs
->skip_count
) {
2976 c
= get_revision_1(revs
);
2982 if (revs
->max_count
> 0)
2987 c
->object
.flags
|= SHOWN
;
2989 if (!revs
->boundary
) {
2995 * get_revision_1() runs out the commits, and
2996 * we are done computing the boundaries.
2997 * switch to boundary commits output mode.
3002 * Update revs->commits to contain the list of
3005 create_boundary_commit_list(revs
);
3007 return get_revision_internal(revs
);
3011 * boundary commits are the commits that are parents of the
3012 * ones we got from get_revision_1() but they themselves are
3013 * not returned from get_revision_1(). Before returning
3014 * 'c', we need to mark its parents that they could be boundaries.
3017 for (l
= c
->parents
; l
; l
= l
->next
) {
3019 p
= &(l
->item
->object
);
3020 if (p
->flags
& (CHILD_SHOWN
| SHOWN
))
3022 p
->flags
|= CHILD_SHOWN
;
3023 gc_boundary(&revs
->boundary_commits
);
3024 add_object_array(p
, NULL
, &revs
->boundary_commits
);
3030 struct commit
*get_revision(struct rev_info
*revs
)
3033 struct commit_list
*reversed
;
3035 if (revs
->reverse
) {
3037 while ((c
= get_revision_internal(revs
))) {
3038 commit_list_insert(c
, &reversed
);
3040 revs
->commits
= reversed
;
3042 revs
->reverse_output_stage
= 1;
3045 if (revs
->reverse_output_stage
)
3046 return pop_commit(&revs
->commits
);
3048 c
= get_revision_internal(revs
);
3049 if (c
&& revs
->graph
)
3050 graph_update(revs
->graph
, c
);
3052 free_saved_parents(revs
);
3056 char *get_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
3058 if (commit
->object
.flags
& BOUNDARY
)
3060 else if (commit
->object
.flags
& UNINTERESTING
)
3062 else if (commit
->object
.flags
& PATCHSAME
)
3064 else if (!revs
|| revs
->left_right
) {
3065 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
3069 } else if (revs
->graph
)
3071 else if (revs
->cherry_mark
)
3076 void put_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
3078 char *mark
= get_revision_mark(revs
, commit
);
3081 fputs(mark
, stdout
);
3085 define_commit_slab(saved_parents
, struct commit_list
*);
3087 #define EMPTY_PARENT_LIST ((struct commit_list *)-1)
3089 void save_parents(struct rev_info
*revs
, struct commit
*commit
)
3091 struct commit_list
**pp
;
3093 if (!revs
->saved_parents_slab
) {
3094 revs
->saved_parents_slab
= xmalloc(sizeof(struct saved_parents
));
3095 init_saved_parents(revs
->saved_parents_slab
);
3098 pp
= saved_parents_at(revs
->saved_parents_slab
, commit
);
3101 * When walking with reflogs, we may visit the same commit
3102 * several times: once for each appearance in the reflog.
3104 * In this case, save_parents() will be called multiple times.
3105 * We want to keep only the first set of parents. We need to
3106 * store a sentinel value for an empty (i.e., NULL) parent
3107 * list to distinguish it from a not-yet-saved list, however.
3111 if (commit
->parents
)
3112 *pp
= copy_commit_list(commit
->parents
);
3114 *pp
= EMPTY_PARENT_LIST
;
3117 struct commit_list
*get_saved_parents(struct rev_info
*revs
, const struct commit
*commit
)
3119 struct commit_list
*parents
;
3121 if (!revs
->saved_parents_slab
)
3122 return commit
->parents
;
3124 parents
= *saved_parents_at(revs
->saved_parents_slab
, commit
);
3125 if (parents
== EMPTY_PARENT_LIST
)
3130 void free_saved_parents(struct rev_info
*revs
)
3132 if (revs
->saved_parents_slab
)
3133 clear_saved_parents(revs
->saved_parents_slab
);