1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
4 #include "git-compat-util.h"
6 #include "environment.h"
9 #include "object-name.h"
10 #include "object-file.h"
18 #include "diff-merges.h"
21 #include "repository.h"
24 #include "reflog-walk.h"
25 #include "patch-ids.h"
27 #include "string-list.h"
30 #include "commit-slab.h"
31 #include "cache-tree.h"
36 #include "read-cache.h"
38 #include "sparse-index.h"
41 #include "commit-reach.h"
42 #include "commit-graph.h"
43 #include "prio-queue.h"
47 #include "json-writer.h"
48 #include "list-objects-filter-options.h"
49 #include "resolve-undo.h"
50 #include "parse-options.h"
51 #include "wildmatch.h"
53 static char *term_bad
;
54 static char *term_good
;
56 implement_shared_commit_slab(revision_sources
, char *);
58 static inline int want_ancestry(const struct rev_info
*revs
);
60 static void mark_blob_uninteresting(struct blob
*blob
)
64 if (blob
->object
.flags
& UNINTERESTING
)
66 blob
->object
.flags
|= UNINTERESTING
;
69 static void mark_tree_contents_uninteresting(struct repository
*r
,
72 struct tree_desc desc
;
73 struct name_entry entry
;
75 if (parse_tree_gently(tree
, 1) < 0)
78 init_tree_desc(&desc
, &tree
->object
.oid
, tree
->buffer
, tree
->size
);
79 while (tree_entry(&desc
, &entry
)) {
80 switch (object_type(entry
.mode
)) {
82 mark_tree_uninteresting(r
, lookup_tree(r
, &entry
.oid
));
85 mark_blob_uninteresting(lookup_blob(r
, &entry
.oid
));
88 /* Subproject commit - not in this repository */
94 * We don't care about the tree any more
95 * after it has been marked uninteresting.
97 free_tree_buffer(tree
);
100 void mark_tree_uninteresting(struct repository
*r
, struct tree
*tree
)
108 if (obj
->flags
& UNINTERESTING
)
110 obj
->flags
|= UNINTERESTING
;
111 mark_tree_contents_uninteresting(r
, tree
);
114 struct path_and_oids_entry
{
115 struct hashmap_entry ent
;
120 static int path_and_oids_cmp(const void *hashmap_cmp_fn_data UNUSED
,
121 const struct hashmap_entry
*eptr
,
122 const struct hashmap_entry
*entry_or_key
,
123 const void *keydata UNUSED
)
125 const struct path_and_oids_entry
*e1
, *e2
;
127 e1
= container_of(eptr
, const struct path_and_oids_entry
, ent
);
128 e2
= container_of(entry_or_key
, const struct path_and_oids_entry
, ent
);
130 return strcmp(e1
->path
, e2
->path
);
133 static void paths_and_oids_clear(struct hashmap
*map
)
135 struct hashmap_iter iter
;
136 struct path_and_oids_entry
*entry
;
138 hashmap_for_each_entry(map
, &iter
, entry
, ent
/* member name */) {
139 oidset_clear(&entry
->trees
);
143 hashmap_clear_and_free(map
, struct path_and_oids_entry
, ent
);
146 static void paths_and_oids_insert(struct hashmap
*map
,
148 const struct object_id
*oid
)
150 int hash
= strhash(path
);
151 struct path_and_oids_entry key
;
152 struct path_and_oids_entry
*entry
;
154 hashmap_entry_init(&key
.ent
, hash
);
156 /* use a shallow copy for the lookup */
157 key
.path
= (char *)path
;
158 oidset_init(&key
.trees
, 0);
160 entry
= hashmap_get_entry(map
, &key
, ent
, NULL
);
162 CALLOC_ARRAY(entry
, 1);
163 hashmap_entry_init(&entry
->ent
, hash
);
164 entry
->path
= xstrdup(key
.path
);
165 oidset_init(&entry
->trees
, 16);
166 hashmap_put(map
, &entry
->ent
);
169 oidset_insert(&entry
->trees
, oid
);
172 static void add_children_by_path(struct repository
*r
,
176 struct tree_desc desc
;
177 struct name_entry entry
;
182 if (parse_tree_gently(tree
, 1) < 0)
185 init_tree_desc(&desc
, &tree
->object
.oid
, tree
->buffer
, tree
->size
);
186 while (tree_entry(&desc
, &entry
)) {
187 switch (object_type(entry
.mode
)) {
189 paths_and_oids_insert(map
, entry
.path
, &entry
.oid
);
191 if (tree
->object
.flags
& UNINTERESTING
) {
192 struct tree
*child
= lookup_tree(r
, &entry
.oid
);
194 child
->object
.flags
|= UNINTERESTING
;
198 if (tree
->object
.flags
& UNINTERESTING
) {
199 struct blob
*child
= lookup_blob(r
, &entry
.oid
);
201 child
->object
.flags
|= UNINTERESTING
;
205 /* Subproject commit - not in this repository */
210 free_tree_buffer(tree
);
213 void mark_trees_uninteresting_sparse(struct repository
*r
,
214 struct oidset
*trees
)
216 unsigned has_interesting
= 0, has_uninteresting
= 0;
217 struct hashmap map
= HASHMAP_INIT(path_and_oids_cmp
, NULL
);
218 struct hashmap_iter map_iter
;
219 struct path_and_oids_entry
*entry
;
220 struct object_id
*oid
;
221 struct oidset_iter iter
;
223 oidset_iter_init(trees
, &iter
);
224 while ((!has_interesting
|| !has_uninteresting
) &&
225 (oid
= oidset_iter_next(&iter
))) {
226 struct tree
*tree
= lookup_tree(r
, oid
);
231 if (tree
->object
.flags
& UNINTERESTING
)
232 has_uninteresting
= 1;
237 /* Do not walk unless we have both types of trees. */
238 if (!has_uninteresting
|| !has_interesting
)
241 oidset_iter_init(trees
, &iter
);
242 while ((oid
= oidset_iter_next(&iter
))) {
243 struct tree
*tree
= lookup_tree(r
, oid
);
244 add_children_by_path(r
, tree
, &map
);
247 hashmap_for_each_entry(&map
, &map_iter
, entry
, ent
/* member name */)
248 mark_trees_uninteresting_sparse(r
, &entry
->trees
);
250 paths_and_oids_clear(&map
);
253 struct commit_stack
{
254 struct commit
**items
;
257 #define COMMIT_STACK_INIT { 0 }
259 static void commit_stack_push(struct commit_stack
*stack
, struct commit
*commit
)
261 ALLOC_GROW(stack
->items
, stack
->nr
+ 1, stack
->alloc
);
262 stack
->items
[stack
->nr
++] = commit
;
265 static struct commit
*commit_stack_pop(struct commit_stack
*stack
)
267 return stack
->nr
? stack
->items
[--stack
->nr
] : NULL
;
270 static void commit_stack_clear(struct commit_stack
*stack
)
272 FREE_AND_NULL(stack
->items
);
273 stack
->nr
= stack
->alloc
= 0;
276 static void mark_one_parent_uninteresting(struct rev_info
*revs
, struct commit
*commit
,
277 struct commit_stack
*pending
)
279 struct commit_list
*l
;
281 if (commit
->object
.flags
& UNINTERESTING
)
283 commit
->object
.flags
|= UNINTERESTING
;
286 * Normally we haven't parsed the parent
287 * yet, so we won't have a parent of a parent
288 * here. However, it may turn out that we've
289 * reached this commit some other way (where it
290 * wasn't uninteresting), in which case we need
291 * to mark its parents recursively too..
293 for (l
= commit
->parents
; l
; l
= l
->next
) {
294 commit_stack_push(pending
, l
->item
);
295 if (revs
&& revs
->exclude_first_parent_only
)
300 void mark_parents_uninteresting(struct rev_info
*revs
, struct commit
*commit
)
302 struct commit_stack pending
= COMMIT_STACK_INIT
;
303 struct commit_list
*l
;
305 for (l
= commit
->parents
; l
; l
= l
->next
) {
306 mark_one_parent_uninteresting(revs
, l
->item
, &pending
);
307 if (revs
&& revs
->exclude_first_parent_only
)
311 while (pending
.nr
> 0)
312 mark_one_parent_uninteresting(revs
, commit_stack_pop(&pending
),
315 commit_stack_clear(&pending
);
318 static void add_pending_object_with_path(struct rev_info
*revs
,
320 const char *name
, unsigned mode
,
323 struct interpret_branch_name_options options
= { 0 };
326 if (revs
->no_walk
&& (obj
->flags
& UNINTERESTING
))
328 if (revs
->reflog_info
&& obj
->type
== OBJ_COMMIT
) {
329 struct strbuf buf
= STRBUF_INIT
;
330 size_t namelen
= strlen(name
);
331 int len
= repo_interpret_branch_name(the_repository
, name
,
332 namelen
, &buf
, &options
);
334 if (0 < len
&& len
< namelen
&& buf
.len
)
335 strbuf_addstr(&buf
, name
+ len
);
336 add_reflog_for_walk(revs
->reflog_info
,
337 (struct commit
*)obj
,
338 buf
.buf
[0] ? buf
.buf
: name
);
339 strbuf_release(&buf
);
340 return; /* do not add the commit itself */
342 add_object_array_with_path(obj
, name
, &revs
->pending
, mode
, path
);
345 static void add_pending_object_with_mode(struct rev_info
*revs
,
347 const char *name
, unsigned mode
)
349 add_pending_object_with_path(revs
, obj
, name
, mode
, NULL
);
352 void add_pending_object(struct rev_info
*revs
,
353 struct object
*obj
, const char *name
)
355 add_pending_object_with_mode(revs
, obj
, name
, S_IFINVALID
);
358 void add_head_to_pending(struct rev_info
*revs
)
360 struct object_id oid
;
362 if (repo_get_oid(the_repository
, "HEAD", &oid
))
364 obj
= parse_object(revs
->repo
, &oid
);
367 add_pending_object(revs
, obj
, "HEAD");
370 static struct object
*get_reference(struct rev_info
*revs
, const char *name
,
371 const struct object_id
*oid
,
374 struct object
*object
;
376 object
= parse_object_with_flags(revs
->repo
, oid
,
377 revs
->verify_objects
? 0 :
378 PARSE_OBJECT_SKIP_HASH_CHECK
|
379 PARSE_OBJECT_DISCARD_TREE
);
382 if (revs
->ignore_missing
)
384 if (revs
->exclude_promisor_objects
&&
385 is_promisor_object(revs
->repo
, oid
))
387 if (revs
->do_not_die_on_missing_objects
) {
388 oidset_insert(&revs
->missing_commits
, oid
);
391 die("bad object %s", name
);
393 object
->flags
|= flags
;
397 void add_pending_oid(struct rev_info
*revs
, const char *name
,
398 const struct object_id
*oid
, unsigned int flags
)
400 struct object
*object
= get_reference(revs
, name
, oid
, flags
);
401 add_pending_object(revs
, object
, name
);
404 static struct commit
*handle_commit(struct rev_info
*revs
,
405 struct object_array_entry
*entry
)
407 struct object
*object
= entry
->item
;
408 const char *name
= entry
->name
;
409 const char *path
= entry
->path
;
410 unsigned int mode
= entry
->mode
;
411 unsigned long flags
= object
->flags
;
414 * Tag object? Look what it points to..
416 while (object
->type
== OBJ_TAG
) {
417 struct tag
*tag
= (struct tag
*) object
;
418 struct object_id
*oid
;
419 if (revs
->tag_objects
&& !(flags
& UNINTERESTING
))
420 add_pending_object(revs
, object
, tag
->tag
);
421 oid
= get_tagged_oid(tag
);
422 object
= parse_object(revs
->repo
, oid
);
424 if (revs
->ignore_missing_links
|| (flags
& UNINTERESTING
))
426 if (revs
->exclude_promisor_objects
&&
427 is_promisor_object(revs
->repo
, &tag
->tagged
->oid
))
429 if (revs
->do_not_die_on_missing_objects
&& oid
) {
430 oidset_insert(&revs
->missing_commits
, oid
);
433 die("bad object %s", oid_to_hex(&tag
->tagged
->oid
));
435 object
->flags
|= flags
;
437 * We'll handle the tagged object by looping or dropping
438 * through to the non-tag handlers below. Do not
439 * propagate path data from the tag's pending entry.
446 * Commit object? Just return it, we'll do all the complex
449 if (object
->type
== OBJ_COMMIT
) {
450 struct commit
*commit
= (struct commit
*)object
;
452 if (repo_parse_commit(revs
->repo
, commit
) < 0)
453 die("unable to parse commit %s", name
);
454 if (flags
& UNINTERESTING
) {
455 mark_parents_uninteresting(revs
, commit
);
457 if (!revs
->topo_order
|| !generation_numbers_enabled(the_repository
))
461 char **slot
= revision_sources_at(revs
->sources
, commit
);
464 *slot
= xstrdup(name
);
470 * Tree object? Either mark it uninteresting, or add it
471 * to the list of objects to look at later..
473 if (object
->type
== OBJ_TREE
) {
474 struct tree
*tree
= (struct tree
*)object
;
475 if (!revs
->tree_objects
)
477 if (flags
& UNINTERESTING
) {
478 mark_tree_contents_uninteresting(revs
->repo
, tree
);
481 add_pending_object_with_path(revs
, object
, name
, mode
, path
);
486 * Blob object? You know the drill by now..
488 if (object
->type
== OBJ_BLOB
) {
489 if (!revs
->blob_objects
)
491 if (flags
& UNINTERESTING
)
493 add_pending_object_with_path(revs
, object
, name
, mode
, path
);
496 die("%s is unknown object", name
);
499 static int everybody_uninteresting(struct commit_list
*orig
,
500 struct commit
**interesting_cache
)
502 struct commit_list
*list
= orig
;
504 if (*interesting_cache
) {
505 struct commit
*commit
= *interesting_cache
;
506 if (!(commit
->object
.flags
& UNINTERESTING
))
511 struct commit
*commit
= list
->item
;
513 if (commit
->object
.flags
& UNINTERESTING
)
516 *interesting_cache
= commit
;
523 * A definition of "relevant" commit that we can use to simplify limited graphs
524 * by eliminating side branches.
526 * A "relevant" commit is one that is !UNINTERESTING (ie we are including it
527 * in our list), or that is a specified BOTTOM commit. Then after computing
528 * a limited list, during processing we can generally ignore boundary merges
529 * coming from outside the graph, (ie from irrelevant parents), and treat
530 * those merges as if they were single-parent. TREESAME is defined to consider
531 * only relevant parents, if any. If we are TREESAME to our on-graph parents,
532 * we don't care if we were !TREESAME to non-graph parents.
534 * Treating bottom commits as relevant ensures that a limited graph's
535 * connection to the actual bottom commit is not viewed as a side branch, but
536 * treated as part of the graph. For example:
538 * ....Z...A---X---o---o---B
542 * When computing "A..B", the A-X connection is at least as important as
543 * Y-X, despite A being flagged UNINTERESTING.
545 * And when computing --ancestry-path "A..B", the A-X connection is more
546 * important than Y-X, despite both A and Y being flagged UNINTERESTING.
548 static inline int relevant_commit(struct commit
*commit
)
550 return (commit
->object
.flags
& (UNINTERESTING
| BOTTOM
)) != UNINTERESTING
;
554 * Return a single relevant commit from a parent list. If we are a TREESAME
555 * commit, and this selects one of our parents, then we can safely simplify to
558 static struct commit
*one_relevant_parent(const struct rev_info
*revs
,
559 struct commit_list
*orig
)
561 struct commit_list
*list
= orig
;
562 struct commit
*relevant
= NULL
;
568 * For 1-parent commits, or if first-parent-only, then return that
569 * first parent (even if not "relevant" by the above definition).
570 * TREESAME will have been set purely on that parent.
572 if (revs
->first_parent_only
|| !orig
->next
)
576 * For multi-parent commits, identify a sole relevant parent, if any.
577 * If we have only one relevant parent, then TREESAME will be set purely
578 * with regard to that parent, and we can simplify accordingly.
580 * If we have more than one relevant parent, or no relevant parents
581 * (and multiple irrelevant ones), then we can't select a parent here
585 struct commit
*commit
= list
->item
;
587 if (relevant_commit(commit
)) {
597 * The goal is to get REV_TREE_NEW as the result only if the
598 * diff consists of all '+' (and no other changes), REV_TREE_OLD
599 * if the whole diff is removal of old data, and otherwise
600 * REV_TREE_DIFFERENT (of course if the trees are the same we
601 * want REV_TREE_SAME).
603 * The only time we care about the distinction is when
604 * remove_empty_trees is in effect, in which case we care only about
605 * whether the whole change is REV_TREE_NEW, or if there's another type
606 * of change. Which means we can stop the diff early in either of these
609 * 1. We're not using remove_empty_trees at all.
611 * 2. We saw anything except REV_TREE_NEW.
613 #define REV_TREE_SAME 0
614 #define REV_TREE_NEW 1 /* Only new files */
615 #define REV_TREE_OLD 2 /* Only files removed */
616 #define REV_TREE_DIFFERENT 3 /* Mixed changes */
617 static int tree_difference
= REV_TREE_SAME
;
619 static void file_add_remove(struct diff_options
*options
,
621 unsigned mode UNUSED
,
622 const struct object_id
*oid UNUSED
,
623 int oid_valid UNUSED
,
624 const char *fullpath UNUSED
,
625 unsigned dirty_submodule UNUSED
)
627 int diff
= addremove
== '+' ? REV_TREE_NEW
: REV_TREE_OLD
;
628 struct rev_info
*revs
= options
->change_fn_data
;
630 tree_difference
|= diff
;
631 if (!revs
->remove_empty_trees
|| tree_difference
!= REV_TREE_NEW
)
632 options
->flags
.has_changes
= 1;
635 static void file_change(struct diff_options
*options
,
636 unsigned old_mode UNUSED
,
637 unsigned new_mode UNUSED
,
638 const struct object_id
*old_oid UNUSED
,
639 const struct object_id
*new_oid UNUSED
,
640 int old_oid_valid UNUSED
,
641 int new_oid_valid UNUSED
,
642 const char *fullpath UNUSED
,
643 unsigned old_dirty_submodule UNUSED
,
644 unsigned new_dirty_submodule UNUSED
)
646 tree_difference
= REV_TREE_DIFFERENT
;
647 options
->flags
.has_changes
= 1;
650 static int bloom_filter_atexit_registered
;
651 static unsigned int count_bloom_filter_maybe
;
652 static unsigned int count_bloom_filter_definitely_not
;
653 static unsigned int count_bloom_filter_false_positive
;
654 static unsigned int count_bloom_filter_not_present
;
656 static void trace2_bloom_filter_statistics_atexit(void)
658 struct json_writer jw
= JSON_WRITER_INIT
;
660 jw_object_begin(&jw
, 0);
661 jw_object_intmax(&jw
, "filter_not_present", count_bloom_filter_not_present
);
662 jw_object_intmax(&jw
, "maybe", count_bloom_filter_maybe
);
663 jw_object_intmax(&jw
, "definitely_not", count_bloom_filter_definitely_not
);
664 jw_object_intmax(&jw
, "false_positive", count_bloom_filter_false_positive
);
667 trace2_data_json("bloom", the_repository
, "statistics", &jw
);
672 static int forbid_bloom_filters(struct pathspec
*spec
)
674 unsigned int allowed_magic
=
681 if (spec
->magic
& ~allowed_magic
)
683 for (size_t nr
= 0; nr
< spec
->nr
; nr
++)
684 if (spec
->items
[nr
].magic
& ~allowed_magic
)
690 static void release_revisions_bloom_keyvecs(struct rev_info
*revs
);
692 static int convert_pathspec_to_bloom_keyvec(struct bloom_keyvec
**out
,
693 const struct pathspec_item
*pi
,
694 const struct bloom_filter_settings
*settings
)
696 char *path_alloc
= NULL
;
701 len
= pi
->nowildcard_len
;
702 if (len
!= pi
->len
) {
704 * for path like "dir/file*", nowildcard part would be
705 * "dir/file", but only "dir" should be used for the
708 while (len
> 0 && pi
->match
[len
- 1] != '/')
711 /* remove single trailing slash from path, if needed */
712 if (len
> 0 && pi
->match
[len
- 1] == '/')
718 if (len
!= pi
->len
) {
719 path_alloc
= xmemdupz(pi
->match
, len
);
724 *out
= bloom_keyvec_new(path
, len
, settings
);
732 static void prepare_to_use_bloom_filter(struct rev_info
*revs
)
737 if (forbid_bloom_filters(&revs
->prune_data
))
740 repo_parse_commit(revs
->repo
, revs
->commits
->item
);
742 revs
->bloom_filter_settings
= get_bloom_filter_settings(revs
->repo
);
743 if (!revs
->bloom_filter_settings
)
746 if (!revs
->pruning
.pathspec
.nr
)
749 revs
->bloom_keyvecs_nr
= revs
->pruning
.pathspec
.nr
;
750 CALLOC_ARRAY(revs
->bloom_keyvecs
, revs
->bloom_keyvecs_nr
);
752 for (int i
= 0; i
< revs
->pruning
.pathspec
.nr
; i
++) {
753 if (convert_pathspec_to_bloom_keyvec(&revs
->bloom_keyvecs
[i
],
754 &revs
->pruning
.pathspec
.items
[i
],
755 revs
->bloom_filter_settings
))
759 if (trace2_is_enabled() && !bloom_filter_atexit_registered
) {
760 atexit(trace2_bloom_filter_statistics_atexit
);
761 bloom_filter_atexit_registered
= 1;
767 revs
->bloom_filter_settings
= NULL
;
768 release_revisions_bloom_keyvecs(revs
);
771 static int check_maybe_different_in_bloom_filter(struct rev_info
*revs
,
772 struct commit
*commit
)
774 struct bloom_filter
*filter
;
777 if (!revs
->repo
->objects
->commit_graph
)
780 if (commit_graph_generation(commit
) == GENERATION_NUMBER_INFINITY
)
783 filter
= get_bloom_filter(revs
->repo
, commit
);
786 count_bloom_filter_not_present
++;
790 for (size_t nr
= 0; !result
&& nr
< revs
->bloom_keyvecs_nr
; nr
++) {
791 result
= bloom_filter_contains_vec(filter
,
792 revs
->bloom_keyvecs
[nr
],
793 revs
->bloom_filter_settings
);
797 count_bloom_filter_maybe
++;
799 count_bloom_filter_definitely_not
++;
804 static int rev_compare_tree(struct rev_info
*revs
,
805 struct commit
*parent
, struct commit
*commit
, int nth_parent
)
807 struct tree
*t1
= repo_get_commit_tree(the_repository
, parent
);
808 struct tree
*t2
= repo_get_commit_tree(the_repository
, commit
);
816 if (revs
->simplify_by_decoration
) {
818 * If we are simplifying by decoration, then the commit
819 * is worth showing if it has a tag pointing at it.
821 if (get_name_decoration(&commit
->object
))
822 return REV_TREE_DIFFERENT
;
824 * A commit that is not pointed by a tag is uninteresting
825 * if we are not limited by path. This means that you will
826 * see the usual "commits that touch the paths" plus any
827 * tagged commit by specifying both --simplify-by-decoration
830 if (!revs
->prune_data
.nr
)
831 return REV_TREE_SAME
;
834 if (revs
->bloom_keyvecs_nr
&& !nth_parent
) {
835 bloom_ret
= check_maybe_different_in_bloom_filter(revs
, commit
);
838 return REV_TREE_SAME
;
841 tree_difference
= REV_TREE_SAME
;
842 revs
->pruning
.flags
.has_changes
= 0;
843 diff_tree_oid(&t1
->object
.oid
, &t2
->object
.oid
, "", &revs
->pruning
);
846 if (bloom_ret
== 1 && tree_difference
== REV_TREE_SAME
)
847 count_bloom_filter_false_positive
++;
849 return tree_difference
;
852 static int rev_same_tree_as_empty(struct rev_info
*revs
, struct commit
*commit
,
855 struct tree
*t1
= repo_get_commit_tree(the_repository
, commit
);
861 if (!nth_parent
&& revs
->bloom_keyvecs_nr
) {
862 bloom_ret
= check_maybe_different_in_bloom_filter(revs
, commit
);
867 tree_difference
= REV_TREE_SAME
;
868 revs
->pruning
.flags
.has_changes
= 0;
869 diff_tree_oid(NULL
, &t1
->object
.oid
, "", &revs
->pruning
);
871 if (bloom_ret
== 1 && tree_difference
== REV_TREE_SAME
)
872 count_bloom_filter_false_positive
++;
874 return tree_difference
== REV_TREE_SAME
;
877 struct treesame_state
{
878 unsigned int nparents
;
879 unsigned char treesame
[FLEX_ARRAY
];
882 static struct treesame_state
*initialise_treesame(struct rev_info
*revs
, struct commit
*commit
)
884 unsigned n
= commit_list_count(commit
->parents
);
885 struct treesame_state
*st
= xcalloc(1, st_add(sizeof(*st
), n
));
887 add_decoration(&revs
->treesame
, &commit
->object
, st
);
892 * Must be called immediately after removing the nth_parent from a commit's
893 * parent list, if we are maintaining the per-parent treesame[] decoration.
894 * This does not recalculate the master TREESAME flag - update_treesame()
895 * should be called to update it after a sequence of treesame[] modifications
896 * that may have affected it.
898 static int compact_treesame(struct rev_info
*revs
, struct commit
*commit
, unsigned nth_parent
)
900 struct treesame_state
*st
;
903 if (!commit
->parents
) {
905 * Have just removed the only parent from a non-merge.
906 * Different handling, as we lack decoration.
909 die("compact_treesame %u", nth_parent
);
910 old_same
= !!(commit
->object
.flags
& TREESAME
);
911 if (rev_same_tree_as_empty(revs
, commit
, nth_parent
))
912 commit
->object
.flags
|= TREESAME
;
914 commit
->object
.flags
&= ~TREESAME
;
918 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
919 if (!st
|| nth_parent
>= st
->nparents
)
920 die("compact_treesame %u", nth_parent
);
922 old_same
= st
->treesame
[nth_parent
];
923 memmove(st
->treesame
+ nth_parent
,
924 st
->treesame
+ nth_parent
+ 1,
925 st
->nparents
- nth_parent
- 1);
928 * If we've just become a non-merge commit, update TREESAME
929 * immediately, and remove the no-longer-needed decoration.
930 * If still a merge, defer update until update_treesame().
932 if (--st
->nparents
== 1) {
933 if (commit
->parents
->next
)
934 die("compact_treesame parents mismatch");
935 if (st
->treesame
[0] && revs
->dense
)
936 commit
->object
.flags
|= TREESAME
;
938 commit
->object
.flags
&= ~TREESAME
;
939 free(add_decoration(&revs
->treesame
, &commit
->object
, NULL
));
945 static unsigned update_treesame(struct rev_info
*revs
, struct commit
*commit
)
947 if (commit
->parents
&& commit
->parents
->next
) {
949 struct treesame_state
*st
;
950 struct commit_list
*p
;
951 unsigned relevant_parents
;
952 unsigned relevant_change
, irrelevant_change
;
954 st
= lookup_decoration(&revs
->treesame
, &commit
->object
);
956 die("update_treesame %s", oid_to_hex(&commit
->object
.oid
));
957 relevant_parents
= 0;
958 relevant_change
= irrelevant_change
= 0;
959 for (p
= commit
->parents
, n
= 0; p
; n
++, p
= p
->next
) {
960 if (relevant_commit(p
->item
)) {
961 relevant_change
|= !st
->treesame
[n
];
964 irrelevant_change
|= !st
->treesame
[n
];
966 if (relevant_parents
? relevant_change
: irrelevant_change
)
967 commit
->object
.flags
&= ~TREESAME
;
969 commit
->object
.flags
|= TREESAME
;
972 return commit
->object
.flags
& TREESAME
;
975 static inline int limiting_can_increase_treesame(const struct rev_info
*revs
)
978 * TREESAME is irrelevant unless prune && dense;
979 * if simplify_history is set, we can't have a mixture of TREESAME and
980 * !TREESAME INTERESTING parents (and we don't have treesame[]
981 * decoration anyway);
982 * if first_parent_only is set, then the TREESAME flag is locked
983 * against the first parent (and again we lack treesame[] decoration).
985 return revs
->prune
&& revs
->dense
&&
986 !revs
->simplify_history
&&
987 !revs
->first_parent_only
;
990 static void try_to_simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
992 struct commit_list
**pp
, *parent
;
993 struct treesame_state
*ts
= NULL
;
994 int relevant_change
= 0, irrelevant_change
= 0;
995 int relevant_parents
, nth_parent
;
998 * If we don't do pruning, everything is interesting
1003 if (!repo_get_commit_tree(the_repository
, commit
))
1006 if (!commit
->parents
) {
1008 * Pretend as if we are comparing ourselves to the
1009 * (non-existent) first parent of this commit object. Even
1010 * though no such parent exists, its changed-path Bloom filter
1011 * (if one exists) is relative to the empty tree, using Bloom
1012 * filters is allowed here.
1014 if (rev_same_tree_as_empty(revs
, commit
, 0))
1015 commit
->object
.flags
|= TREESAME
;
1020 * Normal non-merge commit? If we don't want to make the
1021 * history dense, we consider it always to be a change..
1023 if (!revs
->dense
&& !commit
->parents
->next
)
1026 for (pp
= &commit
->parents
, nth_parent
= 0, relevant_parents
= 0;
1027 (parent
= *pp
) != NULL
;
1028 pp
= &parent
->next
, nth_parent
++) {
1029 struct commit
*p
= parent
->item
;
1030 if (relevant_commit(p
))
1033 if (nth_parent
== 1) {
1035 * This our second loop iteration - so we now know
1036 * we're dealing with a merge.
1038 * Do not compare with later parents when we care only about
1039 * the first parent chain, in order to avoid derailing the
1040 * traversal to follow a side branch that brought everything
1041 * in the path we are limited to by the pathspec.
1043 if (revs
->first_parent_only
)
1046 * If this will remain a potentially-simplifiable
1047 * merge, remember per-parent treesame if needed.
1048 * Initialise the array with the comparison from our
1051 if (revs
->treesame
.name
&&
1052 !revs
->simplify_history
&&
1053 !(commit
->object
.flags
& UNINTERESTING
)) {
1054 ts
= initialise_treesame(revs
, commit
);
1055 if (!(irrelevant_change
|| relevant_change
))
1056 ts
->treesame
[0] = 1;
1059 if (repo_parse_commit(revs
->repo
, p
) < 0)
1060 die("cannot simplify commit %s (because of %s)",
1061 oid_to_hex(&commit
->object
.oid
),
1062 oid_to_hex(&p
->object
.oid
));
1063 switch (rev_compare_tree(revs
, p
, commit
, nth_parent
)) {
1065 if (!revs
->simplify_history
|| !relevant_commit(p
)) {
1066 /* Even if a merge with an uninteresting
1067 * side branch brought the entire change
1068 * we are interested in, we do not want
1069 * to lose the other branches of this
1070 * merge, so we just keep going.
1073 ts
->treesame
[nth_parent
] = 1;
1077 free_commit_list(parent
->next
);
1078 parent
->next
= NULL
;
1079 while (commit
->parents
!= parent
)
1080 pop_commit(&commit
->parents
);
1081 commit
->parents
= parent
;
1084 * A merge commit is a "diversion" if it is not
1085 * TREESAME to its first parent but is TREESAME
1086 * to a later parent. In the simplified history,
1087 * we "divert" the history walk to the later
1088 * parent. These commits are shown when "show_pulls"
1089 * is enabled, so do not mark the object as
1092 if (!revs
->show_pulls
|| !nth_parent
)
1093 commit
->object
.flags
|= TREESAME
;
1098 if (revs
->remove_empty_trees
&&
1099 rev_same_tree_as_empty(revs
, p
, nth_parent
)) {
1100 /* We are adding all the specified
1101 * paths from this parent, so the
1102 * history beyond this parent is not
1103 * interesting. Remove its parents
1104 * (they are grandparents for us).
1105 * IOW, we pretend this parent is a
1108 if (repo_parse_commit(revs
->repo
, p
) < 0)
1109 die("cannot simplify commit %s (invalid %s)",
1110 oid_to_hex(&commit
->object
.oid
),
1111 oid_to_hex(&p
->object
.oid
));
1112 free_commit_list(p
->parents
);
1117 case REV_TREE_DIFFERENT
:
1118 if (relevant_commit(p
))
1119 relevant_change
= 1;
1121 irrelevant_change
= 1;
1124 commit
->object
.flags
|= PULL_MERGE
;
1128 die("bad tree compare for commit %s", oid_to_hex(&commit
->object
.oid
));
1132 * TREESAME is straightforward for single-parent commits. For merge
1133 * commits, it is most useful to define it so that "irrelevant"
1134 * parents cannot make us !TREESAME - if we have any relevant
1135 * parents, then we only consider TREESAMEness with respect to them,
1136 * allowing irrelevant merges from uninteresting branches to be
1137 * simplified away. Only if we have only irrelevant parents do we
1138 * base TREESAME on them. Note that this logic is replicated in
1139 * update_treesame, which should be kept in sync.
1141 if (relevant_parents
? !relevant_change
: !irrelevant_change
)
1142 commit
->object
.flags
|= TREESAME
;
1145 static int process_parents(struct rev_info
*revs
, struct commit
*commit
,
1146 struct commit_list
**list
, struct prio_queue
*queue
)
1148 struct commit_list
*parent
= commit
->parents
;
1149 unsigned pass_flags
;
1151 if (commit
->object
.flags
& ADDED
)
1153 if (revs
->do_not_die_on_missing_objects
&&
1154 oidset_contains(&revs
->missing_commits
, &commit
->object
.oid
))
1156 commit
->object
.flags
|= ADDED
;
1158 if (revs
->include_check
&&
1159 !revs
->include_check(commit
, revs
->include_check_data
))
1163 * If the commit is uninteresting, don't try to
1164 * prune parents - we want the maximal uninteresting
1167 * Normally we haven't parsed the parent
1168 * yet, so we won't have a parent of a parent
1169 * here. However, it may turn out that we've
1170 * reached this commit some other way (where it
1171 * wasn't uninteresting), in which case we need
1172 * to mark its parents recursively too..
1174 if (commit
->object
.flags
& UNINTERESTING
) {
1176 struct commit
*p
= parent
->item
;
1177 parent
= parent
->next
;
1179 p
->object
.flags
|= UNINTERESTING
;
1180 if (repo_parse_commit_gently(revs
->repo
, p
, 1) < 0)
1183 mark_parents_uninteresting(revs
, p
);
1184 if (p
->object
.flags
& SEEN
)
1186 p
->object
.flags
|= (SEEN
| NOT_USER_GIVEN
);
1188 commit_list_insert_by_date(p
, list
);
1190 prio_queue_put(queue
, p
);
1191 if (revs
->exclude_first_parent_only
)
1198 * Ok, the commit wasn't uninteresting. Try to
1199 * simplify the commit history and find the parent
1200 * that has no differences in the path set if one exists.
1202 try_to_simplify_commit(revs
, commit
);
1207 pass_flags
= (commit
->object
.flags
& (SYMMETRIC_LEFT
| ANCESTRY_PATH
));
1209 for (parent
= commit
->parents
; parent
; parent
= parent
->next
) {
1210 struct commit
*p
= parent
->item
;
1211 int gently
= revs
->ignore_missing_links
||
1212 revs
->exclude_promisor_objects
||
1213 revs
->do_not_die_on_missing_objects
;
1214 if (repo_parse_commit_gently(revs
->repo
, p
, gently
) < 0) {
1215 if (revs
->exclude_promisor_objects
&&
1216 is_promisor_object(revs
->repo
, &p
->object
.oid
)) {
1217 if (revs
->first_parent_only
)
1222 if (revs
->do_not_die_on_missing_objects
)
1223 oidset_insert(&revs
->missing_commits
, &p
->object
.oid
);
1225 return -1; /* corrupt repository */
1227 if (revs
->sources
) {
1228 char **slot
= revision_sources_at(revs
->sources
, p
);
1231 *slot
= *revision_sources_at(revs
->sources
, commit
);
1233 p
->object
.flags
|= pass_flags
;
1234 if (!(p
->object
.flags
& SEEN
)) {
1235 p
->object
.flags
|= (SEEN
| NOT_USER_GIVEN
);
1237 commit_list_insert_by_date(p
, list
);
1239 prio_queue_put(queue
, p
);
1241 if (revs
->first_parent_only
)
1247 static void cherry_pick_list(struct commit_list
*list
, struct rev_info
*revs
)
1249 struct commit_list
*p
;
1250 int left_count
= 0, right_count
= 0;
1252 struct patch_ids ids
;
1253 unsigned cherry_flag
;
1255 /* First count the commits on the left and on the right */
1256 for (p
= list
; p
; p
= p
->next
) {
1257 struct commit
*commit
= p
->item
;
1258 unsigned flags
= commit
->object
.flags
;
1259 if (flags
& BOUNDARY
)
1261 else if (flags
& SYMMETRIC_LEFT
)
1267 if (!left_count
|| !right_count
)
1270 left_first
= left_count
< right_count
;
1271 init_patch_ids(revs
->repo
, &ids
);
1272 ids
.diffopts
.pathspec
= revs
->diffopt
.pathspec
;
1274 /* Compute patch-ids for one side */
1275 for (p
= list
; p
; p
= p
->next
) {
1276 struct commit
*commit
= p
->item
;
1277 unsigned flags
= commit
->object
.flags
;
1279 if (flags
& BOUNDARY
)
1282 * If we have fewer left, left_first is set and we omit
1283 * commits on the right branch in this loop. If we have
1284 * fewer right, we skip the left ones.
1286 if (left_first
!= !!(flags
& SYMMETRIC_LEFT
))
1288 add_commit_patch_id(commit
, &ids
);
1291 /* either cherry_mark or cherry_pick are true */
1292 cherry_flag
= revs
->cherry_mark
? PATCHSAME
: SHOWN
;
1294 /* Check the other side */
1295 for (p
= list
; p
; p
= p
->next
) {
1296 struct commit
*commit
= p
->item
;
1297 struct patch_id
*id
;
1298 unsigned flags
= commit
->object
.flags
;
1300 if (flags
& BOUNDARY
)
1303 * If we have fewer left, left_first is set and we omit
1304 * commits on the left branch in this loop.
1306 if (left_first
== !!(flags
& SYMMETRIC_LEFT
))
1310 * Have we seen the same patch id?
1312 id
= patch_id_iter_first(commit
, &ids
);
1316 commit
->object
.flags
|= cherry_flag
;
1318 id
->commit
->object
.flags
|= cherry_flag
;
1319 } while ((id
= patch_id_iter_next(id
, &ids
)));
1322 free_patch_ids(&ids
);
1325 /* How many extra uninteresting commits we want to see.. */
1328 static int still_interesting(struct commit_list
*src
, timestamp_t date
, int slop
,
1329 struct commit
**interesting_cache
)
1332 * No source list at all? We're definitely done..
1338 * Does the destination list contain entries with a date
1339 * before the source list? Definitely _not_ done.
1341 if (date
<= src
->item
->date
)
1345 * Does the source list still have interesting commits in
1346 * it? Definitely not done..
1348 if (!everybody_uninteresting(src
, interesting_cache
))
1351 /* Ok, we're closing in.. */
1356 * "rev-list --ancestry-path=C_0 [--ancestry-path=C_1 ...] A..B"
1357 * computes commits that are ancestors of B but not ancestors of A but
1358 * further limits the result to those that have any of C in their
1359 * ancestry path (i.e. are either ancestors of any of C, descendants
1360 * of any of C, or are any of C). If --ancestry-path is specified with
1361 * no commit, we use all bottom commits for C.
1363 * Before this function is called, ancestors of C will have already
1364 * been marked with ANCESTRY_PATH previously.
1366 * This takes the list of bottom commits and the result of "A..B"
1367 * without --ancestry-path, and limits the latter further to the ones
1368 * that have any of C in their ancestry path. Since the ancestors of C
1369 * have already been marked (a prerequisite of this function), we just
1370 * need to mark the descendants, then exclude any commit that does not
1371 * have any of these marks.
1373 static void limit_to_ancestry(struct commit_list
*bottoms
, struct commit_list
*list
)
1375 struct commit_list
*p
;
1376 struct commit_list
*rlist
= NULL
;
1380 * Reverse the list so that it will be likely that we would
1381 * process parents before children.
1383 for (p
= list
; p
; p
= p
->next
)
1384 commit_list_insert(p
->item
, &rlist
);
1386 for (p
= bottoms
; p
; p
= p
->next
)
1387 p
->item
->object
.flags
|= TMP_MARK
;
1390 * Mark the ones that can reach bottom commits in "list",
1391 * in a bottom-up fashion.
1395 for (p
= rlist
; p
; p
= p
->next
) {
1396 struct commit
*c
= p
->item
;
1397 struct commit_list
*parents
;
1398 if (c
->object
.flags
& (TMP_MARK
| UNINTERESTING
))
1400 for (parents
= c
->parents
;
1402 parents
= parents
->next
) {
1403 if (!(parents
->item
->object
.flags
& TMP_MARK
))
1405 c
->object
.flags
|= TMP_MARK
;
1410 } while (made_progress
);
1413 * NEEDSWORK: decide if we want to remove parents that are
1414 * not marked with TMP_MARK from commit->parents for commits
1415 * in the resulting list. We may not want to do that, though.
1419 * The ones that are not marked with either TMP_MARK or
1420 * ANCESTRY_PATH are uninteresting
1422 for (p
= list
; p
; p
= p
->next
) {
1423 struct commit
*c
= p
->item
;
1424 if (c
->object
.flags
& (TMP_MARK
| ANCESTRY_PATH
))
1426 c
->object
.flags
|= UNINTERESTING
;
1429 /* We are done with TMP_MARK and ANCESTRY_PATH */
1430 for (p
= list
; p
; p
= p
->next
)
1431 p
->item
->object
.flags
&= ~(TMP_MARK
| ANCESTRY_PATH
);
1432 for (p
= bottoms
; p
; p
= p
->next
)
1433 p
->item
->object
.flags
&= ~(TMP_MARK
| ANCESTRY_PATH
);
1434 free_commit_list(rlist
);
1438 * Before walking the history, add the set of "negative" refs the
1439 * caller has asked to exclude to the bottom list.
1441 * This is used to compute "rev-list --ancestry-path A..B", as we need
1442 * to filter the result of "A..B" further to the ones that can actually
1445 static void collect_bottom_commits(struct commit_list
*list
,
1446 struct commit_list
**bottom
)
1448 struct commit_list
*elem
;
1449 for (elem
= list
; elem
; elem
= elem
->next
)
1450 if (elem
->item
->object
.flags
& BOTTOM
)
1451 commit_list_insert(elem
->item
, bottom
);
1454 /* Assumes either left_only or right_only is set */
1455 static void limit_left_right(struct commit_list
*list
, struct rev_info
*revs
)
1457 struct commit_list
*p
;
1459 for (p
= list
; p
; p
= p
->next
) {
1460 struct commit
*commit
= p
->item
;
1462 if (revs
->right_only
) {
1463 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
1464 commit
->object
.flags
|= SHOWN
;
1465 } else /* revs->left_only is set */
1466 if (!(commit
->object
.flags
& SYMMETRIC_LEFT
))
1467 commit
->object
.flags
|= SHOWN
;
1471 static int limit_list(struct rev_info
*revs
)
1474 timestamp_t date
= TIME_MAX
;
1475 struct commit_list
*original_list
= revs
->commits
;
1476 struct commit_list
*newlist
= NULL
;
1477 struct commit_list
**p
= &newlist
;
1478 struct commit
*interesting_cache
= NULL
;
1480 if (revs
->ancestry_path_implicit_bottoms
) {
1481 collect_bottom_commits(original_list
,
1482 &revs
->ancestry_path_bottoms
);
1483 if (!revs
->ancestry_path_bottoms
)
1484 die("--ancestry-path given but there are no bottom commits");
1487 while (original_list
) {
1488 struct commit
*commit
= pop_commit(&original_list
);
1489 struct object
*obj
= &commit
->object
;
1491 if (commit
== interesting_cache
)
1492 interesting_cache
= NULL
;
1494 if (revs
->max_age
!= -1 && (commit
->date
< revs
->max_age
))
1495 obj
->flags
|= UNINTERESTING
;
1496 if (process_parents(revs
, commit
, &original_list
, NULL
) < 0)
1498 if (obj
->flags
& UNINTERESTING
) {
1499 mark_parents_uninteresting(revs
, commit
);
1500 slop
= still_interesting(original_list
, date
, slop
, &interesting_cache
);
1505 if (revs
->min_age
!= -1 && (commit
->date
> revs
->min_age
) &&
1506 !revs
->line_level_traverse
)
1508 if (revs
->max_age_as_filter
!= -1 &&
1509 (commit
->date
< revs
->max_age_as_filter
) && !revs
->line_level_traverse
)
1511 date
= commit
->date
;
1512 p
= &commit_list_insert(commit
, p
)->next
;
1514 if (revs
->cherry_pick
|| revs
->cherry_mark
)
1515 cherry_pick_list(newlist
, revs
);
1517 if (revs
->left_only
|| revs
->right_only
)
1518 limit_left_right(newlist
, revs
);
1520 if (revs
->ancestry_path
)
1521 limit_to_ancestry(revs
->ancestry_path_bottoms
, newlist
);
1524 * Check if any commits have become TREESAME by some of their parents
1525 * becoming UNINTERESTING.
1527 if (limiting_can_increase_treesame(revs
)) {
1528 struct commit_list
*list
= NULL
;
1529 for (list
= newlist
; list
; list
= list
->next
) {
1530 struct commit
*c
= list
->item
;
1531 if (c
->object
.flags
& (UNINTERESTING
| TREESAME
))
1533 update_treesame(revs
, c
);
1537 free_commit_list(original_list
);
1538 revs
->commits
= newlist
;
1543 * Add an entry to refs->cmdline with the specified information.
1546 static void add_rev_cmdline(struct rev_info
*revs
,
1547 struct object
*item
,
1552 struct rev_cmdline_info
*info
= &revs
->cmdline
;
1553 unsigned int nr
= info
->nr
;
1555 ALLOC_GROW(info
->rev
, nr
+ 1, info
->alloc
);
1556 info
->rev
[nr
].item
= item
;
1557 info
->rev
[nr
].name
= xstrdup(name
);
1558 info
->rev
[nr
].whence
= whence
;
1559 info
->rev
[nr
].flags
= flags
;
1563 static void add_rev_cmdline_list(struct rev_info
*revs
,
1564 struct commit_list
*commit_list
,
1568 while (commit_list
) {
1569 struct object
*object
= &commit_list
->item
->object
;
1570 add_rev_cmdline(revs
, object
, oid_to_hex(&object
->oid
),
1572 commit_list
= commit_list
->next
;
1576 int ref_excluded(const struct ref_exclusions
*exclusions
, const char *path
)
1578 const char *stripped_path
= strip_namespace(path
);
1579 struct string_list_item
*item
;
1581 for_each_string_list_item(item
, &exclusions
->excluded_refs
) {
1582 if (!wildmatch(item
->string
, path
, 0))
1586 if (ref_is_hidden(stripped_path
, path
, &exclusions
->hidden_refs
))
1592 void init_ref_exclusions(struct ref_exclusions
*exclusions
)
1594 struct ref_exclusions blank
= REF_EXCLUSIONS_INIT
;
1595 memcpy(exclusions
, &blank
, sizeof(*exclusions
));
1598 void clear_ref_exclusions(struct ref_exclusions
*exclusions
)
1600 string_list_clear(&exclusions
->excluded_refs
, 0);
1601 strvec_clear(&exclusions
->hidden_refs
);
1602 exclusions
->hidden_refs_configured
= 0;
1605 void add_ref_exclusion(struct ref_exclusions
*exclusions
, const char *exclude
)
1607 string_list_append(&exclusions
->excluded_refs
, exclude
);
1610 struct exclude_hidden_refs_cb
{
1611 struct ref_exclusions
*exclusions
;
1612 const char *section
;
1615 static int hide_refs_config(const char *var
, const char *value
,
1616 const struct config_context
*ctx UNUSED
,
1619 struct exclude_hidden_refs_cb
*cb
= cb_data
;
1620 cb
->exclusions
->hidden_refs_configured
= 1;
1621 return parse_hide_refs_config(var
, value
, cb
->section
,
1622 &cb
->exclusions
->hidden_refs
);
1625 void exclude_hidden_refs(struct ref_exclusions
*exclusions
, const char *section
)
1627 struct exclude_hidden_refs_cb cb
;
1629 if (strcmp(section
, "fetch") && strcmp(section
, "receive") &&
1630 strcmp(section
, "uploadpack"))
1631 die(_("unsupported section for hidden refs: %s"), section
);
1633 if (exclusions
->hidden_refs_configured
)
1634 die(_("--exclude-hidden= passed more than once"));
1636 cb
.exclusions
= exclusions
;
1637 cb
.section
= section
;
1639 repo_config(the_repository
, hide_refs_config
, &cb
);
1642 struct all_refs_cb
{
1644 int warned_bad_reflog
;
1645 struct rev_info
*all_revs
;
1646 const char *name_for_errormsg
;
1647 struct worktree
*wt
;
1650 static int handle_one_ref(const char *path
, const char *referent UNUSED
, const struct object_id
*oid
,
1654 struct all_refs_cb
*cb
= cb_data
;
1655 struct object
*object
;
1657 if (ref_excluded(&cb
->all_revs
->ref_excludes
, path
))
1660 object
= get_reference(cb
->all_revs
, path
, oid
, cb
->all_flags
);
1661 add_rev_cmdline(cb
->all_revs
, object
, path
, REV_CMD_REF
, cb
->all_flags
);
1662 add_pending_object(cb
->all_revs
, object
, path
);
1666 static void init_all_refs_cb(struct all_refs_cb
*cb
, struct rev_info
*revs
,
1669 cb
->all_revs
= revs
;
1670 cb
->all_flags
= flags
;
1671 revs
->rev_input_given
= 1;
1675 static void handle_refs(struct ref_store
*refs
,
1676 struct rev_info
*revs
, unsigned flags
,
1677 int (*for_each
)(struct ref_store
*, each_ref_fn
, void *))
1679 struct all_refs_cb cb
;
1682 /* this could happen with uninitialized submodules */
1686 init_all_refs_cb(&cb
, revs
, flags
);
1687 for_each(refs
, handle_one_ref
, &cb
);
1690 static void handle_one_reflog_commit(struct object_id
*oid
, void *cb_data
)
1692 struct all_refs_cb
*cb
= cb_data
;
1693 if (!is_null_oid(oid
)) {
1694 struct object
*o
= parse_object(cb
->all_revs
->repo
, oid
);
1696 o
->flags
|= cb
->all_flags
;
1697 /* ??? CMDLINEFLAGS ??? */
1698 add_pending_object(cb
->all_revs
, o
, "");
1700 else if (!cb
->warned_bad_reflog
) {
1701 warning("reflog of '%s' references pruned commits",
1702 cb
->name_for_errormsg
);
1703 cb
->warned_bad_reflog
= 1;
1708 static int handle_one_reflog_ent(const char *refname UNUSED
,
1709 struct object_id
*ooid
, struct object_id
*noid
,
1710 const char *email UNUSED
,
1711 timestamp_t timestamp UNUSED
,
1713 const char *message UNUSED
,
1716 handle_one_reflog_commit(ooid
, cb_data
);
1717 handle_one_reflog_commit(noid
, cb_data
);
1721 static int handle_one_reflog(const char *refname_in_wt
, void *cb_data
)
1723 struct all_refs_cb
*cb
= cb_data
;
1724 struct strbuf refname
= STRBUF_INIT
;
1726 cb
->warned_bad_reflog
= 0;
1727 strbuf_worktree_ref(cb
->wt
, &refname
, refname_in_wt
);
1728 cb
->name_for_errormsg
= refname
.buf
;
1729 refs_for_each_reflog_ent(get_main_ref_store(the_repository
),
1731 handle_one_reflog_ent
, cb_data
);
1732 strbuf_release(&refname
);
1736 static void add_other_reflogs_to_pending(struct all_refs_cb
*cb
)
1738 struct worktree
**worktrees
, **p
;
1740 worktrees
= get_worktrees();
1741 for (p
= worktrees
; *p
; p
++) {
1742 struct worktree
*wt
= *p
;
1748 refs_for_each_reflog(get_worktree_ref_store(wt
),
1752 free_worktrees(worktrees
);
1755 void add_reflogs_to_pending(struct rev_info
*revs
, unsigned flags
)
1757 struct all_refs_cb cb
;
1760 cb
.all_flags
= flags
;
1762 refs_for_each_reflog(get_main_ref_store(the_repository
),
1763 handle_one_reflog
, &cb
);
1765 if (!revs
->single_worktree
)
1766 add_other_reflogs_to_pending(&cb
);
1769 static void add_cache_tree(struct cache_tree
*it
, struct rev_info
*revs
,
1770 struct strbuf
*path
, unsigned int flags
)
1772 size_t baselen
= path
->len
;
1775 if (it
->entry_count
>= 0) {
1776 struct tree
*tree
= lookup_tree(revs
->repo
, &it
->oid
);
1777 tree
->object
.flags
|= flags
;
1778 add_pending_object_with_path(revs
, &tree
->object
, "",
1782 for (i
= 0; i
< it
->subtree_nr
; i
++) {
1783 struct cache_tree_sub
*sub
= it
->down
[i
];
1784 strbuf_addf(path
, "%s%s", baselen
? "/" : "", sub
->name
);
1785 add_cache_tree(sub
->cache_tree
, revs
, path
, flags
);
1786 strbuf_setlen(path
, baselen
);
1791 static void add_resolve_undo_to_pending(struct index_state
*istate
, struct rev_info
*revs
)
1793 struct string_list_item
*item
;
1794 struct string_list
*resolve_undo
= istate
->resolve_undo
;
1799 for_each_string_list_item(item
, resolve_undo
) {
1800 const char *path
= item
->string
;
1801 struct resolve_undo_info
*ru
= item
->util
;
1806 for (i
= 0; i
< 3; i
++) {
1809 if (!ru
->mode
[i
] || !S_ISREG(ru
->mode
[i
]))
1812 blob
= lookup_blob(revs
->repo
, &ru
->oid
[i
]);
1814 warning(_("resolve-undo records `%s` which is missing"),
1815 oid_to_hex(&ru
->oid
[i
]));
1818 add_pending_object_with_path(revs
, &blob
->object
, "",
1824 static void do_add_index_objects_to_pending(struct rev_info
*revs
,
1825 struct index_state
*istate
,
1830 /* TODO: audit for interaction with sparse-index. */
1831 ensure_full_index(istate
);
1832 for (i
= 0; i
< istate
->cache_nr
; i
++) {
1833 struct cache_entry
*ce
= istate
->cache
[i
];
1836 if (S_ISGITLINK(ce
->ce_mode
))
1839 blob
= lookup_blob(revs
->repo
, &ce
->oid
);
1841 die("unable to add index blob to traversal");
1842 blob
->object
.flags
|= flags
;
1843 add_pending_object_with_path(revs
, &blob
->object
, "",
1844 ce
->ce_mode
, ce
->name
);
1847 if (istate
->cache_tree
) {
1848 struct strbuf path
= STRBUF_INIT
;
1849 add_cache_tree(istate
->cache_tree
, revs
, &path
, flags
);
1850 strbuf_release(&path
);
1853 add_resolve_undo_to_pending(istate
, revs
);
1856 void add_index_objects_to_pending(struct rev_info
*revs
, unsigned int flags
)
1858 struct worktree
**worktrees
, **p
;
1860 repo_read_index(revs
->repo
);
1861 do_add_index_objects_to_pending(revs
, revs
->repo
->index
, flags
);
1863 if (revs
->single_worktree
)
1866 worktrees
= get_worktrees();
1867 for (p
= worktrees
; *p
; p
++) {
1868 struct worktree
*wt
= *p
;
1869 struct index_state istate
= INDEX_STATE_INIT(revs
->repo
);
1873 continue; /* current index already taken care of */
1875 wt_gitdir
= get_worktree_git_dir(wt
);
1877 if (read_index_from(&istate
,
1878 worktree_git_path(the_repository
, wt
, "index"),
1880 do_add_index_objects_to_pending(revs
, &istate
, flags
);
1882 discard_index(&istate
);
1885 free_worktrees(worktrees
);
1888 struct add_alternate_refs_data
{
1889 struct rev_info
*revs
;
1893 static void add_one_alternate_ref(const struct object_id
*oid
,
1896 const char *name
= ".alternate";
1897 struct add_alternate_refs_data
*data
= vdata
;
1900 obj
= get_reference(data
->revs
, name
, oid
, data
->flags
);
1901 add_rev_cmdline(data
->revs
, obj
, name
, REV_CMD_REV
, data
->flags
);
1902 add_pending_object(data
->revs
, obj
, name
);
1905 static void add_alternate_refs_to_pending(struct rev_info
*revs
,
1908 struct add_alternate_refs_data data
;
1911 odb_for_each_alternate_ref(the_repository
->objects
,
1912 add_one_alternate_ref
, &data
);
1915 static int add_parents_only(struct rev_info
*revs
, const char *arg_
, int flags
,
1918 struct object_id oid
;
1920 struct commit
*commit
;
1921 struct commit_list
*parents
;
1923 const char *arg
= arg_
;
1926 flags
^= UNINTERESTING
| BOTTOM
;
1929 if (repo_get_oid_committish(the_repository
, arg
, &oid
))
1932 it
= get_reference(revs
, arg
, &oid
, 0);
1933 if (!it
&& revs
->ignore_missing
)
1935 if (it
->type
!= OBJ_TAG
)
1937 if (!((struct tag
*)it
)->tagged
)
1939 oidcpy(&oid
, &((struct tag
*)it
)->tagged
->oid
);
1941 if (it
->type
!= OBJ_COMMIT
)
1943 commit
= (struct commit
*)it
;
1944 if (exclude_parent
&&
1945 exclude_parent
> commit_list_count(commit
->parents
))
1947 for (parents
= commit
->parents
, parent_number
= 1;
1949 parents
= parents
->next
, parent_number
++) {
1950 if (exclude_parent
&& parent_number
!= exclude_parent
)
1953 it
= &parents
->item
->object
;
1955 add_rev_cmdline(revs
, it
, arg_
, REV_CMD_PARENTS_ONLY
, flags
);
1956 add_pending_object(revs
, it
, arg
);
1961 void repo_init_revisions(struct repository
*r
,
1962 struct rev_info
*revs
,
1965 struct rev_info blank
= REV_INFO_INIT
;
1966 memcpy(revs
, &blank
, sizeof(*revs
));
1969 revs
->pruning
.repo
= r
;
1970 revs
->pruning
.add_remove
= file_add_remove
;
1971 revs
->pruning
.change
= file_change
;
1972 revs
->pruning
.change_fn_data
= revs
;
1973 revs
->prefix
= prefix
;
1975 grep_init(&revs
->grep_filter
, revs
->repo
);
1976 revs
->grep_filter
.status_only
= 1;
1978 repo_diff_setup(revs
->repo
, &revs
->diffopt
);
1979 if (prefix
&& !revs
->diffopt
.prefix
) {
1980 revs
->diffopt
.prefix
= prefix
;
1981 revs
->diffopt
.prefix_length
= strlen(prefix
);
1984 init_display_notes(&revs
->notes_opt
);
1985 list_objects_filter_init(&revs
->filter
);
1986 init_ref_exclusions(&revs
->ref_excludes
);
1987 oidset_init(&revs
->missing_commits
, 0);
1990 static void add_pending_commit_list(struct rev_info
*revs
,
1991 struct commit_list
*commit_list
,
1994 while (commit_list
) {
1995 struct object
*object
= &commit_list
->item
->object
;
1996 object
->flags
|= flags
;
1997 add_pending_object(revs
, object
, oid_to_hex(&object
->oid
));
1998 commit_list
= commit_list
->next
;
2002 static const char *lookup_other_head(struct object_id
*oid
)
2005 static const char *const other_head
[] = {
2006 "MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "REBASE_HEAD"
2009 for (i
= 0; i
< ARRAY_SIZE(other_head
); i
++)
2010 if (!refs_read_ref_full(get_main_ref_store(the_repository
), other_head
[i
],
2011 RESOLVE_REF_READING
| RESOLVE_REF_NO_RECURSE
,
2013 if (is_null_oid(oid
))
2014 die(_("%s exists but is a symbolic ref"), other_head
[i
]);
2015 return other_head
[i
];
2018 die(_("--merge requires one of the pseudorefs MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD or REBASE_HEAD"));
2021 static void prepare_show_merge(struct rev_info
*revs
)
2023 struct commit_list
*bases
= NULL
;
2024 struct commit
*head
, *other
;
2025 struct object_id oid
;
2026 const char *other_name
;
2027 const char **prune
= NULL
;
2028 int i
, prune_num
= 1; /* counting terminating NULL */
2029 struct index_state
*istate
= revs
->repo
->index
;
2031 if (repo_get_oid(the_repository
, "HEAD", &oid
))
2032 die("--merge without HEAD?");
2033 head
= lookup_commit_or_die(&oid
, "HEAD");
2034 other_name
= lookup_other_head(&oid
);
2035 other
= lookup_commit_or_die(&oid
, other_name
);
2036 add_pending_object(revs
, &head
->object
, "HEAD");
2037 add_pending_object(revs
, &other
->object
, other_name
);
2038 if (repo_get_merge_bases(the_repository
, head
, other
, &bases
) < 0)
2040 add_rev_cmdline_list(revs
, bases
, REV_CMD_MERGE_BASE
, UNINTERESTING
| BOTTOM
);
2041 add_pending_commit_list(revs
, bases
, UNINTERESTING
| BOTTOM
);
2042 free_commit_list(bases
);
2043 head
->object
.flags
|= SYMMETRIC_LEFT
;
2045 if (!istate
->cache_nr
)
2046 repo_read_index(revs
->repo
);
2047 for (i
= 0; i
< istate
->cache_nr
; i
++) {
2048 const struct cache_entry
*ce
= istate
->cache
[i
];
2051 if (ce_path_match(istate
, ce
, &revs
->prune_data
, NULL
)) {
2053 REALLOC_ARRAY(prune
, prune_num
);
2054 prune
[prune_num
-2] = ce
->name
;
2055 prune
[prune_num
-1] = NULL
;
2057 while ((i
+1 < istate
->cache_nr
) &&
2058 ce_same_name(ce
, istate
->cache
[i
+1]))
2061 clear_pathspec(&revs
->prune_data
);
2062 parse_pathspec(&revs
->prune_data
, PATHSPEC_ALL_MAGIC
& ~PATHSPEC_LITERAL
,
2063 PATHSPEC_PREFER_FULL
| PATHSPEC_LITERAL_PATH
, "", prune
);
2068 static int dotdot_missing(const char *arg
, char *dotdot
,
2069 struct rev_info
*revs
, int symmetric
)
2071 if (revs
->ignore_missing
)
2073 /* de-munge so we report the full argument */
2076 ? "Invalid symmetric difference expression %s"
2077 : "Invalid revision range %s", arg
);
2080 static int handle_dotdot_1(const char *arg
, char *dotdot
,
2081 struct rev_info
*revs
, int flags
,
2082 int cant_be_filename
,
2083 struct object_context
*a_oc
,
2084 struct object_context
*b_oc
)
2086 const char *a_name
, *b_name
;
2087 struct object_id a_oid
, b_oid
;
2088 struct object
*a_obj
, *b_obj
;
2089 unsigned int a_flags
, b_flags
;
2091 unsigned int flags_exclude
= flags
^ (UNINTERESTING
| BOTTOM
);
2092 unsigned int oc_flags
= GET_OID_COMMITTISH
| GET_OID_RECORD_PATH
;
2098 b_name
= dotdot
+ 2;
2099 if (*b_name
== '.') {
2106 if (get_oid_with_context(revs
->repo
, a_name
, oc_flags
, &a_oid
, a_oc
) ||
2107 get_oid_with_context(revs
->repo
, b_name
, oc_flags
, &b_oid
, b_oc
))
2110 if (!cant_be_filename
) {
2112 verify_non_filename(revs
->prefix
, arg
);
2116 a_obj
= parse_object(revs
->repo
, &a_oid
);
2117 b_obj
= parse_object(revs
->repo
, &b_oid
);
2118 if (!a_obj
|| !b_obj
)
2119 return dotdot_missing(arg
, dotdot
, revs
, symmetric
);
2124 a_flags
= flags_exclude
;
2126 /* A...B -- find merge bases between the two */
2127 struct commit
*a
, *b
;
2128 struct commit_list
*exclude
= NULL
;
2130 a
= lookup_commit_reference(revs
->repo
, &a_obj
->oid
);
2131 b
= lookup_commit_reference(revs
->repo
, &b_obj
->oid
);
2133 return dotdot_missing(arg
, dotdot
, revs
, symmetric
);
2135 if (repo_get_merge_bases(the_repository
, a
, b
, &exclude
) < 0) {
2136 free_commit_list(exclude
);
2139 add_rev_cmdline_list(revs
, exclude
, REV_CMD_MERGE_BASE
,
2141 add_pending_commit_list(revs
, exclude
, flags_exclude
);
2142 free_commit_list(exclude
);
2145 a_flags
= flags
| SYMMETRIC_LEFT
;
2148 a_obj
->flags
|= a_flags
;
2149 b_obj
->flags
|= b_flags
;
2150 add_rev_cmdline(revs
, a_obj
, a_name
, REV_CMD_LEFT
, a_flags
);
2151 add_rev_cmdline(revs
, b_obj
, b_name
, REV_CMD_RIGHT
, b_flags
);
2152 add_pending_object_with_path(revs
, a_obj
, a_name
, a_oc
->mode
, a_oc
->path
);
2153 add_pending_object_with_path(revs
, b_obj
, b_name
, b_oc
->mode
, b_oc
->path
);
2157 static int handle_dotdot(const char *arg
,
2158 struct rev_info
*revs
, int flags
,
2159 int cant_be_filename
)
2161 struct object_context a_oc
= {0}, b_oc
= {0};
2162 char *dotdot
= strstr(arg
, "..");
2169 ret
= handle_dotdot_1(arg
, dotdot
, revs
, flags
, cant_be_filename
,
2173 object_context_release(&a_oc
);
2174 object_context_release(&b_oc
);
2178 static int handle_revision_arg_1(const char *arg_
, struct rev_info
*revs
, int flags
, unsigned revarg_opt
)
2180 struct object_context oc
= {0};
2182 struct object
*object
;
2183 struct object_id oid
;
2185 const char *arg
= arg_
;
2186 int cant_be_filename
= revarg_opt
& REVARG_CANNOT_BE_FILENAME
;
2187 unsigned get_sha1_flags
= GET_OID_RECORD_PATH
;
2190 flags
= flags
& UNINTERESTING
? flags
| BOTTOM
: flags
& ~BOTTOM
;
2192 if (!cant_be_filename
&& !strcmp(arg
, "..")) {
2194 * Just ".."? That is not a range but the
2195 * pathspec for the parent directory.
2201 if (!handle_dotdot(arg
, revs
, flags
, revarg_opt
)) {
2206 mark
= strstr(arg
, "^@");
2207 if (mark
&& !mark
[2]) {
2209 if (add_parents_only(revs
, arg
, flags
, 0)) {
2215 mark
= strstr(arg
, "^!");
2216 if (mark
&& !mark
[2]) {
2218 if (!add_parents_only(revs
, arg
, flags
^ (UNINTERESTING
| BOTTOM
), 0))
2221 mark
= strstr(arg
, "^-");
2223 int exclude_parent
= 1;
2226 if (strtol_i(mark
+ 2, 10, &exclude_parent
) ||
2227 exclude_parent
< 1) {
2234 if (!add_parents_only(revs
, arg
, flags
^ (UNINTERESTING
| BOTTOM
), exclude_parent
))
2240 local_flags
= UNINTERESTING
| BOTTOM
;
2244 if (revarg_opt
& REVARG_COMMITTISH
)
2245 get_sha1_flags
|= GET_OID_COMMITTISH
;
2248 * Even if revs->do_not_die_on_missing_objects is set, we
2249 * should error out if we can't even get an oid, as
2250 * `--missing=print` should be able to report missing oids.
2252 if (get_oid_with_context(revs
->repo
, arg
, get_sha1_flags
, &oid
, &oc
)) {
2253 ret
= revs
->ignore_missing
? 0 : -1;
2256 if (!cant_be_filename
)
2257 verify_non_filename(revs
->prefix
, arg
);
2258 object
= get_reference(revs
, arg
, &oid
, flags
^ local_flags
);
2260 ret
= (revs
->ignore_missing
|| revs
->do_not_die_on_missing_objects
) ? 0 : -1;
2263 add_rev_cmdline(revs
, object
, arg_
, REV_CMD_REV
, flags
^ local_flags
);
2264 add_pending_object_with_path(revs
, object
, arg
, oc
.mode
, oc
.path
);
2269 object_context_release(&oc
);
2273 int handle_revision_arg(const char *arg
, struct rev_info
*revs
, int flags
, unsigned revarg_opt
)
2275 int ret
= handle_revision_arg_1(arg
, revs
, flags
, revarg_opt
);
2277 revs
->rev_input_given
= 1;
2281 static void read_pathspec_from_stdin(struct strbuf
*sb
,
2282 struct strvec
*prune
)
2284 while (strbuf_getline(sb
, stdin
) != EOF
)
2285 strvec_push(prune
, sb
->buf
);
2288 static void add_grep(struct rev_info
*revs
, const char *ptn
, enum grep_pat_token what
)
2290 append_grep_pattern(&revs
->grep_filter
, ptn
, "command line", 0, what
);
2293 static void add_header_grep(struct rev_info
*revs
, enum grep_header_field field
, const char *pattern
)
2295 append_header_grep_pattern(&revs
->grep_filter
, field
, pattern
);
2298 static void add_message_grep(struct rev_info
*revs
, const char *pattern
)
2300 add_grep(revs
, pattern
, GREP_PATTERN_BODY
);
2303 static int parse_count(const char *arg
)
2307 if (strtol_i(arg
, 10, &count
) < 0)
2308 die("'%s': not an integer", arg
);
2312 static timestamp_t
parse_age(const char *arg
)
2318 num
= parse_timestamp(arg
, &p
, 10);
2319 if (errno
|| *p
|| p
== arg
)
2320 die("'%s': not a number of seconds since epoch", arg
);
2324 static int handle_revision_opt(struct rev_info
*revs
, int argc
, const char **argv
,
2325 int *unkc
, const char **unkv
,
2326 const struct setup_revision_opt
* opt
)
2328 const char *arg
= argv
[0];
2329 const char *optarg
= NULL
;
2331 const unsigned hexsz
= the_hash_algo
->hexsz
;
2333 /* pseudo revision arguments */
2334 if (!strcmp(arg
, "--all") || !strcmp(arg
, "--branches") ||
2335 !strcmp(arg
, "--tags") || !strcmp(arg
, "--remotes") ||
2336 !strcmp(arg
, "--reflog") || !strcmp(arg
, "--not") ||
2337 !strcmp(arg
, "--no-walk") || !strcmp(arg
, "--do-walk") ||
2338 !strcmp(arg
, "--bisect") || starts_with(arg
, "--glob=") ||
2339 !strcmp(arg
, "--indexed-objects") ||
2340 !strcmp(arg
, "--alternate-refs") ||
2341 starts_with(arg
, "--exclude=") || starts_with(arg
, "--exclude-hidden=") ||
2342 starts_with(arg
, "--branches=") || starts_with(arg
, "--tags=") ||
2343 starts_with(arg
, "--remotes=") || starts_with(arg
, "--no-walk="))
2345 unkv
[(*unkc
)++] = arg
;
2349 if ((argcount
= parse_long_opt("max-count", argv
, &optarg
))) {
2350 revs
->max_count
= parse_count(optarg
);
2353 } else if ((argcount
= parse_long_opt("skip", argv
, &optarg
))) {
2354 revs
->skip_count
= parse_count(optarg
);
2356 } else if ((*arg
== '-') && isdigit(arg
[1])) {
2357 /* accept -<digit>, like traditional "head" */
2358 revs
->max_count
= parse_count(arg
+ 1);
2360 } else if (!strcmp(arg
, "-n")) {
2362 return error("-n requires an argument");
2363 revs
->max_count
= parse_count(argv
[1]);
2366 } else if (skip_prefix(arg
, "-n", &optarg
)) {
2367 revs
->max_count
= parse_count(optarg
);
2369 } else if ((argcount
= parse_long_opt("max-age", argv
, &optarg
))) {
2370 revs
->max_age
= parse_age(optarg
);
2372 } else if ((argcount
= parse_long_opt("since", argv
, &optarg
))) {
2373 revs
->max_age
= approxidate(optarg
);
2375 } else if ((argcount
= parse_long_opt("since-as-filter", argv
, &optarg
))) {
2376 revs
->max_age_as_filter
= approxidate(optarg
);
2378 } else if ((argcount
= parse_long_opt("after", argv
, &optarg
))) {
2379 revs
->max_age
= approxidate(optarg
);
2381 } else if ((argcount
= parse_long_opt("min-age", argv
, &optarg
))) {
2382 revs
->min_age
= parse_age(optarg
);
2384 } else if ((argcount
= parse_long_opt("before", argv
, &optarg
))) {
2385 revs
->min_age
= approxidate(optarg
);
2387 } else if ((argcount
= parse_long_opt("until", argv
, &optarg
))) {
2388 revs
->min_age
= approxidate(optarg
);
2390 } else if (!strcmp(arg
, "--first-parent")) {
2391 revs
->first_parent_only
= 1;
2392 } else if (!strcmp(arg
, "--exclude-first-parent-only")) {
2393 revs
->exclude_first_parent_only
= 1;
2394 } else if (!strcmp(arg
, "--ancestry-path")) {
2395 revs
->ancestry_path
= 1;
2396 revs
->simplify_history
= 0;
2398 revs
->ancestry_path_implicit_bottoms
= 1;
2399 } else if (skip_prefix(arg
, "--ancestry-path=", &optarg
)) {
2401 struct object_id oid
;
2402 const char *msg
= _("could not get commit for --ancestry-path argument %s");
2404 revs
->ancestry_path
= 1;
2405 revs
->simplify_history
= 0;
2408 if (repo_get_oid_committish(revs
->repo
, optarg
, &oid
))
2409 return error(msg
, optarg
);
2410 get_reference(revs
, optarg
, &oid
, ANCESTRY_PATH
);
2411 c
= lookup_commit_reference(revs
->repo
, &oid
);
2413 return error(msg
, optarg
);
2414 commit_list_insert(c
, &revs
->ancestry_path_bottoms
);
2415 } else if (!strcmp(arg
, "-g") || !strcmp(arg
, "--walk-reflogs")) {
2416 init_reflog_walk(&revs
->reflog_info
);
2417 } else if (!strcmp(arg
, "--default")) {
2419 return error("bad --default argument");
2420 revs
->def
= argv
[1];
2422 } else if (!strcmp(arg
, "--merge")) {
2423 revs
->show_merge
= 1;
2424 } else if (!strcmp(arg
, "--topo-order")) {
2425 revs
->sort_order
= REV_SORT_IN_GRAPH_ORDER
;
2426 revs
->topo_order
= 1;
2427 } else if (!strcmp(arg
, "--simplify-merges")) {
2428 revs
->simplify_merges
= 1;
2429 revs
->topo_order
= 1;
2430 revs
->rewrite_parents
= 1;
2431 revs
->simplify_history
= 0;
2433 } else if (!strcmp(arg
, "--simplify-by-decoration")) {
2434 revs
->simplify_merges
= 1;
2435 revs
->topo_order
= 1;
2436 revs
->rewrite_parents
= 1;
2437 revs
->simplify_history
= 0;
2438 revs
->simplify_by_decoration
= 1;
2441 } else if (!strcmp(arg
, "--date-order")) {
2442 revs
->sort_order
= REV_SORT_BY_COMMIT_DATE
;
2443 revs
->topo_order
= 1;
2444 } else if (!strcmp(arg
, "--author-date-order")) {
2445 revs
->sort_order
= REV_SORT_BY_AUTHOR_DATE
;
2446 revs
->topo_order
= 1;
2447 } else if (!strcmp(arg
, "--parents")) {
2448 revs
->rewrite_parents
= 1;
2449 revs
->print_parents
= 1;
2450 } else if (!strcmp(arg
, "--dense")) {
2452 } else if (!strcmp(arg
, "--sparse")) {
2454 } else if (!strcmp(arg
, "--in-commit-order")) {
2455 revs
->tree_blobs_in_commit_order
= 1;
2456 } else if (!strcmp(arg
, "--remove-empty")) {
2457 revs
->remove_empty_trees
= 1;
2458 } else if (!strcmp(arg
, "--merges")) {
2459 revs
->min_parents
= 2;
2460 } else if (!strcmp(arg
, "--no-merges")) {
2461 revs
->max_parents
= 1;
2462 } else if (skip_prefix(arg
, "--min-parents=", &optarg
)) {
2463 revs
->min_parents
= parse_count(optarg
);
2464 } else if (!strcmp(arg
, "--no-min-parents")) {
2465 revs
->min_parents
= 0;
2466 } else if (skip_prefix(arg
, "--max-parents=", &optarg
)) {
2467 revs
->max_parents
= parse_count(optarg
);
2468 } else if (!strcmp(arg
, "--no-max-parents")) {
2469 revs
->max_parents
= -1;
2470 } else if (!strcmp(arg
, "--boundary")) {
2472 } else if (!strcmp(arg
, "--left-right")) {
2473 revs
->left_right
= 1;
2474 } else if (!strcmp(arg
, "--left-only")) {
2475 if (revs
->right_only
)
2476 die(_("options '%s' and '%s' cannot be used together"),
2477 "--left-only", "--right-only/--cherry");
2478 revs
->left_only
= 1;
2480 } else if (!strcmp(arg
, "--right-only")) {
2481 if (revs
->left_only
)
2482 die(_("options '%s' and '%s' cannot be used together"), "--right-only", "--left-only");
2483 revs
->right_only
= 1;
2485 } else if (!strcmp(arg
, "--cherry")) {
2486 if (revs
->left_only
)
2487 die(_("options '%s' and '%s' cannot be used together"), "--cherry", "--left-only");
2488 revs
->cherry_mark
= 1;
2489 revs
->right_only
= 1;
2490 revs
->max_parents
= 1;
2492 } else if (!strcmp(arg
, "--count")) {
2494 } else if (!strcmp(arg
, "--cherry-mark")) {
2495 if (revs
->cherry_pick
)
2496 die(_("options '%s' and '%s' cannot be used together"), "--cherry-mark", "--cherry-pick");
2497 revs
->cherry_mark
= 1;
2498 revs
->limited
= 1; /* needs limit_list() */
2499 } else if (!strcmp(arg
, "--cherry-pick")) {
2500 if (revs
->cherry_mark
)
2501 die(_("options '%s' and '%s' cannot be used together"), "--cherry-pick", "--cherry-mark");
2502 revs
->cherry_pick
= 1;
2504 } else if (!strcmp(arg
, "--objects")) {
2505 revs
->tag_objects
= 1;
2506 revs
->tree_objects
= 1;
2507 revs
->blob_objects
= 1;
2508 } else if (!strcmp(arg
, "--objects-edge")) {
2509 revs
->tag_objects
= 1;
2510 revs
->tree_objects
= 1;
2511 revs
->blob_objects
= 1;
2512 revs
->edge_hint
= 1;
2513 } else if (!strcmp(arg
, "--objects-edge-aggressive")) {
2514 revs
->tag_objects
= 1;
2515 revs
->tree_objects
= 1;
2516 revs
->blob_objects
= 1;
2517 revs
->edge_hint
= 1;
2518 revs
->edge_hint_aggressive
= 1;
2519 } else if (!strcmp(arg
, "--verify-objects")) {
2520 revs
->tag_objects
= 1;
2521 revs
->tree_objects
= 1;
2522 revs
->blob_objects
= 1;
2523 revs
->verify_objects
= 1;
2524 disable_commit_graph(revs
->repo
);
2525 } else if (!strcmp(arg
, "--unpacked")) {
2527 } else if (starts_with(arg
, "--unpacked=")) {
2528 die(_("--unpacked=<packfile> no longer supported"));
2529 } else if (!strcmp(arg
, "--no-kept-objects")) {
2530 revs
->no_kept_objects
= 1;
2531 revs
->keep_pack_cache_flags
|= IN_CORE_KEEP_PACKS
;
2532 revs
->keep_pack_cache_flags
|= ON_DISK_KEEP_PACKS
;
2533 } else if (skip_prefix(arg
, "--no-kept-objects=", &optarg
)) {
2534 revs
->no_kept_objects
= 1;
2535 if (!strcmp(optarg
, "in-core"))
2536 revs
->keep_pack_cache_flags
|= IN_CORE_KEEP_PACKS
;
2537 if (!strcmp(optarg
, "on-disk"))
2538 revs
->keep_pack_cache_flags
|= ON_DISK_KEEP_PACKS
;
2539 } else if (!strcmp(arg
, "-r")) {
2541 revs
->diffopt
.flags
.recursive
= 1;
2542 } else if (!strcmp(arg
, "-t")) {
2544 revs
->diffopt
.flags
.recursive
= 1;
2545 revs
->diffopt
.flags
.tree_in_recursive
= 1;
2546 } else if ((argcount
= diff_merges_parse_opts(revs
, argv
))) {
2548 } else if (!strcmp(arg
, "-v")) {
2549 revs
->verbose_header
= 1;
2550 } else if (!strcmp(arg
, "--pretty")) {
2551 revs
->verbose_header
= 1;
2552 revs
->pretty_given
= 1;
2553 get_commit_format(NULL
, revs
);
2554 } else if (skip_prefix(arg
, "--pretty=", &optarg
) ||
2555 skip_prefix(arg
, "--format=", &optarg
)) {
2557 * Detached form ("--pretty X" as opposed to "--pretty=X")
2558 * not allowed, since the argument is optional.
2560 revs
->verbose_header
= 1;
2561 revs
->pretty_given
= 1;
2562 get_commit_format(optarg
, revs
);
2563 } else if (!strcmp(arg
, "--expand-tabs")) {
2564 revs
->expand_tabs_in_log
= 8;
2565 } else if (!strcmp(arg
, "--no-expand-tabs")) {
2566 revs
->expand_tabs_in_log
= 0;
2567 } else if (skip_prefix(arg
, "--expand-tabs=", &arg
)) {
2569 if (strtol_i(arg
, 10, &val
) < 0 || val
< 0)
2570 die("'%s': not a non-negative integer", arg
);
2571 revs
->expand_tabs_in_log
= val
;
2572 } else if (!strcmp(arg
, "--show-notes") || !strcmp(arg
, "--notes")) {
2573 enable_default_display_notes(&revs
->notes_opt
, &revs
->show_notes
);
2574 revs
->show_notes_given
= 1;
2575 } else if (!strcmp(arg
, "--show-signature")) {
2576 revs
->show_signature
= 1;
2577 } else if (!strcmp(arg
, "--no-show-signature")) {
2578 revs
->show_signature
= 0;
2579 } else if (!strcmp(arg
, "--show-linear-break")) {
2580 revs
->break_bar
= " ..........";
2581 revs
->track_linear
= 1;
2582 revs
->track_first_time
= 1;
2583 } else if (skip_prefix(arg
, "--show-linear-break=", &optarg
)) {
2584 revs
->break_bar
= xstrdup(optarg
);
2585 revs
->track_linear
= 1;
2586 revs
->track_first_time
= 1;
2587 } else if (!strcmp(arg
, "--show-notes-by-default")) {
2588 revs
->show_notes_by_default
= 1;
2589 } else if (skip_prefix(arg
, "--show-notes=", &optarg
) ||
2590 skip_prefix(arg
, "--notes=", &optarg
)) {
2591 if (starts_with(arg
, "--show-notes=") &&
2592 revs
->notes_opt
.use_default_notes
< 0)
2593 revs
->notes_opt
.use_default_notes
= 1;
2594 enable_ref_display_notes(&revs
->notes_opt
, &revs
->show_notes
, optarg
);
2595 revs
->show_notes_given
= 1;
2596 } else if (!strcmp(arg
, "--no-notes")) {
2597 disable_display_notes(&revs
->notes_opt
, &revs
->show_notes
);
2598 revs
->show_notes_given
= 1;
2599 } else if (!strcmp(arg
, "--standard-notes")) {
2600 revs
->show_notes_given
= 1;
2601 revs
->notes_opt
.use_default_notes
= 1;
2602 } else if (!strcmp(arg
, "--no-standard-notes")) {
2603 revs
->notes_opt
.use_default_notes
= 0;
2604 } else if (!strcmp(arg
, "--oneline")) {
2605 revs
->verbose_header
= 1;
2606 get_commit_format("oneline", revs
);
2607 revs
->pretty_given
= 1;
2608 revs
->abbrev_commit
= 1;
2609 } else if (!strcmp(arg
, "--graph")) {
2610 graph_clear(revs
->graph
);
2611 revs
->graph
= graph_init(revs
);
2612 } else if (!strcmp(arg
, "--no-graph")) {
2613 graph_clear(revs
->graph
);
2615 } else if (!strcmp(arg
, "--encode-email-headers")) {
2616 revs
->encode_email_headers
= 1;
2617 } else if (!strcmp(arg
, "--no-encode-email-headers")) {
2618 revs
->encode_email_headers
= 0;
2619 } else if (!strcmp(arg
, "--root")) {
2620 revs
->show_root_diff
= 1;
2621 } else if (!strcmp(arg
, "--no-commit-id")) {
2622 revs
->no_commit_id
= 1;
2623 } else if (!strcmp(arg
, "--always")) {
2624 revs
->always_show_header
= 1;
2625 } else if (!strcmp(arg
, "--no-abbrev")) {
2627 } else if (!strcmp(arg
, "--abbrev")) {
2628 revs
->abbrev
= DEFAULT_ABBREV
;
2629 } else if (skip_prefix(arg
, "--abbrev=", &optarg
)) {
2630 revs
->abbrev
= strtoul(optarg
, NULL
, 10);
2631 if (revs
->abbrev
< MINIMUM_ABBREV
)
2632 revs
->abbrev
= MINIMUM_ABBREV
;
2633 else if (revs
->abbrev
> hexsz
)
2634 revs
->abbrev
= hexsz
;
2635 } else if (!strcmp(arg
, "--abbrev-commit")) {
2636 revs
->abbrev_commit
= 1;
2637 revs
->abbrev_commit_given
= 1;
2638 } else if (!strcmp(arg
, "--no-abbrev-commit")) {
2639 revs
->abbrev_commit
= 0;
2640 } else if (!strcmp(arg
, "--full-diff")) {
2642 revs
->full_diff
= 1;
2643 } else if (!strcmp(arg
, "--show-pulls")) {
2644 revs
->show_pulls
= 1;
2645 } else if (!strcmp(arg
, "--full-history")) {
2646 revs
->simplify_history
= 0;
2647 } else if (!strcmp(arg
, "--relative-date")) {
2648 revs
->date_mode
.type
= DATE_RELATIVE
;
2649 revs
->date_mode_explicit
= 1;
2650 } else if ((argcount
= parse_long_opt("date", argv
, &optarg
))) {
2651 parse_date_format(optarg
, &revs
->date_mode
);
2652 revs
->date_mode_explicit
= 1;
2654 } else if (!strcmp(arg
, "--log-size")) {
2655 revs
->show_log_size
= 1;
2658 * Grepping the commit log
2660 else if ((argcount
= parse_long_opt("author", argv
, &optarg
))) {
2661 add_header_grep(revs
, GREP_HEADER_AUTHOR
, optarg
);
2663 } else if ((argcount
= parse_long_opt("committer", argv
, &optarg
))) {
2664 add_header_grep(revs
, GREP_HEADER_COMMITTER
, optarg
);
2666 } else if ((argcount
= parse_long_opt("grep-reflog", argv
, &optarg
))) {
2667 add_header_grep(revs
, GREP_HEADER_REFLOG
, optarg
);
2669 } else if ((argcount
= parse_long_opt("grep", argv
, &optarg
))) {
2670 add_message_grep(revs
, optarg
);
2672 } else if (!strcmp(arg
, "--basic-regexp")) {
2673 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_BRE
;
2674 } else if (!strcmp(arg
, "--extended-regexp") || !strcmp(arg
, "-E")) {
2675 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_ERE
;
2676 } else if (!strcmp(arg
, "--regexp-ignore-case") || !strcmp(arg
, "-i")) {
2677 revs
->grep_filter
.ignore_case
= 1;
2678 revs
->diffopt
.pickaxe_opts
|= DIFF_PICKAXE_IGNORE_CASE
;
2679 } else if (!strcmp(arg
, "--fixed-strings") || !strcmp(arg
, "-F")) {
2680 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_FIXED
;
2681 } else if (!strcmp(arg
, "--perl-regexp") || !strcmp(arg
, "-P")) {
2682 revs
->grep_filter
.pattern_type_option
= GREP_PATTERN_TYPE_PCRE
;
2683 } else if (!strcmp(arg
, "--all-match")) {
2684 revs
->grep_filter
.all_match
= 1;
2685 } else if (!strcmp(arg
, "--invert-grep")) {
2686 revs
->grep_filter
.no_body_match
= 1;
2687 } else if ((argcount
= parse_long_opt("encoding", argv
, &optarg
))) {
2688 free(git_log_output_encoding
);
2689 if (strcmp(optarg
, "none"))
2690 git_log_output_encoding
= xstrdup(optarg
);
2692 git_log_output_encoding
= xstrdup("");
2694 } else if (!strcmp(arg
, "--reverse")) {
2696 } else if (!strcmp(arg
, "--children")) {
2697 revs
->children
.name
= "children";
2699 } else if (!strcmp(arg
, "--ignore-missing")) {
2700 revs
->ignore_missing
= 1;
2701 } else if (opt
&& opt
->allow_exclude_promisor_objects
&&
2702 !strcmp(arg
, "--exclude-promisor-objects")) {
2703 if (fetch_if_missing
)
2704 BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0");
2705 revs
->exclude_promisor_objects
= 1;
2707 int opts
= diff_opt_parse(&revs
->diffopt
, argv
, argc
, revs
->prefix
);
2709 unkv
[(*unkc
)++] = arg
;
2716 void parse_revision_opt(struct rev_info
*revs
, struct parse_opt_ctx_t
*ctx
,
2717 const struct option
*options
,
2718 const char * const usagestr
[])
2720 int n
= handle_revision_opt(revs
, ctx
->argc
, ctx
->argv
,
2721 &ctx
->cpidx
, ctx
->out
, NULL
);
2723 error("unknown option `%s'", ctx
->argv
[0]);
2724 usage_with_options(usagestr
, options
);
2730 void revision_opts_finish(struct rev_info
*revs
)
2732 if (revs
->graph
&& revs
->track_linear
)
2733 die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");
2736 revs
->topo_order
= 1;
2737 revs
->rewrite_parents
= 1;
2741 static int for_each_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
,
2742 void *cb_data
, const char *term
)
2744 struct strbuf bisect_refs
= STRBUF_INIT
;
2746 strbuf_addf(&bisect_refs
, "refs/bisect/%s", term
);
2747 status
= refs_for_each_fullref_in(refs
, bisect_refs
.buf
, NULL
, fn
, cb_data
);
2748 strbuf_release(&bisect_refs
);
2752 static int for_each_bad_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
, void *cb_data
)
2754 return for_each_bisect_ref(refs
, fn
, cb_data
, term_bad
);
2757 static int for_each_good_bisect_ref(struct ref_store
*refs
, each_ref_fn fn
, void *cb_data
)
2759 return for_each_bisect_ref(refs
, fn
, cb_data
, term_good
);
2762 static int handle_revision_pseudo_opt(struct rev_info
*revs
,
2763 const char **argv
, int *flags
)
2765 const char *arg
= argv
[0];
2767 struct ref_store
*refs
;
2770 if (revs
->repo
!= the_repository
) {
2772 * We need some something like get_submodule_worktrees()
2773 * before we can go through all worktrees of a submodule,
2774 * .e.g with adding all HEADs from --all, which is not
2775 * supported right now, so stick to single worktree.
2777 if (!revs
->single_worktree
)
2778 BUG("--single-worktree cannot be used together with submodule");
2780 refs
= get_main_ref_store(revs
->repo
);
2785 * Commands like "git shortlog" will not accept the options below
2786 * unless parse_revision_opt queues them (as opposed to erroring
2789 * When implementing your new pseudo-option, remember to
2790 * register it in the list at the top of handle_revision_opt.
2792 if (!strcmp(arg
, "--all")) {
2793 handle_refs(refs
, revs
, *flags
, refs_for_each_ref
);
2794 handle_refs(refs
, revs
, *flags
, refs_head_ref
);
2795 if (!revs
->single_worktree
) {
2796 struct all_refs_cb cb
;
2798 init_all_refs_cb(&cb
, revs
, *flags
);
2799 other_head_refs(handle_one_ref
, &cb
);
2801 clear_ref_exclusions(&revs
->ref_excludes
);
2802 } else if (!strcmp(arg
, "--branches")) {
2803 if (revs
->ref_excludes
.hidden_refs_configured
)
2804 return error(_("options '%s' and '%s' cannot be used together"),
2805 "--exclude-hidden", "--branches");
2806 handle_refs(refs
, revs
, *flags
, refs_for_each_branch_ref
);
2807 clear_ref_exclusions(&revs
->ref_excludes
);
2808 } else if (!strcmp(arg
, "--bisect")) {
2809 read_bisect_terms(&term_bad
, &term_good
);
2810 handle_refs(refs
, revs
, *flags
, for_each_bad_bisect_ref
);
2811 handle_refs(refs
, revs
, *flags
^ (UNINTERESTING
| BOTTOM
),
2812 for_each_good_bisect_ref
);
2814 } else if (!strcmp(arg
, "--tags")) {
2815 if (revs
->ref_excludes
.hidden_refs_configured
)
2816 return error(_("options '%s' and '%s' cannot be used together"),
2817 "--exclude-hidden", "--tags");
2818 handle_refs(refs
, revs
, *flags
, refs_for_each_tag_ref
);
2819 clear_ref_exclusions(&revs
->ref_excludes
);
2820 } else if (!strcmp(arg
, "--remotes")) {
2821 if (revs
->ref_excludes
.hidden_refs_configured
)
2822 return error(_("options '%s' and '%s' cannot be used together"),
2823 "--exclude-hidden", "--remotes");
2824 handle_refs(refs
, revs
, *flags
, refs_for_each_remote_ref
);
2825 clear_ref_exclusions(&revs
->ref_excludes
);
2826 } else if ((argcount
= parse_long_opt("glob", argv
, &optarg
))) {
2827 struct all_refs_cb cb
;
2828 init_all_refs_cb(&cb
, revs
, *flags
);
2829 refs_for_each_glob_ref(get_main_ref_store(the_repository
),
2830 handle_one_ref
, optarg
, &cb
);
2831 clear_ref_exclusions(&revs
->ref_excludes
);
2833 } else if ((argcount
= parse_long_opt("exclude", argv
, &optarg
))) {
2834 add_ref_exclusion(&revs
->ref_excludes
, optarg
);
2836 } else if ((argcount
= parse_long_opt("exclude-hidden", argv
, &optarg
))) {
2837 exclude_hidden_refs(&revs
->ref_excludes
, optarg
);
2839 } else if (skip_prefix(arg
, "--branches=", &optarg
)) {
2840 struct all_refs_cb cb
;
2841 if (revs
->ref_excludes
.hidden_refs_configured
)
2842 return error(_("options '%s' and '%s' cannot be used together"),
2843 "--exclude-hidden", "--branches");
2844 init_all_refs_cb(&cb
, revs
, *flags
);
2845 refs_for_each_glob_ref_in(get_main_ref_store(the_repository
),
2846 handle_one_ref
, optarg
,
2847 "refs/heads/", &cb
);
2848 clear_ref_exclusions(&revs
->ref_excludes
);
2849 } else if (skip_prefix(arg
, "--tags=", &optarg
)) {
2850 struct all_refs_cb cb
;
2851 if (revs
->ref_excludes
.hidden_refs_configured
)
2852 return error(_("options '%s' and '%s' cannot be used together"),
2853 "--exclude-hidden", "--tags");
2854 init_all_refs_cb(&cb
, revs
, *flags
);
2855 refs_for_each_glob_ref_in(get_main_ref_store(the_repository
),
2856 handle_one_ref
, optarg
,
2858 clear_ref_exclusions(&revs
->ref_excludes
);
2859 } else if (skip_prefix(arg
, "--remotes=", &optarg
)) {
2860 struct all_refs_cb cb
;
2861 if (revs
->ref_excludes
.hidden_refs_configured
)
2862 return error(_("options '%s' and '%s' cannot be used together"),
2863 "--exclude-hidden", "--remotes");
2864 init_all_refs_cb(&cb
, revs
, *flags
);
2865 refs_for_each_glob_ref_in(get_main_ref_store(the_repository
),
2866 handle_one_ref
, optarg
,
2867 "refs/remotes/", &cb
);
2868 clear_ref_exclusions(&revs
->ref_excludes
);
2869 } else if (!strcmp(arg
, "--reflog")) {
2870 add_reflogs_to_pending(revs
, *flags
);
2871 } else if (!strcmp(arg
, "--indexed-objects")) {
2872 add_index_objects_to_pending(revs
, *flags
);
2873 } else if (!strcmp(arg
, "--alternate-refs")) {
2874 add_alternate_refs_to_pending(revs
, *flags
);
2875 } else if (!strcmp(arg
, "--not")) {
2876 *flags
^= UNINTERESTING
| BOTTOM
;
2877 } else if (!strcmp(arg
, "--no-walk")) {
2879 } else if (skip_prefix(arg
, "--no-walk=", &optarg
)) {
2881 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
2882 * not allowed, since the argument is optional.
2885 if (!strcmp(optarg
, "sorted"))
2886 revs
->unsorted_input
= 0;
2887 else if (!strcmp(optarg
, "unsorted"))
2888 revs
->unsorted_input
= 1;
2890 return error("invalid argument to --no-walk");
2891 } else if (!strcmp(arg
, "--do-walk")) {
2893 } else if (!strcmp(arg
, "--single-worktree")) {
2894 revs
->single_worktree
= 1;
2895 } else if (skip_prefix(arg
, ("--filter="), &arg
)) {
2896 parse_list_objects_filter(&revs
->filter
, arg
);
2897 } else if (!strcmp(arg
, ("--no-filter"))) {
2898 list_objects_filter_set_no_filter(&revs
->filter
);
2906 static void read_revisions_from_stdin(struct rev_info
*revs
,
2907 struct strvec
*prune
)
2910 int seen_dashdash
= 0;
2911 int seen_end_of_options
= 0;
2915 save_warning
= warn_on_object_refname_ambiguity
;
2916 warn_on_object_refname_ambiguity
= 0;
2918 strbuf_init(&sb
, 1000);
2919 while (strbuf_getline(&sb
, stdin
) != EOF
) {
2923 if (!strcmp(sb
.buf
, "--")) {
2928 if (!seen_end_of_options
&& sb
.buf
[0] == '-') {
2929 const char *argv
[] = { sb
.buf
, NULL
};
2931 if (!strcmp(sb
.buf
, "--end-of-options")) {
2932 seen_end_of_options
= 1;
2936 if (handle_revision_pseudo_opt(revs
, argv
, &flags
) > 0)
2939 die(_("invalid option '%s' in --stdin mode"), sb
.buf
);
2942 if (handle_revision_arg(sb
.buf
, revs
, flags
,
2943 REVARG_CANNOT_BE_FILENAME
))
2944 die("bad revision '%s'", sb
.buf
);
2947 read_pathspec_from_stdin(&sb
, prune
);
2949 strbuf_release(&sb
);
2950 warn_on_object_refname_ambiguity
= save_warning
;
2953 static void NORETURN
diagnose_missing_default(const char *def
)
2956 const char *refname
;
2958 refname
= refs_resolve_ref_unsafe(get_main_ref_store(the_repository
),
2959 def
, 0, NULL
, &flags
);
2960 if (!refname
|| !(flags
& REF_ISSYMREF
) || (flags
& REF_ISBROKEN
))
2961 die(_("your current branch appears to be broken"));
2963 skip_prefix(refname
, "refs/heads/", &refname
);
2964 die(_("your current branch '%s' does not have any commits yet"),
2969 * Parse revision information, filling in the "rev_info" structure,
2970 * and removing the used arguments from the argument list.
2972 * Returns the number of arguments left that weren't recognized
2973 * (which are also moved to the head of the argument list)
2975 int setup_revisions(int argc
, const char **argv
, struct rev_info
*revs
, struct setup_revision_opt
*opt
)
2977 int i
, flags
, left
, seen_dashdash
, revarg_opt
;
2978 struct strvec prune_data
= STRVEC_INIT
;
2979 int seen_end_of_options
= 0;
2981 /* First, search for "--" */
2982 if (opt
&& opt
->assume_dashdash
) {
2986 for (i
= 1; i
< argc
; i
++) {
2987 const char *arg
= argv
[i
];
2988 if (strcmp(arg
, "--"))
2990 if (opt
&& opt
->free_removed_argv_elements
)
2991 free((char *)argv
[i
]);
2995 strvec_pushv(&prune_data
, argv
+ i
+ 1);
3001 /* Second, deal with arguments and options */
3003 revarg_opt
= opt
? opt
->revarg_opt
: 0;
3005 revarg_opt
|= REVARG_CANNOT_BE_FILENAME
;
3006 for (left
= i
= 1; i
< argc
; i
++) {
3007 const char *arg
= argv
[i
];
3008 if (!seen_end_of_options
&& *arg
== '-') {
3011 opts
= handle_revision_pseudo_opt(
3019 if (!strcmp(arg
, "--stdin")) {
3020 if (revs
->disable_stdin
) {
3024 if (revs
->read_from_stdin
++)
3025 die("--stdin given twice?");
3026 read_revisions_from_stdin(revs
, &prune_data
);
3030 if (!strcmp(arg
, "--end-of-options")) {
3031 seen_end_of_options
= 1;
3035 opts
= handle_revision_opt(revs
, argc
- i
, argv
+ i
,
3047 if (handle_revision_arg(arg
, revs
, flags
, revarg_opt
)) {
3049 if (seen_dashdash
|| *arg
== '^')
3050 die("bad revision '%s'", arg
);
3052 /* If we didn't have a "--":
3053 * (1) all filenames must exist;
3054 * (2) all rev-args must not be interpretable
3055 * as a valid filename.
3056 * but the latter we have checked in the main loop.
3058 for (j
= i
; j
< argc
; j
++)
3059 verify_filename(revs
->prefix
, argv
[j
], j
== i
);
3061 strvec_pushv(&prune_data
, argv
+ i
);
3065 revision_opts_finish(revs
);
3067 if (prune_data
.nr
) {
3069 * If we need to introduce the magic "a lone ':' means no
3070 * pathspec whatsoever", here is the place to do so.
3072 * if (prune_data.nr == 1 && !strcmp(prune_data[0], ":")) {
3073 * prune_data.nr = 0;
3074 * prune_data.alloc = 0;
3075 * free(prune_data.path);
3076 * prune_data.path = NULL;
3078 * terminate prune_data.alloc with NULL and
3079 * call init_pathspec() to set revs->prune_data here.
3082 parse_pathspec(&revs
->prune_data
, 0, 0,
3083 revs
->prefix
, prune_data
.v
);
3085 strvec_clear(&prune_data
);
3088 revs
->def
= opt
? opt
->def
: NULL
;
3089 if (opt
&& opt
->tweak
)
3091 if (revs
->show_merge
)
3092 prepare_show_merge(revs
);
3093 if (revs
->def
&& !revs
->pending
.nr
&& !revs
->rev_input_given
) {
3094 struct object_id oid
;
3095 struct object
*object
;
3096 struct object_context oc
;
3097 if (get_oid_with_context(revs
->repo
, revs
->def
, 0, &oid
, &oc
))
3098 diagnose_missing_default(revs
->def
);
3099 object
= get_reference(revs
, revs
->def
, &oid
, 0);
3100 add_pending_object_with_mode(revs
, object
, revs
->def
, oc
.mode
);
3101 object_context_release(&oc
);
3104 /* Did the user ask for any diff output? Run the diff! */
3105 if (revs
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
)
3108 /* Pickaxe, diff-filter and rename following need diffs */
3109 if ((revs
->diffopt
.pickaxe_opts
& DIFF_PICKAXE_KINDS_MASK
) ||
3110 revs
->diffopt
.filter
|| revs
->diffopt
.filter_not
||
3111 revs
->diffopt
.flags
.follow_renames
)
3114 if (revs
->diffopt
.objfind
)
3115 revs
->simplify_history
= 0;
3117 if (revs
->line_level_traverse
) {
3118 if (want_ancestry(revs
))
3120 revs
->topo_order
= 1;
3123 if (revs
->topo_order
&& !generation_numbers_enabled(the_repository
))
3126 if (revs
->prune_data
.nr
) {
3127 copy_pathspec(&revs
->pruning
.pathspec
, &revs
->prune_data
);
3128 /* Can't prune commits with rename following: the paths change.. */
3129 if (!revs
->diffopt
.flags
.follow_renames
)
3131 if (!revs
->full_diff
)
3132 copy_pathspec(&revs
->diffopt
.pathspec
,
3136 diff_merges_setup_revs(revs
);
3138 revs
->diffopt
.abbrev
= revs
->abbrev
;
3140 diff_setup_done(&revs
->diffopt
);
3142 if (!is_encoding_utf8(get_log_output_encoding()))
3143 revs
->grep_filter
.ignore_locale
= 1;
3144 compile_grep_patterns(&revs
->grep_filter
);
3146 if (revs
->reflog_info
&& revs
->limited
)
3147 die("cannot combine --walk-reflogs with history-limiting options");
3148 if (revs
->rewrite_parents
&& revs
->children
.name
)
3149 die(_("options '%s' and '%s' cannot be used together"), "--parents", "--children");
3150 if (revs
->filter
.choice
&& !revs
->blob_objects
)
3151 die(_("object filtering requires --objects"));
3154 * Limitations on the graph functionality
3156 die_for_incompatible_opt3(!!revs
->graph
, "--graph",
3157 !!revs
->reverse
, "--reverse",
3158 !!revs
->reflog_info
, "--walk-reflogs");
3160 if (revs
->no_walk
&& revs
->graph
)
3161 die(_("options '%s' and '%s' cannot be used together"), "--no-walk", "--graph");
3162 if (!revs
->reflog_info
&& revs
->grep_filter
.use_reflog_filter
)
3163 die(_("the option '%s' requires '%s'"), "--grep-reflog", "--walk-reflogs");
3165 if (revs
->line_level_traverse
&&
3166 (revs
->diffopt
.output_format
& ~(DIFF_FORMAT_PATCH
| DIFF_FORMAT_NO_OUTPUT
)))
3167 die(_("-L does not yet support diff formats besides -p and -s"));
3169 if (revs
->expand_tabs_in_log
< 0)
3170 revs
->expand_tabs_in_log
= revs
->expand_tabs_in_log_default
;
3172 if (!revs
->show_notes_given
&& revs
->show_notes_by_default
) {
3173 enable_default_display_notes(&revs
->notes_opt
, &revs
->show_notes
);
3174 revs
->show_notes_given
= 1;
3180 static void release_revisions_cmdline(struct rev_cmdline_info
*cmdline
)
3184 for (i
= 0; i
< cmdline
->nr
; i
++)
3185 free((char *)cmdline
->rev
[i
].name
);
3189 static void release_revisions_mailmap(struct string_list
*mailmap
)
3193 clear_mailmap(mailmap
);
3197 static void release_revisions_topo_walk_info(struct topo_walk_info
*info
);
3199 static void release_revisions_bloom_keyvecs(struct rev_info
*revs
)
3201 for (size_t nr
= 0; nr
< revs
->bloom_keyvecs_nr
; nr
++)
3202 bloom_keyvec_free(revs
->bloom_keyvecs
[nr
]);
3203 FREE_AND_NULL(revs
->bloom_keyvecs
);
3204 revs
->bloom_keyvecs_nr
= 0;
3207 static void free_void_commit_list(void *list
)
3209 free_commit_list(list
);
3212 void release_revisions(struct rev_info
*revs
)
3214 free_commit_list(revs
->commits
);
3215 free_commit_list(revs
->ancestry_path_bottoms
);
3216 release_display_notes(&revs
->notes_opt
);
3217 object_array_clear(&revs
->pending
);
3218 object_array_clear(&revs
->boundary_commits
);
3219 release_revisions_cmdline(&revs
->cmdline
);
3220 list_objects_filter_release(&revs
->filter
);
3221 clear_pathspec(&revs
->prune_data
);
3222 date_mode_release(&revs
->date_mode
);
3223 release_revisions_mailmap(revs
->mailmap
);
3224 free_grep_patterns(&revs
->grep_filter
);
3225 graph_clear(revs
->graph
);
3226 diff_free(&revs
->diffopt
);
3227 diff_free(&revs
->pruning
);
3228 reflog_walk_info_release(revs
->reflog_info
);
3229 release_revisions_topo_walk_info(revs
->topo_walk_info
);
3230 clear_decoration(&revs
->children
, free_void_commit_list
);
3231 clear_decoration(&revs
->merge_simplification
, free
);
3232 clear_decoration(&revs
->treesame
, free
);
3233 line_log_free(revs
);
3234 oidset_clear(&revs
->missing_commits
);
3235 release_revisions_bloom_keyvecs(revs
);
3238 static void add_child(struct rev_info
*revs
, struct commit
*parent
, struct commit
*child
)
3240 struct commit_list
*l
= xcalloc(1, sizeof(*l
));
3243 l
->next
= add_decoration(&revs
->children
, &parent
->object
, l
);
3246 static int remove_duplicate_parents(struct rev_info
*revs
, struct commit
*commit
)
3248 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
3249 struct commit_list
**pp
, *p
;
3250 int surviving_parents
;
3252 /* Examine existing parents while marking ones we have seen... */
3253 pp
= &commit
->parents
;
3254 surviving_parents
= 0;
3255 while ((p
= *pp
) != NULL
) {
3256 struct commit
*parent
= p
->item
;
3257 if (parent
->object
.flags
& TMP_MARK
) {
3261 compact_treesame(revs
, commit
, surviving_parents
);
3264 parent
->object
.flags
|= TMP_MARK
;
3265 surviving_parents
++;
3268 /* clear the temporary mark */
3269 for (p
= commit
->parents
; p
; p
= p
->next
) {
3270 p
->item
->object
.flags
&= ~TMP_MARK
;
3272 /* no update_treesame() - removing duplicates can't affect TREESAME */
3273 return surviving_parents
;
3276 struct merge_simplify_state
{
3277 struct commit
*simplified
;
3280 static struct merge_simplify_state
*locate_simplify_state(struct rev_info
*revs
, struct commit
*commit
)
3282 struct merge_simplify_state
*st
;
3284 st
= lookup_decoration(&revs
->merge_simplification
, &commit
->object
);
3286 CALLOC_ARRAY(st
, 1);
3287 add_decoration(&revs
->merge_simplification
, &commit
->object
, st
);
3292 static int mark_redundant_parents(struct commit
*commit
)
3294 struct commit_list
*h
= reduce_heads(commit
->parents
);
3295 int i
= 0, marked
= 0;
3296 struct commit_list
*po
, *pn
;
3298 /* Want these for sanity-checking only */
3299 int orig_cnt
= commit_list_count(commit
->parents
);
3300 int cnt
= commit_list_count(h
);
3303 * Not ready to remove items yet, just mark them for now, based
3304 * on the output of reduce_heads(). reduce_heads outputs the reduced
3305 * set in its original order, so this isn't too hard.
3307 po
= commit
->parents
;
3310 if (pn
&& po
->item
== pn
->item
) {
3314 po
->item
->object
.flags
|= TMP_MARK
;
3320 if (i
!= cnt
|| cnt
+marked
!= orig_cnt
)
3321 die("mark_redundant_parents %d %d %d %d", orig_cnt
, cnt
, i
, marked
);
3323 free_commit_list(h
);
3328 static int mark_treesame_root_parents(struct commit
*commit
)
3330 struct commit_list
*p
;
3333 for (p
= commit
->parents
; p
; p
= p
->next
) {
3334 struct commit
*parent
= p
->item
;
3335 if (!parent
->parents
&& (parent
->object
.flags
& TREESAME
)) {
3336 parent
->object
.flags
|= TMP_MARK
;
3345 * Awkward naming - this means one parent we are TREESAME to.
3346 * cf mark_treesame_root_parents: root parents that are TREESAME (to an
3347 * empty tree). Better name suggestions?
3349 static int leave_one_treesame_to_parent(struct rev_info
*revs
, struct commit
*commit
)
3351 struct treesame_state
*ts
= lookup_decoration(&revs
->treesame
, &commit
->object
);
3352 struct commit
*unmarked
= NULL
, *marked
= NULL
;
3353 struct commit_list
*p
;
3356 for (p
= commit
->parents
, n
= 0; p
; p
= p
->next
, n
++) {
3357 if (ts
->treesame
[n
]) {
3358 if (p
->item
->object
.flags
& TMP_MARK
) {
3371 * If we are TREESAME to a marked-for-deletion parent, but not to any
3372 * unmarked parents, unmark the first TREESAME parent. This is the
3373 * parent that the default simplify_history==1 scan would have followed,
3374 * and it doesn't make sense to omit that path when asking for a
3375 * simplified full history. Retaining it improves the chances of
3376 * understanding odd missed merges that took an old version of a file.
3380 * I--------*X A modified the file, but mainline merge X used
3381 * \ / "-s ours", so took the version from I. X is
3382 * `-*A--' TREESAME to I and !TREESAME to A.
3384 * Default log from X would produce "I". Without this check,
3385 * --full-history --simplify-merges would produce "I-A-X", showing
3386 * the merge commit X and that it changed A, but not making clear that
3387 * it had just taken the I version. With this check, the topology above
3390 * Note that it is possible that the simplification chooses a different
3391 * TREESAME parent from the default, in which case this test doesn't
3392 * activate, and we _do_ drop the default parent. Example:
3394 * I------X A modified the file, but it was reverted in B,
3395 * \ / meaning mainline merge X is TREESAME to both
3398 * Default log would produce "I" by following the first parent;
3399 * --full-history --simplify-merges will produce "I-A-B". But this is a
3400 * reasonable result - it presents a logical full history leading from
3401 * I to X, and X is not an important merge.
3403 if (!unmarked
&& marked
) {
3404 marked
->object
.flags
&= ~TMP_MARK
;
3411 static int remove_marked_parents(struct rev_info
*revs
, struct commit
*commit
)
3413 struct commit_list
**pp
, *p
;
3414 int nth_parent
, removed
= 0;
3416 pp
= &commit
->parents
;
3418 while ((p
= *pp
) != NULL
) {
3419 struct commit
*parent
= p
->item
;
3420 if (parent
->object
.flags
& TMP_MARK
) {
3421 parent
->object
.flags
&= ~TMP_MARK
;
3425 compact_treesame(revs
, commit
, nth_parent
);
3432 /* Removing parents can only increase TREESAMEness */
3433 if (removed
&& !(commit
->object
.flags
& TREESAME
))
3434 update_treesame(revs
, commit
);
3439 static struct commit_list
**simplify_one(struct rev_info
*revs
, struct commit
*commit
, struct commit_list
**tail
)
3441 struct commit_list
*p
;
3442 struct commit
*parent
;
3443 struct merge_simplify_state
*st
, *pst
;
3446 st
= locate_simplify_state(revs
, commit
);
3449 * Have we handled this one?
3455 * An UNINTERESTING commit simplifies to itself, so does a
3456 * root commit. We do not rewrite parents of such commit
3459 if ((commit
->object
.flags
& UNINTERESTING
) || !commit
->parents
) {
3460 st
->simplified
= commit
;
3465 * Do we know what commit all of our parents that matter
3466 * should be rewritten to? Otherwise we are not ready to
3467 * rewrite this one yet.
3469 for (cnt
= 0, p
= commit
->parents
; p
; p
= p
->next
) {
3470 pst
= locate_simplify_state(revs
, p
->item
);
3471 if (!pst
->simplified
) {
3472 tail
= &commit_list_insert(p
->item
, tail
)->next
;
3475 if (revs
->first_parent_only
)
3479 tail
= &commit_list_insert(commit
, tail
)->next
;
3484 * Rewrite our list of parents. Note that this cannot
3485 * affect our TREESAME flags in any way - a commit is
3486 * always TREESAME to its simplification.
3488 for (p
= commit
->parents
; p
; p
= p
->next
) {
3489 pst
= locate_simplify_state(revs
, p
->item
);
3490 p
->item
= pst
->simplified
;
3491 if (revs
->first_parent_only
)
3495 if (revs
->first_parent_only
)
3498 cnt
= remove_duplicate_parents(revs
, commit
);
3501 * It is possible that we are a merge and one side branch
3502 * does not have any commit that touches the given paths;
3503 * in such a case, the immediate parent from that branch
3504 * will be rewritten to be the merge base.
3506 * o----X X: the commit we are looking at;
3507 * / / o: a commit that touches the paths;
3510 * Further, a merge of an independent branch that doesn't
3511 * touch the path will reduce to a treesame root parent:
3513 * ----o----X X: the commit we are looking at;
3514 * / o: a commit that touches the paths;
3515 * r r: a root commit not touching the paths
3517 * Detect and simplify both cases.
3520 int marked
= mark_redundant_parents(commit
);
3521 marked
+= mark_treesame_root_parents(commit
);
3523 marked
-= leave_one_treesame_to_parent(revs
, commit
);
3525 cnt
= remove_marked_parents(revs
, commit
);
3529 * A commit simplifies to itself if it is a root, if it is
3530 * UNINTERESTING, if it touches the given paths, or if it is a
3531 * merge and its parents don't simplify to one relevant commit
3532 * (the first two cases are already handled at the beginning of
3535 * Otherwise, it simplifies to what its sole relevant parent
3539 (commit
->object
.flags
& UNINTERESTING
) ||
3540 !(commit
->object
.flags
& TREESAME
) ||
3541 (parent
= one_relevant_parent(revs
, commit
->parents
)) == NULL
||
3542 (revs
->show_pulls
&& (commit
->object
.flags
& PULL_MERGE
)))
3543 st
->simplified
= commit
;
3545 pst
= locate_simplify_state(revs
, parent
);
3546 st
->simplified
= pst
->simplified
;
3551 static void simplify_merges(struct rev_info
*revs
)
3553 struct commit_list
*list
, *next
;
3554 struct commit_list
*yet_to_do
, **tail
;
3555 struct commit
*commit
;
3560 /* feed the list reversed */
3562 for (list
= revs
->commits
; list
; list
= next
) {
3563 commit
= list
->item
;
3566 * Do not free(list) here yet; the original list
3567 * is used later in this function.
3569 commit_list_insert(commit
, &yet_to_do
);
3576 commit
= pop_commit(&list
);
3577 tail
= simplify_one(revs
, commit
, tail
);
3581 /* clean up the result, removing the simplified ones */
3582 list
= revs
->commits
;
3583 revs
->commits
= NULL
;
3584 tail
= &revs
->commits
;
3586 struct merge_simplify_state
*st
;
3588 commit
= pop_commit(&list
);
3589 st
= locate_simplify_state(revs
, commit
);
3590 if (st
->simplified
== commit
)
3591 tail
= &commit_list_insert(commit
, tail
)->next
;
3595 static void set_children(struct rev_info
*revs
)
3597 struct commit_list
*l
;
3598 for (l
= revs
->commits
; l
; l
= l
->next
) {
3599 struct commit
*commit
= l
->item
;
3600 struct commit_list
*p
;
3602 for (p
= commit
->parents
; p
; p
= p
->next
)
3603 add_child(revs
, p
->item
, commit
);
3607 void reset_revision_walk(void)
3609 clear_object_flags(the_repository
,
3610 SEEN
| ADDED
| SHOWN
| TOPO_WALK_EXPLORED
| TOPO_WALK_INDEGREE
);
3613 static int mark_uninteresting(const struct object_id
*oid
,
3614 struct packed_git
*pack UNUSED
,
3615 uint32_t pos UNUSED
,
3618 struct rev_info
*revs
= cb
;
3619 struct object
*o
= lookup_unknown_object(revs
->repo
, oid
);
3620 o
->flags
|= UNINTERESTING
| SEEN
;
3624 define_commit_slab(indegree_slab
, int);
3625 define_commit_slab(author_date_slab
, timestamp_t
);
3627 struct topo_walk_info
{
3628 timestamp_t min_generation
;
3629 struct prio_queue explore_queue
;
3630 struct prio_queue indegree_queue
;
3631 struct prio_queue topo_queue
;
3632 struct indegree_slab indegree
;
3633 struct author_date_slab author_date
;
3636 static int topo_walk_atexit_registered
;
3637 static unsigned int count_explore_walked
;
3638 static unsigned int count_indegree_walked
;
3639 static unsigned int count_topo_walked
;
3641 static void trace2_topo_walk_statistics_atexit(void)
3643 struct json_writer jw
= JSON_WRITER_INIT
;
3645 jw_object_begin(&jw
, 0);
3646 jw_object_intmax(&jw
, "count_explore_walked", count_explore_walked
);
3647 jw_object_intmax(&jw
, "count_indegree_walked", count_indegree_walked
);
3648 jw_object_intmax(&jw
, "count_topo_walked", count_topo_walked
);
3651 trace2_data_json("topo_walk", the_repository
, "statistics", &jw
);
3656 static inline void test_flag_and_insert(struct prio_queue
*q
, struct commit
*c
, int flag
)
3658 if (c
->object
.flags
& flag
)
3661 c
->object
.flags
|= flag
;
3662 prio_queue_put(q
, c
);
3665 static void explore_walk_step(struct rev_info
*revs
)
3667 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3668 struct commit_list
*p
;
3669 struct commit
*c
= prio_queue_get(&info
->explore_queue
);
3674 if (repo_parse_commit_gently(revs
->repo
, c
, 1) < 0)
3677 count_explore_walked
++;
3679 if (revs
->sort_order
== REV_SORT_BY_AUTHOR_DATE
)
3680 record_author_date(&info
->author_date
, c
);
3682 if (revs
->max_age
!= -1 && (c
->date
< revs
->max_age
))
3683 c
->object
.flags
|= UNINTERESTING
;
3685 if (process_parents(revs
, c
, NULL
, NULL
) < 0)
3688 if (c
->object
.flags
& UNINTERESTING
)
3689 mark_parents_uninteresting(revs
, c
);
3691 for (p
= c
->parents
; p
; p
= p
->next
)
3692 test_flag_and_insert(&info
->explore_queue
, p
->item
, TOPO_WALK_EXPLORED
);
3695 static void explore_to_depth(struct rev_info
*revs
,
3696 timestamp_t gen_cutoff
)
3698 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3700 while ((c
= prio_queue_peek(&info
->explore_queue
)) &&
3701 commit_graph_generation(c
) >= gen_cutoff
)
3702 explore_walk_step(revs
);
3705 static void indegree_walk_step(struct rev_info
*revs
)
3707 struct commit_list
*p
;
3708 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3709 struct commit
*c
= prio_queue_get(&info
->indegree_queue
);
3714 if (repo_parse_commit_gently(revs
->repo
, c
, 1) < 0)
3717 count_indegree_walked
++;
3719 explore_to_depth(revs
, commit_graph_generation(c
));
3721 for (p
= c
->parents
; p
; p
= p
->next
) {
3722 struct commit
*parent
= p
->item
;
3723 int *pi
= indegree_slab_at(&info
->indegree
, parent
);
3725 if (repo_parse_commit_gently(revs
->repo
, parent
, 1) < 0)
3733 test_flag_and_insert(&info
->indegree_queue
, parent
, TOPO_WALK_INDEGREE
);
3735 if (revs
->first_parent_only
)
3740 static void compute_indegrees_to_depth(struct rev_info
*revs
,
3741 timestamp_t gen_cutoff
)
3743 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3745 while ((c
= prio_queue_peek(&info
->indegree_queue
)) &&
3746 commit_graph_generation(c
) >= gen_cutoff
)
3747 indegree_walk_step(revs
);
3750 static void release_revisions_topo_walk_info(struct topo_walk_info
*info
)
3754 clear_prio_queue(&info
->explore_queue
);
3755 clear_prio_queue(&info
->indegree_queue
);
3756 clear_prio_queue(&info
->topo_queue
);
3757 clear_indegree_slab(&info
->indegree
);
3758 clear_author_date_slab(&info
->author_date
);
3762 static void reset_topo_walk(struct rev_info
*revs
)
3764 release_revisions_topo_walk_info(revs
->topo_walk_info
);
3765 revs
->topo_walk_info
= NULL
;
3768 static void init_topo_walk(struct rev_info
*revs
)
3770 struct topo_walk_info
*info
;
3771 struct commit_list
*list
;
3772 if (revs
->topo_walk_info
)
3773 reset_topo_walk(revs
);
3775 revs
->topo_walk_info
= xmalloc(sizeof(struct topo_walk_info
));
3776 info
= revs
->topo_walk_info
;
3777 memset(info
, 0, sizeof(struct topo_walk_info
));
3779 init_indegree_slab(&info
->indegree
);
3780 memset(&info
->explore_queue
, 0, sizeof(info
->explore_queue
));
3781 memset(&info
->indegree_queue
, 0, sizeof(info
->indegree_queue
));
3782 memset(&info
->topo_queue
, 0, sizeof(info
->topo_queue
));
3784 switch (revs
->sort_order
) {
3785 default: /* REV_SORT_IN_GRAPH_ORDER */
3786 info
->topo_queue
.compare
= NULL
;
3788 case REV_SORT_BY_COMMIT_DATE
:
3789 info
->topo_queue
.compare
= compare_commits_by_commit_date
;
3791 case REV_SORT_BY_AUTHOR_DATE
:
3792 init_author_date_slab(&info
->author_date
);
3793 info
->topo_queue
.compare
= compare_commits_by_author_date
;
3794 info
->topo_queue
.cb_data
= &info
->author_date
;
3798 info
->explore_queue
.compare
= compare_commits_by_gen_then_commit_date
;
3799 info
->indegree_queue
.compare
= compare_commits_by_gen_then_commit_date
;
3801 info
->min_generation
= GENERATION_NUMBER_INFINITY
;
3802 for (list
= revs
->commits
; list
; list
= list
->next
) {
3803 struct commit
*c
= list
->item
;
3804 timestamp_t generation
;
3806 if (repo_parse_commit_gently(revs
->repo
, c
, 1))
3809 test_flag_and_insert(&info
->explore_queue
, c
, TOPO_WALK_EXPLORED
);
3810 test_flag_and_insert(&info
->indegree_queue
, c
, TOPO_WALK_INDEGREE
);
3812 generation
= commit_graph_generation(c
);
3813 if (generation
< info
->min_generation
)
3814 info
->min_generation
= generation
;
3816 *(indegree_slab_at(&info
->indegree
, c
)) = 1;
3818 if (revs
->sort_order
== REV_SORT_BY_AUTHOR_DATE
)
3819 record_author_date(&info
->author_date
, c
);
3821 compute_indegrees_to_depth(revs
, info
->min_generation
);
3823 for (list
= revs
->commits
; list
; list
= list
->next
) {
3824 struct commit
*c
= list
->item
;
3826 if (*(indegree_slab_at(&info
->indegree
, c
)) == 1)
3827 prio_queue_put(&info
->topo_queue
, c
);
3831 * This is unfortunate; the initial tips need to be shown
3832 * in the order given from the revision traversal machinery.
3834 if (revs
->sort_order
== REV_SORT_IN_GRAPH_ORDER
)
3835 prio_queue_reverse(&info
->topo_queue
);
3837 if (trace2_is_enabled() && !topo_walk_atexit_registered
) {
3838 atexit(trace2_topo_walk_statistics_atexit
);
3839 topo_walk_atexit_registered
= 1;
3843 static struct commit
*next_topo_commit(struct rev_info
*revs
)
3846 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3848 /* pop next off of topo_queue */
3849 c
= prio_queue_get(&info
->topo_queue
);
3852 *(indegree_slab_at(&info
->indegree
, c
)) = 0;
3857 static void expand_topo_walk(struct rev_info
*revs
, struct commit
*commit
)
3859 struct commit_list
*p
;
3860 struct topo_walk_info
*info
= revs
->topo_walk_info
;
3861 if (process_parents(revs
, commit
, NULL
, NULL
) < 0) {
3862 if (!revs
->ignore_missing_links
)
3863 die("Failed to traverse parents of commit %s",
3864 oid_to_hex(&commit
->object
.oid
));
3867 count_topo_walked
++;
3869 for (p
= commit
->parents
; p
; p
= p
->next
) {
3870 struct commit
*parent
= p
->item
;
3872 timestamp_t generation
;
3874 if (parent
->object
.flags
& UNINTERESTING
)
3877 if (repo_parse_commit_gently(revs
->repo
, parent
, 1) < 0)
3880 generation
= commit_graph_generation(parent
);
3881 if (generation
< info
->min_generation
) {
3882 info
->min_generation
= generation
;
3883 compute_indegrees_to_depth(revs
, info
->min_generation
);
3886 pi
= indegree_slab_at(&info
->indegree
, parent
);
3890 prio_queue_put(&info
->topo_queue
, parent
);
3892 if (revs
->first_parent_only
)
3897 int prepare_revision_walk(struct rev_info
*revs
)
3900 struct object_array old_pending
;
3901 struct commit_list
**next
= &revs
->commits
;
3903 memcpy(&old_pending
, &revs
->pending
, sizeof(old_pending
));
3904 revs
->pending
.nr
= 0;
3905 revs
->pending
.alloc
= 0;
3906 revs
->pending
.objects
= NULL
;
3907 for (i
= 0; i
< old_pending
.nr
; i
++) {
3908 struct object_array_entry
*e
= old_pending
.objects
+ i
;
3909 struct commit
*commit
= handle_commit(revs
, e
);
3911 if (!(commit
->object
.flags
& SEEN
)) {
3912 commit
->object
.flags
|= SEEN
;
3913 next
= commit_list_append(commit
, next
);
3917 object_array_clear(&old_pending
);
3919 /* Signal whether we need per-parent treesame decoration */
3920 if (revs
->simplify_merges
||
3921 (revs
->limited
&& limiting_can_increase_treesame(revs
)))
3922 revs
->treesame
.name
= "treesame";
3924 if (revs
->exclude_promisor_objects
) {
3925 for_each_packed_object(revs
->repo
, mark_uninteresting
, revs
,
3926 FOR_EACH_OBJECT_PROMISOR_ONLY
);
3929 if (!revs
->reflog_info
)
3930 prepare_to_use_bloom_filter(revs
);
3931 if (!revs
->unsorted_input
)
3932 commit_list_sort_by_date(&revs
->commits
);
3935 if (revs
->limited
) {
3936 if (limit_list(revs
) < 0)
3938 if (revs
->topo_order
)
3939 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
3940 } else if (revs
->topo_order
)
3941 init_topo_walk(revs
);
3942 if (revs
->line_level_traverse
&& want_ancestry(revs
))
3944 * At the moment we can only do line-level log with parent
3945 * rewriting by performing this expensive pre-filtering step.
3946 * If parent rewriting is not requested, then we rather
3947 * perform the line-level log filtering during the regular
3948 * history traversal.
3950 line_log_filter(revs
);
3951 if (revs
->simplify_merges
)
3952 simplify_merges(revs
);
3953 if (revs
->children
.name
)
3959 static enum rewrite_result
rewrite_one_1(struct rev_info
*revs
,
3961 struct prio_queue
*queue
)
3964 struct commit
*p
= *pp
;
3966 if (process_parents(revs
, p
, NULL
, queue
) < 0)
3967 return rewrite_one_error
;
3968 if (p
->object
.flags
& UNINTERESTING
)
3969 return rewrite_one_ok
;
3970 if (!(p
->object
.flags
& TREESAME
))
3971 return rewrite_one_ok
;
3973 return rewrite_one_noparents
;
3974 if (!(p
= one_relevant_parent(revs
, p
->parents
)))
3975 return rewrite_one_ok
;
3980 static void merge_queue_into_list(struct prio_queue
*q
, struct commit_list
**list
)
3983 struct commit
*item
= prio_queue_peek(q
);
3984 struct commit_list
*p
= *list
;
3986 if (p
&& p
->item
->date
>= item
->date
)
3989 p
= commit_list_insert(item
, list
);
3990 list
= &p
->next
; /* skip newly added item */
3991 prio_queue_get(q
); /* pop item */
3996 static enum rewrite_result
rewrite_one(struct rev_info
*revs
, struct commit
**pp
)
3998 struct prio_queue queue
= { compare_commits_by_commit_date
};
3999 enum rewrite_result ret
= rewrite_one_1(revs
, pp
, &queue
);
4000 merge_queue_into_list(&queue
, &revs
->commits
);
4001 clear_prio_queue(&queue
);
4005 int rewrite_parents(struct rev_info
*revs
, struct commit
*commit
,
4006 rewrite_parent_fn_t rewrite_parent
)
4008 struct commit_list
**pp
= &commit
->parents
;
4010 struct commit_list
*parent
= *pp
;
4011 switch (rewrite_parent(revs
, &parent
->item
)) {
4012 case rewrite_one_ok
:
4014 case rewrite_one_noparents
:
4018 case rewrite_one_error
:
4023 remove_duplicate_parents(revs
, commit
);
4027 static int commit_match(struct commit
*commit
, struct rev_info
*opt
)
4030 const char *encoding
;
4031 const char *message
;
4032 struct strbuf buf
= STRBUF_INIT
;
4034 if (!opt
->grep_filter
.pattern_list
&& !opt
->grep_filter
.header_list
)
4037 /* Prepend "fake" headers as needed */
4038 if (opt
->grep_filter
.use_reflog_filter
) {
4039 strbuf_addstr(&buf
, "reflog ");
4040 get_reflog_message(&buf
, opt
->reflog_info
);
4041 strbuf_addch(&buf
, '\n');
4045 * We grep in the user's output encoding, under the assumption that it
4046 * is the encoding they are most likely to write their grep pattern
4047 * for. In addition, it means we will match the "notes" encoding below,
4048 * so we will not end up with a buffer that has two different encodings
4051 encoding
= get_log_output_encoding();
4052 message
= repo_logmsg_reencode(the_repository
, commit
, NULL
, encoding
);
4054 /* Copy the commit to temporary if we are using "fake" headers */
4056 strbuf_addstr(&buf
, message
);
4058 if (opt
->grep_filter
.header_list
&& opt
->mailmap
) {
4059 const char *commit_headers
[] = { "author ", "committer ", NULL
};
4062 strbuf_addstr(&buf
, message
);
4064 apply_mailmap_to_header(&buf
, commit_headers
, opt
->mailmap
);
4067 /* Append "fake" message parts as needed */
4068 if (opt
->show_notes
) {
4070 strbuf_addstr(&buf
, message
);
4071 format_display_notes(&commit
->object
.oid
, &buf
, encoding
, 1);
4075 * Find either in the original commit message, or in the temporary.
4076 * Note that we cast away the constness of "message" here. It is
4077 * const because it may come from the cached commit buffer. That's OK,
4078 * because we know that it is modifiable heap memory, and that while
4079 * grep_buffer may modify it for speed, it will restore any
4080 * changes before returning.
4083 retval
= grep_buffer(&opt
->grep_filter
, buf
.buf
, buf
.len
);
4085 retval
= grep_buffer(&opt
->grep_filter
,
4086 (char *)message
, strlen(message
));
4087 strbuf_release(&buf
);
4088 repo_unuse_commit_buffer(the_repository
, commit
, message
);
4092 static inline int want_ancestry(const struct rev_info
*revs
)
4094 return (revs
->rewrite_parents
|| revs
->children
.name
);
4098 * Return a timestamp to be used for --since/--until comparisons for this
4099 * commit, based on the revision options.
4101 static timestamp_t
comparison_date(const struct rev_info
*revs
,
4102 struct commit
*commit
)
4104 return revs
->reflog_info
?
4105 get_reflog_timestamp(revs
->reflog_info
) :
4109 enum commit_action
get_commit_action(struct rev_info
*revs
, struct commit
*commit
)
4111 if (commit
->object
.flags
& SHOWN
)
4112 return commit_ignore
;
4113 if (revs
->unpacked
&& has_object_pack(revs
->repo
, &commit
->object
.oid
))
4114 return commit_ignore
;
4115 if (revs
->no_kept_objects
) {
4116 if (has_object_kept_pack(revs
->repo
, &commit
->object
.oid
,
4117 revs
->keep_pack_cache_flags
))
4118 return commit_ignore
;
4120 if (commit
->object
.flags
& UNINTERESTING
)
4121 return commit_ignore
;
4122 if (revs
->line_level_traverse
&& !want_ancestry(revs
)) {
4124 * In case of line-level log with parent rewriting
4125 * prepare_revision_walk() already took care of all line-level
4126 * log filtering, and there is nothing left to do here.
4128 * If parent rewriting was not requested, then this is the
4129 * place to perform the line-level log filtering. Notably,
4130 * this check, though expensive, must come before the other,
4131 * cheaper filtering conditions, because the tracked line
4132 * ranges must be adjusted even when the commit will end up
4133 * being ignored based on other conditions.
4135 if (!line_log_process_ranges_arbitrary_commit(revs
, commit
))
4136 return commit_ignore
;
4138 if (revs
->min_age
!= -1 &&
4139 comparison_date(revs
, commit
) > revs
->min_age
)
4140 return commit_ignore
;
4141 if (revs
->max_age_as_filter
!= -1 &&
4142 comparison_date(revs
, commit
) < revs
->max_age_as_filter
)
4143 return commit_ignore
;
4144 if (revs
->min_parents
|| (revs
->max_parents
>= 0)) {
4145 int n
= commit_list_count(commit
->parents
);
4146 if ((n
< revs
->min_parents
) ||
4147 ((revs
->max_parents
>= 0) && (n
> revs
->max_parents
)))
4148 return commit_ignore
;
4150 if (!commit_match(commit
, revs
))
4151 return commit_ignore
;
4152 if (revs
->prune
&& revs
->dense
) {
4153 /* Commit without changes? */
4154 if (commit
->object
.flags
& TREESAME
) {
4156 struct commit_list
*p
;
4157 /* drop merges unless we want parenthood */
4158 if (!want_ancestry(revs
))
4159 return commit_ignore
;
4161 if (revs
->show_pulls
&& (commit
->object
.flags
& PULL_MERGE
))
4165 * If we want ancestry, then need to keep any merges
4166 * between relevant commits to tie together topology.
4167 * For consistency with TREESAME and simplification
4168 * use "relevant" here rather than just INTERESTING,
4169 * to treat bottom commit(s) as part of the topology.
4171 for (n
= 0, p
= commit
->parents
; p
; p
= p
->next
)
4172 if (relevant_commit(p
->item
))
4175 return commit_ignore
;
4181 define_commit_slab(saved_parents
, struct commit_list
*);
4183 #define EMPTY_PARENT_LIST ((struct commit_list *)-1)
4186 * You may only call save_parents() once per commit (this is checked
4187 * for non-root commits).
4189 static void save_parents(struct rev_info
*revs
, struct commit
*commit
)
4191 struct commit_list
**pp
;
4193 if (!revs
->saved_parents_slab
) {
4194 revs
->saved_parents_slab
= xmalloc(sizeof(struct saved_parents
));
4195 init_saved_parents(revs
->saved_parents_slab
);
4198 pp
= saved_parents_at(revs
->saved_parents_slab
, commit
);
4201 * When walking with reflogs, we may visit the same commit
4202 * several times: once for each appearance in the reflog.
4204 * In this case, save_parents() will be called multiple times.
4205 * We want to keep only the first set of parents. We need to
4206 * store a sentinel value for an empty (i.e., NULL) parent
4207 * list to distinguish it from a not-yet-saved list, however.
4211 if (commit
->parents
)
4212 *pp
= copy_commit_list(commit
->parents
);
4214 *pp
= EMPTY_PARENT_LIST
;
4217 static void free_saved_parent(struct commit_list
**parents
)
4219 if (*parents
!= EMPTY_PARENT_LIST
)
4220 free_commit_list(*parents
);
4223 static void free_saved_parents(struct rev_info
*revs
)
4225 if (!revs
->saved_parents_slab
)
4227 deep_clear_saved_parents(revs
->saved_parents_slab
, free_saved_parent
);
4228 FREE_AND_NULL(revs
->saved_parents_slab
);
4231 struct commit_list
*get_saved_parents(struct rev_info
*revs
, const struct commit
*commit
)
4233 struct commit_list
*parents
;
4235 if (!revs
->saved_parents_slab
)
4236 return commit
->parents
;
4238 parents
= *saved_parents_at(revs
->saved_parents_slab
, commit
);
4239 if (parents
== EMPTY_PARENT_LIST
)
4244 enum commit_action
simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
4246 enum commit_action action
= get_commit_action(revs
, commit
);
4248 if (action
== commit_show
&&
4249 revs
->prune
&& revs
->dense
&& want_ancestry(revs
)) {
4251 * --full-diff on simplified parents is no good: it
4252 * will show spurious changes from the commits that
4253 * were elided. So we save the parents on the side
4254 * when --full-diff is in effect.
4256 if (revs
->full_diff
)
4257 save_parents(revs
, commit
);
4258 if (rewrite_parents(revs
, commit
, rewrite_one
) < 0)
4259 return commit_error
;
4264 static void track_linear(struct rev_info
*revs
, struct commit
*commit
)
4266 if (revs
->track_first_time
) {
4268 revs
->track_first_time
= 0;
4270 struct commit_list
*p
;
4271 for (p
= revs
->previous_parents
; p
; p
= p
->next
)
4272 if (p
->item
== NULL
|| /* first commit */
4273 oideq(&p
->item
->object
.oid
, &commit
->object
.oid
))
4275 revs
->linear
= p
!= NULL
;
4277 if (revs
->reverse
) {
4279 commit
->object
.flags
|= TRACK_LINEAR
;
4281 free_commit_list(revs
->previous_parents
);
4282 revs
->previous_parents
= copy_commit_list(commit
->parents
);
4285 static struct commit
*get_revision_1(struct rev_info
*revs
)
4288 struct commit
*commit
;
4290 if (revs
->reflog_info
)
4291 commit
= next_reflog_entry(revs
->reflog_info
);
4292 else if (revs
->topo_walk_info
)
4293 commit
= next_topo_commit(revs
);
4295 commit
= pop_commit(&revs
->commits
);
4300 if (revs
->reflog_info
)
4301 commit
->object
.flags
&= ~(ADDED
| SEEN
| SHOWN
);
4304 * If we haven't done the list limiting, we need to look at
4305 * the parents here. We also need to do the date-based limiting
4306 * that we'd otherwise have done in limit_list().
4308 if (!revs
->limited
) {
4309 if (revs
->max_age
!= -1 &&
4310 comparison_date(revs
, commit
) < revs
->max_age
)
4313 if (revs
->reflog_info
)
4314 try_to_simplify_commit(revs
, commit
);
4315 else if (revs
->topo_walk_info
)
4316 expand_topo_walk(revs
, commit
);
4317 else if (process_parents(revs
, commit
, &revs
->commits
, NULL
) < 0) {
4318 if (!revs
->ignore_missing_links
)
4319 die("Failed to traverse parents of commit %s",
4320 oid_to_hex(&commit
->object
.oid
));
4324 switch (simplify_commit(revs
, commit
)) {
4328 die("Failed to simplify parents of commit %s",
4329 oid_to_hex(&commit
->object
.oid
));
4331 if (revs
->track_linear
)
4332 track_linear(revs
, commit
);
4339 * Return true for entries that have not yet been shown. (This is an
4340 * object_array_each_func_t.)
4342 static int entry_unshown(struct object_array_entry
*entry
, void *cb_data UNUSED
)
4344 return !(entry
->item
->flags
& SHOWN
);
4348 * If array is on the verge of a realloc, garbage-collect any entries
4349 * that have already been shown to try to free up some space.
4351 static void gc_boundary(struct object_array
*array
)
4353 if (array
->nr
== array
->alloc
)
4354 object_array_filter(array
, entry_unshown
, NULL
);
4357 static void create_boundary_commit_list(struct rev_info
*revs
)
4361 struct object_array
*array
= &revs
->boundary_commits
;
4362 struct object_array_entry
*objects
= array
->objects
;
4365 * If revs->commits is non-NULL at this point, an error occurred in
4366 * get_revision_1(). Ignore the error and continue printing the
4367 * boundary commits anyway. (This is what the code has always
4370 free_commit_list(revs
->commits
);
4371 revs
->commits
= NULL
;
4374 * Put all of the actual boundary commits from revs->boundary_commits
4375 * into revs->commits
4377 for (i
= 0; i
< array
->nr
; i
++) {
4378 c
= (struct commit
*)(objects
[i
].item
);
4381 if (!(c
->object
.flags
& CHILD_SHOWN
))
4383 if (c
->object
.flags
& (SHOWN
| BOUNDARY
))
4385 c
->object
.flags
|= BOUNDARY
;
4386 commit_list_insert(c
, &revs
->commits
);
4390 * If revs->topo_order is set, sort the boundary commits
4391 * in topological order
4393 sort_in_topological_order(&revs
->commits
, revs
->sort_order
);
4396 static struct commit
*get_revision_internal(struct rev_info
*revs
)
4398 struct commit
*c
= NULL
;
4399 struct commit_list
*l
;
4401 if (revs
->boundary
== 2) {
4403 * All of the normal commits have already been returned,
4404 * and we are now returning boundary commits.
4405 * create_boundary_commit_list() has populated
4406 * revs->commits with the remaining commits to return.
4408 c
= pop_commit(&revs
->commits
);
4410 c
->object
.flags
|= SHOWN
;
4415 * If our max_count counter has reached zero, then we are done. We
4416 * don't simply return NULL because we still might need to show
4417 * boundary commits. But we want to avoid calling get_revision_1, which
4418 * might do a considerable amount of work finding the next commit only
4419 * for us to throw it away.
4421 * If it is non-zero, then either we don't have a max_count at all
4422 * (-1), or it is still counting, in which case we decrement.
4424 if (revs
->max_count
) {
4425 c
= get_revision_1(revs
);
4427 while (revs
->skip_count
> 0) {
4429 c
= get_revision_1(revs
);
4432 free_commit_buffer(revs
->repo
->parsed_objects
, c
);
4436 if (revs
->max_count
> 0)
4441 c
->object
.flags
|= SHOWN
;
4443 if (!revs
->boundary
)
4448 * get_revision_1() runs out the commits, and
4449 * we are done computing the boundaries.
4450 * switch to boundary commits output mode.
4455 * Update revs->commits to contain the list of
4458 create_boundary_commit_list(revs
);
4460 return get_revision_internal(revs
);
4464 * boundary commits are the commits that are parents of the
4465 * ones we got from get_revision_1() but they themselves are
4466 * not returned from get_revision_1(). Before returning
4467 * 'c', we need to mark its parents that they could be boundaries.
4470 for (l
= c
->parents
; l
; l
= l
->next
) {
4472 p
= &(l
->item
->object
);
4473 if (p
->flags
& (CHILD_SHOWN
| SHOWN
))
4475 p
->flags
|= CHILD_SHOWN
;
4476 gc_boundary(&revs
->boundary_commits
);
4477 add_object_array(p
, NULL
, &revs
->boundary_commits
);
4483 struct commit
*get_revision(struct rev_info
*revs
)
4486 struct commit_list
*reversed
;
4488 if (revs
->reverse
) {
4490 while ((c
= get_revision_internal(revs
)))
4491 commit_list_insert(c
, &reversed
);
4492 free_commit_list(revs
->commits
);
4493 revs
->commits
= reversed
;
4495 revs
->reverse_output_stage
= 1;
4498 if (revs
->reverse_output_stage
) {
4499 c
= pop_commit(&revs
->commits
);
4500 if (revs
->track_linear
)
4501 revs
->linear
= !!(c
&& c
->object
.flags
& TRACK_LINEAR
);
4505 c
= get_revision_internal(revs
);
4506 if (c
&& revs
->graph
)
4507 graph_update(revs
->graph
, c
);
4509 free_saved_parents(revs
);
4510 free_commit_list(revs
->previous_parents
);
4511 revs
->previous_parents
= NULL
;
4516 const char *get_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
4518 if (commit
->object
.flags
& BOUNDARY
)
4520 else if (commit
->object
.flags
& UNINTERESTING
)
4522 else if (commit
->object
.flags
& PATCHSAME
)
4524 else if (!revs
|| revs
->left_right
) {
4525 if (commit
->object
.flags
& SYMMETRIC_LEFT
)
4529 } else if (revs
->graph
)
4531 else if (revs
->cherry_mark
)
4536 void put_revision_mark(const struct rev_info
*revs
, const struct commit
*commit
)
4538 const char *mark
= get_revision_mark(revs
, commit
);
4541 fputs(mark
, stdout
);