10 #include "reflog-walk.h"
12 static char *path_name(struct name_path
*path
, const char *name
)
16 int nlen
= strlen(name
);
19 for (p
= path
; p
; p
= p
->up
) {
21 len
+= p
->elem_len
+ 1;
24 m
= n
+ len
- (nlen
+ 1);
26 for (p
= path
; p
; p
= p
->up
) {
29 memcpy(m
, p
->elem
, p
->elem_len
);
36 void add_object(struct object
*obj
,
37 struct object_array
*p
,
38 struct name_path
*path
,
41 add_object_array(obj
, path_name(path
, name
), p
);
44 static void mark_blob_uninteresting(struct blob
*blob
)
46 if (blob
->object
.flags
& UNINTERESTING
)
48 blob
->object
.flags
|= UNINTERESTING
;
51 void mark_tree_uninteresting(struct tree
*tree
)
53 struct tree_desc desc
;
54 struct name_entry entry
;
55 struct object
*obj
= &tree
->object
;
57 if (obj
->flags
& UNINTERESTING
)
59 obj
->flags
|= UNINTERESTING
;
60 if (!has_sha1_file(obj
->sha1
))
62 if (parse_tree(tree
) < 0)
63 die("bad tree %s", sha1_to_hex(obj
->sha1
));
65 desc
.buf
= tree
->buffer
;
66 desc
.size
= tree
->size
;
67 while (tree_entry(&desc
, &entry
)) {
68 if (S_ISDIR(entry
.mode
))
69 mark_tree_uninteresting(lookup_tree(entry
.sha1
));
71 mark_blob_uninteresting(lookup_blob(entry
.sha1
));
75 * We don't care about the tree any more
76 * after it has been marked uninteresting.
82 void mark_parents_uninteresting(struct commit
*commit
)
84 struct commit_list
*parents
= commit
->parents
;
87 struct commit
*commit
= parents
->item
;
88 if (!(commit
->object
.flags
& UNINTERESTING
)) {
89 commit
->object
.flags
|= UNINTERESTING
;
92 * Normally we haven't parsed the parent
93 * yet, so we won't have a parent of a parent
94 * here. However, it may turn out that we've
95 * reached this commit some other way (where it
96 * wasn't uninteresting), in which case we need
97 * to mark its parents recursively too..
100 mark_parents_uninteresting(commit
);
104 * A missing commit is ok iff its parent is marked
107 * We just mark such a thing parsed, so that when
108 * it is popped next time around, we won't be trying
109 * to parse it and get an error.
111 if (!has_sha1_file(commit
->object
.sha1
))
112 commit
->object
.parsed
= 1;
113 parents
= parents
->next
;
117 void add_pending_object(struct rev_info
*revs
, struct object
*obj
, const char *name
)
119 add_object_array(obj
, name
, &revs
->pending
);
120 if (revs
->reflog_info
&& obj
->type
== OBJ_COMMIT
)
121 add_reflog_for_walk(revs
->reflog_info
,
122 (struct commit
*)obj
, name
);
125 static struct object
*get_reference(struct rev_info
*revs
, const char *name
, const unsigned char *sha1
, unsigned int flags
)
127 struct object
*object
;
129 object
= parse_object(sha1
);
131 die("bad object %s", name
);
132 object
->flags
|= flags
;
136 static struct commit
*handle_commit(struct rev_info
*revs
, struct object
*object
, const char *name
)
138 unsigned long flags
= object
->flags
;
141 * Tag object? Look what it points to..
143 while (object
->type
== OBJ_TAG
) {
144 struct tag
*tag
= (struct tag
*) object
;
145 if (revs
->tag_objects
&& !(flags
& UNINTERESTING
))
146 add_pending_object(revs
, object
, tag
->tag
);
147 object
= parse_object(tag
->tagged
->sha1
);
149 die("bad object %s", sha1_to_hex(tag
->tagged
->sha1
));
153 * Commit object? Just return it, we'll do all the complex
156 if (object
->type
== OBJ_COMMIT
) {
157 struct commit
*commit
= (struct commit
*)object
;
158 if (parse_commit(commit
) < 0)
159 die("unable to parse commit %s", name
);
160 if (flags
& UNINTERESTING
) {
161 commit
->object
.flags
|= UNINTERESTING
;
162 mark_parents_uninteresting(commit
);
169 * Tree object? Either mark it uniniteresting, or add it
170 * to the list of objects to look at later..
172 if (object
->type
== OBJ_TREE
) {
173 struct tree
*tree
= (struct tree
*)object
;
174 if (!revs
->tree_objects
)
176 if (flags
& UNINTERESTING
) {
177 mark_tree_uninteresting(tree
);
180 add_pending_object(revs
, object
, "");
185 * Blob object? You know the drill by now..
187 if (object
->type
== OBJ_BLOB
) {
188 struct blob
*blob
= (struct blob
*)object
;
189 if (!revs
->blob_objects
)
191 if (flags
& UNINTERESTING
) {
192 mark_blob_uninteresting(blob
);
195 add_pending_object(revs
, object
, "");
198 die("%s is unknown object", name
);
201 static int everybody_uninteresting(struct commit_list
*orig
)
203 struct commit_list
*list
= orig
;
205 struct commit
*commit
= list
->item
;
207 if (commit
->object
.flags
& UNINTERESTING
)
214 static int tree_difference
= REV_TREE_SAME
;
216 static void file_add_remove(struct diff_options
*options
,
217 int addremove
, unsigned mode
,
218 const unsigned char *sha1
,
219 const char *base
, const char *path
)
221 int diff
= REV_TREE_DIFFERENT
;
224 * Is it an add of a new file? It means that the old tree
225 * didn't have it at all, so we will turn "REV_TREE_SAME" ->
226 * "REV_TREE_NEW", but leave any "REV_TREE_DIFFERENT" alone
227 * (and if it already was "REV_TREE_NEW", we'll keep it
228 * "REV_TREE_NEW" of course).
230 if (addremove
== '+') {
231 diff
= tree_difference
;
232 if (diff
!= REV_TREE_SAME
)
236 tree_difference
= diff
;
239 static void file_change(struct diff_options
*options
,
240 unsigned old_mode
, unsigned new_mode
,
241 const unsigned char *old_sha1
,
242 const unsigned char *new_sha1
,
243 const char *base
, const char *path
)
245 tree_difference
= REV_TREE_DIFFERENT
;
248 int rev_compare_tree(struct rev_info
*revs
, struct tree
*t1
, struct tree
*t2
)
253 return REV_TREE_DIFFERENT
;
254 tree_difference
= REV_TREE_SAME
;
255 if (diff_tree_sha1(t1
->object
.sha1
, t2
->object
.sha1
, "",
257 return REV_TREE_DIFFERENT
;
258 return tree_difference
;
261 int rev_same_tree_as_empty(struct rev_info
*revs
, struct tree
*t1
)
265 struct tree_desc empty
, real
;
270 tree
= read_object_with_reference(t1
->object
.sha1
, tree_type
, &real
.size
, NULL
);
279 retval
= diff_tree(&empty
, &real
, "", &revs
->pruning
);
282 return retval
>= 0 && !tree_difference
;
285 static void try_to_simplify_commit(struct rev_info
*revs
, struct commit
*commit
)
287 struct commit_list
**pp
, *parent
;
288 int tree_changed
= 0, tree_same
= 0;
293 if (!commit
->parents
) {
294 if (!rev_same_tree_as_empty(revs
, commit
->tree
))
295 commit
->object
.flags
|= TREECHANGE
;
299 pp
= &commit
->parents
;
300 while ((parent
= *pp
) != NULL
) {
301 struct commit
*p
= parent
->item
;
304 switch (rev_compare_tree(revs
, p
->tree
, commit
->tree
)) {
307 if (!revs
->simplify_history
|| (p
->object
.flags
& UNINTERESTING
)) {
308 /* Even if a merge with an uninteresting
309 * side branch brought the entire change
310 * we are interested in, we do not want
311 * to lose the other branches of this
312 * merge, so we just keep going.
318 commit
->parents
= parent
;
322 if (revs
->remove_empty_trees
&&
323 rev_same_tree_as_empty(revs
, p
->tree
)) {
324 /* We are adding all the specified
325 * paths from this parent, so the
326 * history beyond this parent is not
327 * interesting. Remove its parents
328 * (they are grandparents for us).
329 * IOW, we pretend this parent is a
336 case REV_TREE_DIFFERENT
:
341 die("bad tree compare for commit %s", sha1_to_hex(commit
->object
.sha1
));
343 if (tree_changed
&& !tree_same
)
344 commit
->object
.flags
|= TREECHANGE
;
347 static void add_parents_to_list(struct rev_info
*revs
, struct commit
*commit
, struct commit_list
**list
)
349 struct commit_list
*parent
= commit
->parents
;
352 if (commit
->object
.flags
& ADDED
)
354 commit
->object
.flags
|= ADDED
;
357 * If the commit is uninteresting, don't try to
358 * prune parents - we want the maximal uninteresting
361 * Normally we haven't parsed the parent
362 * yet, so we won't have a parent of a parent
363 * here. However, it may turn out that we've
364 * reached this commit some other way (where it
365 * wasn't uninteresting), in which case we need
366 * to mark its parents recursively too..
368 if (commit
->object
.flags
& UNINTERESTING
) {
370 struct commit
*p
= parent
->item
;
371 parent
= parent
->next
;
373 p
->object
.flags
|= UNINTERESTING
;
375 mark_parents_uninteresting(p
);
376 if (p
->object
.flags
& SEEN
)
378 p
->object
.flags
|= SEEN
;
379 insert_by_date(p
, list
);
385 * Ok, the commit wasn't uninteresting. Try to
386 * simplify the commit history and find the parent
387 * that has no differences in the path set if one exists.
390 revs
->prune_fn(revs
, commit
);
395 left_flag
= (commit
->object
.flags
& SYMMETRIC_LEFT
);
396 parent
= commit
->parents
;
398 struct commit
*p
= parent
->item
;
400 parent
= parent
->next
;
403 p
->object
.flags
|= left_flag
;
404 if (p
->object
.flags
& SEEN
)
406 p
->object
.flags
|= SEEN
;
407 insert_by_date(p
, list
);
411 static void limit_list(struct rev_info
*revs
)
413 struct commit_list
*list
= revs
->commits
;
414 struct commit_list
*newlist
= NULL
;
415 struct commit_list
**p
= &newlist
;
418 struct commit_list
*entry
= list
;
419 struct commit
*commit
= list
->item
;
420 struct object
*obj
= &commit
->object
;
425 if (revs
->max_age
!= -1 && (commit
->date
< revs
->max_age
))
426 obj
->flags
|= UNINTERESTING
;
427 add_parents_to_list(revs
, commit
, &list
);
428 if (obj
->flags
& UNINTERESTING
) {
429 mark_parents_uninteresting(commit
);
430 if (everybody_uninteresting(list
))
434 if (revs
->min_age
!= -1 && (commit
->date
> revs
->min_age
))
436 p
= &commit_list_insert(commit
, p
)->next
;
438 if (revs
->boundary
) {
439 /* mark the ones that are on the result list first */
440 for (list
= newlist
; list
; list
= list
->next
) {
441 struct commit
*commit
= list
->item
;
442 commit
->object
.flags
|= TMP_MARK
;
444 for (list
= newlist
; list
; list
= list
->next
) {
445 struct commit
*commit
= list
->item
;
446 struct object
*obj
= &commit
->object
;
447 struct commit_list
*parent
;
448 if (obj
->flags
& UNINTERESTING
)
450 for (parent
= commit
->parents
;
452 parent
= parent
->next
) {
453 struct commit
*pcommit
= parent
->item
;
454 if (!(pcommit
->object
.flags
& UNINTERESTING
))
456 pcommit
->object
.flags
|= BOUNDARY
;
457 if (pcommit
->object
.flags
& TMP_MARK
)
459 pcommit
->object
.flags
|= TMP_MARK
;
460 p
= &commit_list_insert(pcommit
, p
)->next
;
463 for (list
= newlist
; list
; list
= list
->next
) {
464 struct commit
*commit
= list
->item
;
465 commit
->object
.flags
&= ~TMP_MARK
;
468 revs
->commits
= newlist
;
473 int warned_bad_reflog
;
474 struct rev_info
*all_revs
;
475 const char *name_for_errormsg
;
478 static int handle_one_ref(const char *path
, const unsigned char *sha1
, int flag
, void *cb_data
)
480 struct all_refs_cb
*cb
= cb_data
;
481 struct object
*object
= get_reference(cb
->all_revs
, path
, sha1
,
483 add_pending_object(cb
->all_revs
, object
, "");
487 static void handle_all(struct rev_info
*revs
, unsigned flags
)
489 struct all_refs_cb cb
;
491 cb
.all_flags
= flags
;
492 for_each_ref(handle_one_ref
, &cb
);
495 static void handle_one_reflog_commit(unsigned char *sha1
, void *cb_data
)
497 struct all_refs_cb
*cb
= cb_data
;
498 if (!is_null_sha1(sha1
)) {
499 struct object
*o
= parse_object(sha1
);
501 o
->flags
|= cb
->all_flags
;
502 add_pending_object(cb
->all_revs
, o
, "");
504 else if (!cb
->warned_bad_reflog
) {
505 warn("reflog of '%s' references pruned commits",
506 cb
->name_for_errormsg
);
507 cb
->warned_bad_reflog
= 1;
512 static int handle_one_reflog_ent(unsigned char *osha1
, unsigned char *nsha1
,
513 const char *email
, unsigned long timestamp
, int tz
,
514 const char *message
, void *cb_data
)
516 handle_one_reflog_commit(osha1
, cb_data
);
517 handle_one_reflog_commit(nsha1
, cb_data
);
521 static int handle_one_reflog(const char *path
, const unsigned char *sha1
, int flag
, void *cb_data
)
523 struct all_refs_cb
*cb
= cb_data
;
524 cb
->warned_bad_reflog
= 0;
525 cb
->name_for_errormsg
= path
;
526 for_each_reflog_ent(path
, handle_one_reflog_ent
, cb_data
);
530 static void handle_reflog(struct rev_info
*revs
, unsigned flags
)
532 struct all_refs_cb cb
;
534 cb
.all_flags
= flags
;
535 for_each_ref(handle_one_reflog
, &cb
);
538 static int add_parents_only(struct rev_info
*revs
, const char *arg
, int flags
)
540 unsigned char sha1
[20];
542 struct commit
*commit
;
543 struct commit_list
*parents
;
546 flags
^= UNINTERESTING
;
549 if (get_sha1(arg
, sha1
))
552 it
= get_reference(revs
, arg
, sha1
, 0);
553 if (it
->type
!= OBJ_TAG
)
555 hashcpy(sha1
, ((struct tag
*)it
)->tagged
->sha1
);
557 if (it
->type
!= OBJ_COMMIT
)
559 commit
= (struct commit
*)it
;
560 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
561 it
= &parents
->item
->object
;
563 add_pending_object(revs
, it
, arg
);
568 void init_revisions(struct rev_info
*revs
, const char *prefix
)
570 memset(revs
, 0, sizeof(*revs
));
572 revs
->abbrev
= DEFAULT_ABBREV
;
573 revs
->ignore_merges
= 1;
574 revs
->simplify_history
= 1;
575 revs
->pruning
.recursive
= 1;
576 revs
->pruning
.add_remove
= file_add_remove
;
577 revs
->pruning
.change
= file_change
;
580 revs
->prefix
= prefix
;
583 revs
->skip_count
= -1;
584 revs
->max_count
= -1;
586 revs
->prune_fn
= NULL
;
587 revs
->prune_data
= NULL
;
589 revs
->topo_setter
= topo_sort_default_setter
;
590 revs
->topo_getter
= topo_sort_default_getter
;
592 revs
->commit_format
= CMIT_FMT_DEFAULT
;
594 diff_setup(&revs
->diffopt
);
597 static void add_pending_commit_list(struct rev_info
*revs
,
598 struct commit_list
*commit_list
,
601 while (commit_list
) {
602 struct object
*object
= &commit_list
->item
->object
;
603 object
->flags
|= flags
;
604 add_pending_object(revs
, object
, sha1_to_hex(object
->sha1
));
605 commit_list
= commit_list
->next
;
609 static void prepare_show_merge(struct rev_info
*revs
)
611 struct commit_list
*bases
;
612 struct commit
*head
, *other
;
613 unsigned char sha1
[20];
614 const char **prune
= NULL
;
615 int i
, prune_num
= 1; /* counting terminating NULL */
617 if (get_sha1("HEAD", sha1
) || !(head
= lookup_commit(sha1
)))
618 die("--merge without HEAD?");
619 if (get_sha1("MERGE_HEAD", sha1
) || !(other
= lookup_commit(sha1
)))
620 die("--merge without MERGE_HEAD?");
621 add_pending_object(revs
, &head
->object
, "HEAD");
622 add_pending_object(revs
, &other
->object
, "MERGE_HEAD");
623 bases
= get_merge_bases(head
, other
, 1);
625 struct commit
*it
= bases
->item
;
626 struct commit_list
*n
= bases
->next
;
629 it
->object
.flags
|= UNINTERESTING
;
630 add_pending_object(revs
, &it
->object
, "(merge-base)");
635 for (i
= 0; i
< active_nr
; i
++) {
636 struct cache_entry
*ce
= active_cache
[i
];
639 if (ce_path_match(ce
, revs
->prune_data
)) {
641 prune
= xrealloc(prune
, sizeof(*prune
) * prune_num
);
642 prune
[prune_num
-2] = ce
->name
;
643 prune
[prune_num
-1] = NULL
;
645 while ((i
+1 < active_nr
) &&
646 ce_same_name(ce
, active_cache
[i
+1]))
649 revs
->prune_data
= prune
;
652 int handle_revision_arg(const char *arg
, struct rev_info
*revs
,
654 int cant_be_filename
)
657 struct object
*object
;
658 unsigned char sha1
[20];
661 dotdot
= strstr(arg
, "..");
663 unsigned char from_sha1
[20];
664 const char *next
= dotdot
+ 2;
665 const char *this = arg
;
666 int symmetric
= *next
== '.';
667 unsigned int flags_exclude
= flags
^ UNINTERESTING
;
676 if (!get_sha1(this, from_sha1
) &&
677 !get_sha1(next
, sha1
)) {
678 struct commit
*a
, *b
;
679 struct commit_list
*exclude
;
681 a
= lookup_commit_reference(from_sha1
);
682 b
= lookup_commit_reference(sha1
);
685 "Invalid symmetric difference expression %s...%s" :
686 "Invalid revision range %s..%s",
690 if (!cant_be_filename
) {
692 verify_non_filename(revs
->prefix
, arg
);
696 exclude
= get_merge_bases(a
, b
, 1);
697 add_pending_commit_list(revs
, exclude
,
699 free_commit_list(exclude
);
700 a
->object
.flags
|= flags
| SYMMETRIC_LEFT
;
702 a
->object
.flags
|= flags_exclude
;
703 b
->object
.flags
|= flags
;
704 add_pending_object(revs
, &a
->object
, this);
705 add_pending_object(revs
, &b
->object
, next
);
710 dotdot
= strstr(arg
, "^@");
711 if (dotdot
&& !dotdot
[2]) {
713 if (add_parents_only(revs
, arg
, flags
))
717 dotdot
= strstr(arg
, "^!");
718 if (dotdot
&& !dotdot
[2]) {
720 if (!add_parents_only(revs
, arg
, flags
^ UNINTERESTING
))
726 local_flags
= UNINTERESTING
;
729 if (get_sha1(arg
, sha1
))
731 if (!cant_be_filename
)
732 verify_non_filename(revs
->prefix
, arg
);
733 object
= get_reference(revs
, arg
, sha1
, flags
^ local_flags
);
734 add_pending_object(revs
, object
, arg
);
738 static void add_grep(struct rev_info
*revs
, const char *ptn
, enum grep_pat_token what
)
740 if (!revs
->grep_filter
) {
741 struct grep_opt
*opt
= xcalloc(1, sizeof(*opt
));
742 opt
->status_only
= 1;
743 opt
->pattern_tail
= &(opt
->pattern_list
);
744 opt
->regflags
= REG_NEWLINE
;
745 revs
->grep_filter
= opt
;
747 append_grep_pattern(revs
->grep_filter
, ptn
,
748 "command line", 0, what
);
751 static void add_header_grep(struct rev_info
*revs
, const char *field
, const char *pattern
)
757 fldlen
= strlen(field
);
758 patlen
= strlen(pattern
);
759 pat
= xmalloc(patlen
+ fldlen
+ 10);
761 if (*pattern
== '^') {
765 sprintf(pat
, "^%s %s%s", field
, prefix
, pattern
);
766 add_grep(revs
, pat
, GREP_PATTERN_HEAD
);
769 static void add_message_grep(struct rev_info
*revs
, const char *pattern
)
771 add_grep(revs
, pattern
, GREP_PATTERN_BODY
);
774 static void add_ignore_packed(struct rev_info
*revs
, const char *name
)
776 int num
= ++revs
->num_ignore_packed
;
778 revs
->ignore_packed
= xrealloc(revs
->ignore_packed
,
779 sizeof(const char **) * (num
+ 1));
780 revs
->ignore_packed
[num
-1] = name
;
781 revs
->ignore_packed
[num
] = NULL
;
785 * Parse revision information, filling in the "rev_info" structure,
786 * and removing the used arguments from the argument list.
788 * Returns the number of arguments left that weren't recognized
789 * (which are also moved to the head of the argument list)
791 int setup_revisions(int argc
, const char **argv
, struct rev_info
*revs
, const char *def
)
793 int i
, flags
, seen_dashdash
, show_merge
;
794 const char **unrecognized
= argv
+ 1;
798 /* First, search for "--" */
800 for (i
= 1; i
< argc
; i
++) {
801 const char *arg
= argv
[i
];
802 if (strcmp(arg
, "--"))
806 revs
->prune_data
= get_pathspec(revs
->prefix
, argv
+ i
+ 1);
811 flags
= show_merge
= 0;
812 for (i
= 1; i
< argc
; i
++) {
813 const char *arg
= argv
[i
];
816 if (!strncmp(arg
, "--max-count=", 12)) {
817 revs
->max_count
= atoi(arg
+ 12);
820 if (!strncmp(arg
, "--skip=", 7)) {
821 revs
->skip_count
= atoi(arg
+ 7);
824 /* accept -<digit>, like traditional "head" */
825 if ((*arg
== '-') && isdigit(arg
[1])) {
826 revs
->max_count
= atoi(arg
+ 1);
829 if (!strcmp(arg
, "-n")) {
831 die("-n requires an argument");
832 revs
->max_count
= atoi(argv
[++i
]);
835 if (!strncmp(arg
,"-n",2)) {
836 revs
->max_count
= atoi(arg
+ 2);
839 if (!strncmp(arg
, "--max-age=", 10)) {
840 revs
->max_age
= atoi(arg
+ 10);
843 if (!strncmp(arg
, "--since=", 8)) {
844 revs
->max_age
= approxidate(arg
+ 8);
847 if (!strncmp(arg
, "--after=", 8)) {
848 revs
->max_age
= approxidate(arg
+ 8);
851 if (!strncmp(arg
, "--min-age=", 10)) {
852 revs
->min_age
= atoi(arg
+ 10);
855 if (!strncmp(arg
, "--before=", 9)) {
856 revs
->min_age
= approxidate(arg
+ 9);
859 if (!strncmp(arg
, "--until=", 8)) {
860 revs
->min_age
= approxidate(arg
+ 8);
863 if (!strcmp(arg
, "--all")) {
864 handle_all(revs
, flags
);
867 if (!strcmp(arg
, "--reflog")) {
868 handle_reflog(revs
, flags
);
871 if (!strcmp(arg
, "--walk-reflogs")) {
872 init_reflog_walk(&revs
->reflog_info
);
875 if (!strcmp(arg
, "--not")) {
876 flags
^= UNINTERESTING
;
879 if (!strcmp(arg
, "--default")) {
881 die("bad --default argument");
885 if (!strcmp(arg
, "--merge")) {
889 if (!strcmp(arg
, "--topo-order")) {
890 revs
->topo_order
= 1;
893 if (!strcmp(arg
, "--date-order")) {
895 revs
->topo_order
= 1;
898 if (!strcmp(arg
, "--parents")) {
902 if (!strcmp(arg
, "--dense")) {
906 if (!strcmp(arg
, "--sparse")) {
910 if (!strcmp(arg
, "--remove-empty")) {
911 revs
->remove_empty_trees
= 1;
914 if (!strcmp(arg
, "--no-merges")) {
918 if (!strcmp(arg
, "--boundary")) {
922 if (!strcmp(arg
, "--left-right")) {
923 revs
->left_right
= 1;
926 if (!strcmp(arg
, "--objects")) {
927 revs
->tag_objects
= 1;
928 revs
->tree_objects
= 1;
929 revs
->blob_objects
= 1;
932 if (!strcmp(arg
, "--objects-edge")) {
933 revs
->tag_objects
= 1;
934 revs
->tree_objects
= 1;
935 revs
->blob_objects
= 1;
939 if (!strcmp(arg
, "--unpacked")) {
941 free(revs
->ignore_packed
);
942 revs
->ignore_packed
= NULL
;
943 revs
->num_ignore_packed
= 0;
946 if (!strncmp(arg
, "--unpacked=", 11)) {
948 add_ignore_packed(revs
, arg
+11);
951 if (!strcmp(arg
, "-r")) {
953 revs
->diffopt
.recursive
= 1;
956 if (!strcmp(arg
, "-t")) {
958 revs
->diffopt
.recursive
= 1;
959 revs
->diffopt
.tree_in_recursive
= 1;
962 if (!strcmp(arg
, "-m")) {
963 revs
->ignore_merges
= 0;
966 if (!strcmp(arg
, "-c")) {
968 revs
->dense_combined_merges
= 0;
969 revs
->combine_merges
= 1;
972 if (!strcmp(arg
, "--cc")) {
974 revs
->dense_combined_merges
= 1;
975 revs
->combine_merges
= 1;
978 if (!strcmp(arg
, "-v")) {
979 revs
->verbose_header
= 1;
982 if (!strncmp(arg
, "--pretty", 8)) {
983 revs
->verbose_header
= 1;
984 revs
->commit_format
= get_commit_format(arg
+8);
987 if (!strcmp(arg
, "--root")) {
988 revs
->show_root_diff
= 1;
991 if (!strcmp(arg
, "--no-commit-id")) {
992 revs
->no_commit_id
= 1;
995 if (!strcmp(arg
, "--always")) {
996 revs
->always_show_header
= 1;
999 if (!strcmp(arg
, "--no-abbrev")) {
1003 if (!strcmp(arg
, "--abbrev")) {
1004 revs
->abbrev
= DEFAULT_ABBREV
;
1007 if (!strncmp(arg
, "--abbrev=", 9)) {
1008 revs
->abbrev
= strtoul(arg
+ 9, NULL
, 10);
1009 if (revs
->abbrev
< MINIMUM_ABBREV
)
1010 revs
->abbrev
= MINIMUM_ABBREV
;
1011 else if (revs
->abbrev
> 40)
1015 if (!strcmp(arg
, "--abbrev-commit")) {
1016 revs
->abbrev_commit
= 1;
1019 if (!strcmp(arg
, "--full-diff")) {
1021 revs
->full_diff
= 1;
1024 if (!strcmp(arg
, "--full-history")) {
1025 revs
->simplify_history
= 0;
1028 if (!strcmp(arg
, "--relative-date")) {
1029 revs
->relative_date
= 1;
1034 * Grepping the commit log
1036 if (!strncmp(arg
, "--author=", 9)) {
1037 add_header_grep(revs
, "author", arg
+9);
1040 if (!strncmp(arg
, "--committer=", 12)) {
1041 add_header_grep(revs
, "committer", arg
+12);
1044 if (!strncmp(arg
, "--grep=", 7)) {
1045 add_message_grep(revs
, arg
+7);
1048 if (!strcmp(arg
, "--all-match")) {
1052 if (!strncmp(arg
, "--encoding=", 11)) {
1054 if (strcmp(arg
, "none"))
1055 git_log_output_encoding
= strdup(arg
);
1057 git_log_output_encoding
= "";
1060 if (!strcmp(arg
, "--reverse")) {
1065 opts
= diff_opt_parse(&revs
->diffopt
, argv
+i
, argc
-i
);
1071 *unrecognized
++ = arg
;
1076 if (handle_revision_arg(arg
, revs
, flags
, seen_dashdash
)) {
1078 if (seen_dashdash
|| *arg
== '^')
1079 die("bad revision '%s'", arg
);
1081 /* If we didn't have a "--":
1082 * (1) all filenames must exist;
1083 * (2) all rev-args must not be interpretable
1084 * as a valid filename.
1085 * but the latter we have checked in the main loop.
1087 for (j
= i
; j
< argc
; j
++)
1088 verify_filename(revs
->prefix
, argv
[j
]);
1090 revs
->prune_data
= get_pathspec(revs
->prefix
,
1097 prepare_show_merge(revs
);
1098 if (def
&& !revs
->pending
.nr
) {
1099 unsigned char sha1
[20];
1100 struct object
*object
;
1101 if (get_sha1(def
, sha1
))
1102 die("bad default revision '%s'", def
);
1103 object
= get_reference(revs
, def
, sha1
, 0);
1104 add_pending_object(revs
, object
, def
);
1107 if (revs
->topo_order
)
1110 if (revs
->prune_data
) {
1111 diff_tree_setup_paths(revs
->prune_data
, &revs
->pruning
);
1112 revs
->prune_fn
= try_to_simplify_commit
;
1113 if (!revs
->full_diff
)
1114 diff_tree_setup_paths(revs
->prune_data
, &revs
->diffopt
);
1116 if (revs
->combine_merges
) {
1117 revs
->ignore_merges
= 0;
1118 if (revs
->dense_combined_merges
&& !revs
->diffopt
.output_format
)
1119 revs
->diffopt
.output_format
= DIFF_FORMAT_PATCH
;
1121 revs
->diffopt
.abbrev
= revs
->abbrev
;
1122 if (diff_setup_done(&revs
->diffopt
) < 0)
1123 die("diff_setup_done failed");
1125 if (revs
->grep_filter
) {
1126 revs
->grep_filter
->all_match
= all_match
;
1127 compile_grep_patterns(revs
->grep_filter
);
1133 void prepare_revision_walk(struct rev_info
*revs
)
1135 int nr
= revs
->pending
.nr
;
1136 struct object_array_entry
*e
, *list
;
1138 e
= list
= revs
->pending
.objects
;
1139 revs
->pending
.nr
= 0;
1140 revs
->pending
.alloc
= 0;
1141 revs
->pending
.objects
= NULL
;
1143 struct commit
*commit
= handle_commit(revs
, e
->item
, e
->name
);
1145 if (!(commit
->object
.flags
& SEEN
)) {
1146 commit
->object
.flags
|= SEEN
;
1147 insert_by_date(commit
, &revs
->commits
);
1158 if (revs
->topo_order
)
1159 sort_in_topological_order_fn(&revs
->commits
, revs
->lifo
,
1164 static int rewrite_one(struct rev_info
*revs
, struct commit
**pp
)
1167 struct commit
*p
= *pp
;
1169 add_parents_to_list(revs
, p
, &revs
->commits
);
1170 if (p
->parents
&& p
->parents
->next
)
1172 if (p
->object
.flags
& (TREECHANGE
| UNINTERESTING
))
1176 *pp
= p
->parents
->item
;
1180 static void rewrite_parents(struct rev_info
*revs
, struct commit
*commit
)
1182 struct commit_list
**pp
= &commit
->parents
;
1184 struct commit_list
*parent
= *pp
;
1185 if (rewrite_one(revs
, &parent
->item
) < 0) {
1193 static void mark_boundary_to_show(struct commit
*commit
)
1195 struct commit_list
*p
= commit
->parents
;
1199 if (commit
->object
.flags
& BOUNDARY
)
1200 commit
->object
.flags
|= BOUNDARY_SHOW
;
1204 static int commit_match(struct commit
*commit
, struct rev_info
*opt
)
1206 if (!opt
->grep_filter
)
1208 return grep_buffer(opt
->grep_filter
,
1209 NULL
, /* we say nothing, not even filename */
1210 commit
->buffer
, strlen(commit
->buffer
));
1213 static struct commit
*get_revision_1(struct rev_info
*revs
)
1219 struct commit_list
*entry
= revs
->commits
;
1220 struct commit
*commit
= entry
->item
;
1222 revs
->commits
= entry
->next
;
1225 if (revs
->reflog_info
)
1226 fake_reflog_parent(revs
->reflog_info
, commit
);
1229 * If we haven't done the list limiting, we need to look at
1230 * the parents here. We also need to do the date-based limiting
1231 * that we'd otherwise have done in limit_list().
1233 if (!revs
->limited
) {
1234 if (revs
->max_age
!= -1 &&
1235 (commit
->date
< revs
->max_age
))
1237 add_parents_to_list(revs
, commit
, &revs
->commits
);
1239 if (commit
->object
.flags
& SHOWN
)
1242 if (revs
->unpacked
&& has_sha1_pack(commit
->object
.sha1
,
1243 revs
->ignore_packed
))
1246 /* We want to show boundary commits only when their
1247 * children are shown. When path-limiter is in effect,
1248 * rewrite_parents() drops some commits from getting shown,
1249 * and there is no point showing boundary parents that
1250 * are not shown. After rewrite_parents() rewrites the
1251 * parents of a commit that is shown, we mark the boundary
1252 * parents with BOUNDARY_SHOW.
1254 if (commit
->object
.flags
& BOUNDARY_SHOW
) {
1255 commit
->object
.flags
|= SHOWN
;
1258 if (commit
->object
.flags
& UNINTERESTING
)
1260 if (revs
->min_age
!= -1 && (commit
->date
> revs
->min_age
))
1262 if (revs
->no_merges
&&
1263 commit
->parents
&& commit
->parents
->next
)
1265 if (!commit_match(commit
, revs
))
1267 if (revs
->prune_fn
&& revs
->dense
) {
1268 /* Commit without changes? */
1269 if (!(commit
->object
.flags
& TREECHANGE
)) {
1270 /* drop merges unless we want parenthood */
1273 /* non-merge - always ignore it */
1274 if (!commit
->parents
|| !commit
->parents
->next
)
1278 rewrite_parents(revs
, commit
);
1281 mark_boundary_to_show(commit
);
1282 commit
->object
.flags
|= SHOWN
;
1284 } while (revs
->commits
);
1288 struct commit
*get_revision(struct rev_info
*revs
)
1290 struct commit
*c
= NULL
;
1292 if (revs
->reverse
) {
1293 struct commit_list
*list
;
1296 * rev_info.reverse is used to note the fact that we
1297 * want to output the list of revisions in reverse
1298 * order. To accomplish this goal, reverse can have
1302 * 1 reverse the list
1303 * 2 internal use: we have already obtained and
1304 * reversed the list, now we only need to yield
1308 if (revs
->reverse
== 1) {
1311 while ((c
= get_revision(revs
)))
1312 commit_list_insert(c
, &list
);
1313 revs
->commits
= list
;
1319 c
= revs
->commits
->item
;
1320 list
= revs
->commits
->next
;
1321 free(revs
->commits
);
1322 revs
->commits
= list
;
1326 if (0 < revs
->skip_count
) {
1327 while ((c
= get_revision_1(revs
)) != NULL
) {
1328 if (revs
->skip_count
-- <= 0)
1333 /* Check the max_count ... */
1334 switch (revs
->max_count
) {
1344 return get_revision_1(revs
);