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"
15 static void mark_parents_uninteresting(struct commit *commit)
17 struct commit_list *parents = commit->parents;
20 struct commit *commit = parents->item;
21 commit->object.flags |= UNINTERESTING;
22 parents = parents->next;
26 static int everybody_uninteresting(struct commit_list *list)
29 struct commit *commit = list->item;
31 if (commit->object.flags & UNINTERESTING)
38 int main(int argc, char **argv)
41 unsigned char sha1[2][20];
42 struct commit_list *list = NULL;
43 struct commit *commit, *end;
44 int i, verbose_header = 0, show_parents = 0;
45 unsigned long max_age = -1;
46 unsigned long min_age = -1;
50 for (i = 1 ; i < argc; i++) {
53 if (!strncmp(arg, "--max-count=", 12)) {
54 max_count = atoi(arg + 12);
57 if (!strncmp(arg, "--max-age=", 10)) {
58 max_age = atoi(arg + 10);
61 if (!strncmp(arg, "--min-age=", 10)) {
62 min_age = atoi(arg + 10);
65 if (!strcmp(arg, "--header")) {
69 if (!strcmp(arg, "--parents")) {
74 if (nr_sha > 2 || get_sha1(arg, sha1[nr_sha]))
75 usage(rev_list_usage);
80 usage(rev_list_usage);
82 commit = lookup_commit_reference(sha1[0]);
83 if (!commit || parse_commit(commit) < 0)
84 die("bad starting commit object");
88 end = lookup_commit_reference(sha1[1]);
89 if (!end || parse_commit(end) < 0)
90 die("bad ending commit object");
93 commit_list_insert(commit, &list);
95 struct commit_list *newlist = NULL;
96 struct commit_list **p = &newlist;
98 struct commit *commit = pop_most_recent_commit(&list, SEEN);
99 struct object *obj = &commit->object;
101 if (commit == end || (obj->flags & UNINTERESTING)) {
102 mark_parents_uninteresting(commit);
103 if (everybody_uninteresting(list))
107 p = &commit_list_insert(commit, p)->next;
113 struct commit *commit = pop_most_recent_commit(&list, SEEN);
115 if (commit->object.flags & UNINTERESTING)
117 if (min_age != -1 && (commit->date > min_age))
119 if (max_age != -1 && (commit->date < max_age))
121 if (max_count != -1 && !max_count--)
123 printf("%s", sha1_to_hex(commit->object.sha1));
125 struct commit_list *parents = commit->parents;
127 printf(" %s", sha1_to_hex(parents->item->object.sha1));
128 parents = parents->next;
133 printf("%s%c", commit->buffer, 0);