5 #define INTERESTING (1u << 1)
6 #define UNINTERESTING (1u << 2)
8 static const char rev_list_usage
[] =
9 "usage: git-rev-list [OPTION] commit-id <commit-id>\n"
16 static int verbose_header
= 0;
17 static int show_parents
= 0;
18 static int hdr_termination
= 0;
19 static const char *prefix
= "";
20 static unsigned long max_age
= -1;
21 static unsigned long min_age
= -1;
22 static int max_count
= -1;
23 static enum cmit_fmt commit_format
= CMIT_FMT_RAW
;
25 static void show_commit(struct commit
*commit
)
27 printf("%s%s", prefix
, sha1_to_hex(commit
->object
.sha1
));
29 struct commit_list
*parents
= commit
->parents
;
31 printf(" %s", sha1_to_hex(parents
->item
->object
.sha1
));
32 parents
= parents
->next
;
37 static char pretty_header
[16384];
38 pretty_print_commit(commit_format
, commit
->buffer
, ~0, pretty_header
, sizeof(pretty_header
));
39 printf("%s%c", pretty_header
, hdr_termination
);
43 static void show_commit_list(struct commit_list
*list
)
46 struct commit
*commit
= pop_most_recent_commit(&list
, SEEN
);
48 if (commit
->object
.flags
& UNINTERESTING
)
50 if (min_age
!= -1 && (commit
->date
> min_age
))
52 if (max_age
!= -1 && (commit
->date
< max_age
))
54 if (max_count
!= -1 && !max_count
--)
60 static void mark_parents_uninteresting(struct commit
*commit
)
62 struct commit_list
*parents
= commit
->parents
;
65 struct commit
*commit
= parents
->item
;
66 commit
->object
.flags
|= UNINTERESTING
;
67 parents
= parents
->next
;
71 static int everybody_uninteresting(struct commit_list
*list
)
74 struct commit
*commit
= list
->item
;
76 if (commit
->object
.flags
& UNINTERESTING
)
83 struct commit_list
*limit_list(struct commit_list
*list
)
85 struct commit_list
*newlist
= NULL
;
86 struct commit_list
**p
= &newlist
;
88 struct commit
*commit
= pop_most_recent_commit(&list
, SEEN
);
89 struct object
*obj
= &commit
->object
;
91 if (obj
->flags
& UNINTERESTING
) {
92 mark_parents_uninteresting(commit
);
93 if (everybody_uninteresting(list
))
97 p
= &commit_list_insert(commit
, p
)->next
;
102 static enum cmit_fmt
get_commit_format(const char *arg
)
105 return CMIT_FMT_DEFAULT
;
106 if (!strcmp(arg
, "=raw"))
108 if (!strcmp(arg
, "=medium"))
109 return CMIT_FMT_MEDIUM
;
110 if (!strcmp(arg
, "=short"))
111 return CMIT_FMT_SHORT
;
112 usage(rev_list_usage
);
116 int main(int argc
, char **argv
)
118 struct commit_list
*list
= NULL
;
121 for (i
= 1 ; i
< argc
; i
++) {
124 unsigned char sha1
[20];
125 struct commit
*commit
;
127 if (!strncmp(arg
, "--max-count=", 12)) {
128 max_count
= atoi(arg
+ 12);
131 if (!strncmp(arg
, "--max-age=", 10)) {
132 max_age
= atoi(arg
+ 10);
135 if (!strncmp(arg
, "--min-age=", 10)) {
136 min_age
= atoi(arg
+ 10);
139 if (!strcmp(arg
, "--header")) {
143 if (!strncmp(arg
, "--pretty", 8)) {
144 commit_format
= get_commit_format(arg
+8);
146 hdr_termination
= '\n';
150 if (!strcmp(arg
, "--parents")) {
157 flags
= UNINTERESTING
;
161 if (get_sha1(arg
, sha1
))
162 usage(rev_list_usage
);
163 commit
= lookup_commit_reference(sha1
);
164 if (!commit
|| parse_commit(commit
) < 0)
165 die("bad commit object %s", arg
);
166 commit
->object
.flags
|= flags
;
167 commit_list_insert(commit
, &list
);
171 usage(rev_list_usage
);
174 list
= limit_list(list
);
176 show_commit_list(list
);