6 #define INTERESTING (1u << 1)
8 static const char rev_list_usage
[] =
9 "usage: git-rev-list [OPTION] commit-id <commit-id>\n"
15 " --merge-order [ --show-breaks ]";
17 static int verbose_header
= 0;
18 static int show_parents
= 0;
19 static int hdr_termination
= 0;
20 static const char *prefix
= "";
21 static unsigned long max_age
= -1;
22 static unsigned long min_age
= -1;
23 static int max_count
= -1;
24 static enum cmit_fmt commit_format
= CMIT_FMT_RAW
;
25 static int merge_order
= 0;
26 static int show_breaks
= 0;
28 static void show_commit(struct commit
*commit
)
32 if (commit
->object
.flags
& DISCONTINUITY
) {
34 } else if (commit
->object
.flags
& BOUNDARY
) {
38 printf("%s%s", prefix
, sha1_to_hex(commit
->object
.sha1
));
40 struct commit_list
*parents
= commit
->parents
;
42 printf(" %s", sha1_to_hex(parents
->item
->object
.sha1
));
43 parents
= parents
->next
;
48 static char pretty_header
[16384];
49 pretty_print_commit(commit_format
, commit
->buffer
, ~0, pretty_header
, sizeof(pretty_header
));
50 printf("%s%c", pretty_header
, hdr_termination
);
54 static int filter_commit(struct commit
* commit
)
56 if (commit
->object
.flags
& UNINTERESTING
)
58 if (min_age
!= -1 && (commit
->date
> min_age
))
60 if (max_age
!= -1 && (commit
->date
< max_age
))
62 if (max_count
!= -1 && !max_count
--)
68 static int process_commit(struct commit
* commit
)
70 int action
=filter_commit(commit
);
76 if (action
== CONTINUE
) {
85 static void show_commit_list(struct commit_list
*list
)
88 struct commit
*commit
= pop_most_recent_commit(&list
, SEEN
);
90 if (process_commit(commit
) == STOP
)
95 static void mark_parents_uninteresting(struct commit
*commit
)
97 struct commit_list
*parents
= commit
->parents
;
100 struct commit
*commit
= parents
->item
;
101 commit
->object
.flags
|= UNINTERESTING
;
102 parents
= parents
->next
;
106 static int everybody_uninteresting(struct commit_list
*list
)
109 struct commit
*commit
= list
->item
;
111 if (commit
->object
.flags
& UNINTERESTING
)
118 struct commit_list
*limit_list(struct commit_list
*list
)
120 struct commit_list
*newlist
= NULL
;
121 struct commit_list
**p
= &newlist
;
123 struct commit
*commit
= pop_most_recent_commit(&list
, SEEN
);
124 struct object
*obj
= &commit
->object
;
126 if (obj
->flags
& UNINTERESTING
) {
127 mark_parents_uninteresting(commit
);
128 if (everybody_uninteresting(list
))
132 p
= &commit_list_insert(commit
, p
)->next
;
137 static enum cmit_fmt
get_commit_format(const char *arg
)
140 return CMIT_FMT_DEFAULT
;
141 if (!strcmp(arg
, "=raw"))
143 if (!strcmp(arg
, "=medium"))
144 return CMIT_FMT_MEDIUM
;
145 if (!strcmp(arg
, "=short"))
146 return CMIT_FMT_SHORT
;
147 usage(rev_list_usage
);
151 int main(int argc
, char **argv
)
153 struct commit_list
*list
= NULL
;
156 for (i
= 1 ; i
< argc
; i
++) {
159 unsigned char sha1
[20];
160 struct commit
*commit
;
162 if (!strncmp(arg
, "--max-count=", 12)) {
163 max_count
= atoi(arg
+ 12);
166 if (!strncmp(arg
, "--max-age=", 10)) {
167 max_age
= atoi(arg
+ 10);
170 if (!strncmp(arg
, "--min-age=", 10)) {
171 min_age
= atoi(arg
+ 10);
174 if (!strcmp(arg
, "--header")) {
178 if (!strncmp(arg
, "--pretty", 8)) {
179 commit_format
= get_commit_format(arg
+8);
181 hdr_termination
= '\n';
185 if (!strcmp(arg
, "--parents")) {
189 if (!strncmp(arg
, "--merge-order", 13)) {
193 if (!strncmp(arg
, "--show-breaks", 13)) {
200 flags
= UNINTERESTING
;
204 if (get_sha1(arg
, sha1
) || (show_breaks
&& !merge_order
))
205 usage(rev_list_usage
);
206 commit
= lookup_commit_reference(sha1
);
207 if (!commit
|| parse_commit(commit
) < 0)
208 die("bad commit object %s", arg
);
209 commit
->object
.flags
|= flags
;
210 commit_list_insert(commit
, &list
);
214 usage(rev_list_usage
);
218 list
= limit_list(list
);
219 show_commit_list(list
);
221 if (sort_list_in_merge_order(list
, &process_commit
)) {
222 die("merge order sort failed\n");