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 void mark_parents_uninteresting(struct commit *commit)
18 struct commit_list *parents = commit->parents;
21 struct commit *commit = parents->item;
22 commit->object.flags |= UNINTERESTING;
23 parents = parents->next;
27 static int everybody_uninteresting(struct commit_list *list)
30 struct commit *commit = list->item;
32 if (commit->object.flags & UNINTERESTING)
39 int main(int argc, char **argv)
42 unsigned char sha1[2][20];
43 struct commit_list *list = NULL;
44 struct commit *commit, *end;
45 int i, verbose_header = 0, show_parents = 0, pretty_print = 0;
46 int hdr_termination = 0;
47 const char *prefix = "";
48 unsigned long max_age = -1;
49 unsigned long min_age = -1;
53 for (i = 1 ; i < argc; i++) {
56 if (!strncmp(arg, "--max-count=", 12)) {
57 max_count = atoi(arg + 12);
60 if (!strncmp(arg, "--max-age=", 10)) {
61 max_age = atoi(arg + 10);
64 if (!strncmp(arg, "--min-age=", 10)) {
65 min_age = atoi(arg + 10);
68 if (!strcmp(arg, "--header")) {
72 if (!strcmp(arg, "--pretty")) {
75 hdr_termination = '\n';
79 if (!strcmp(arg, "--parents")) {
84 if (nr_sha > 2 || get_sha1(arg, sha1[nr_sha]))
85 usage(rev_list_usage);
90 usage(rev_list_usage);
92 commit = lookup_commit_reference(sha1[0]);
93 if (!commit || parse_commit(commit) < 0)
94 die("bad starting commit object");
98 end = lookup_commit_reference(sha1[1]);
99 if (!end || parse_commit(end) < 0)
100 die("bad ending commit object");
103 commit_list_insert(commit, &list);
105 struct commit_list *newlist = NULL;
106 struct commit_list **p = &newlist;
108 struct commit *commit = pop_most_recent_commit(&list, SEEN);
109 struct object *obj = &commit->object;
111 if (commit == end || (obj->flags & UNINTERESTING)) {
112 mark_parents_uninteresting(commit);
113 if (everybody_uninteresting(list))
117 p = &commit_list_insert(commit, p)->next;
123 struct commit *commit = pop_most_recent_commit(&list, SEEN);
125 if (commit->object.flags & UNINTERESTING)
127 if (min_age != -1 && (commit->date > min_age))
129 if (max_age != -1 && (commit->date < max_age))
131 if (max_count != -1 && !max_count--)
133 printf("%s%s", prefix, sha1_to_hex(commit->object.sha1));
135 struct commit_list *parents = commit->parents;
137 printf(" %s", sha1_to_hex(parents->item->object.sha1));
138 parents = parents->next;
142 if (verbose_header) {
143 const char *buf = commit->buffer;
145 static char pretty_header[16384];
146 pretty_print_commit(commit->buffer, ~0, pretty_header, sizeof(pretty_header));
149 printf("%s%c", buf, hdr_termination);