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 pretty_print = 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;
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 const char *buf = commit->buffer;
39 static char pretty_header[16384];
40 pretty_print_commit(commit->buffer, ~0, pretty_header, sizeof(pretty_header));
43 printf("%s%c", buf, hdr_termination);
47 static void show_commit_list(struct commit_list *list)
50 struct commit *commit = pop_most_recent_commit(&list, SEEN);
52 if (commit->object.flags & UNINTERESTING)
54 if (min_age != -1 && (commit->date > min_age))
56 if (max_age != -1 && (commit->date < max_age))
58 if (max_count != -1 && !max_count--)
64 static void mark_parents_uninteresting(struct commit *commit)
66 struct commit_list *parents = commit->parents;
69 struct commit *commit = parents->item;
70 commit->object.flags |= UNINTERESTING;
71 parents = parents->next;
75 static int everybody_uninteresting(struct commit_list *list)
78 struct commit *commit = list->item;
80 if (commit->object.flags & UNINTERESTING)
87 struct commit_list *limit_list(struct commit_list *list, struct commit *end)
89 struct commit_list *newlist = NULL;
90 struct commit_list **p = &newlist;
92 struct commit *commit = pop_most_recent_commit(&list, SEEN);
93 struct object *obj = &commit->object;
95 if (commit == end || (obj->flags & UNINTERESTING)) {
96 mark_parents_uninteresting(commit);
97 if (everybody_uninteresting(list))
101 p = &commit_list_insert(commit, p)->next;
106 int main(int argc, char **argv)
109 unsigned char sha1[2][20];
110 struct commit_list *list = NULL;
111 struct commit *commit, *end;
115 for (i = 1 ; i < argc; i++) {
118 if (!strncmp(arg, "--max-count=", 12)) {
119 max_count = atoi(arg + 12);
122 if (!strncmp(arg, "--max-age=", 10)) {
123 max_age = atoi(arg + 10);
126 if (!strncmp(arg, "--min-age=", 10)) {
127 min_age = atoi(arg + 10);
130 if (!strcmp(arg, "--header")) {
134 if (!strcmp(arg, "--pretty")) {
137 hdr_termination = '\n';
141 if (!strcmp(arg, "--parents")) {
146 if (nr_sha > 2 || get_sha1(arg, sha1[nr_sha]))
147 usage(rev_list_usage);
152 usage(rev_list_usage);
154 commit = lookup_commit_reference(sha1[0]);
155 if (!commit || parse_commit(commit) < 0)
156 die("bad starting commit object");
160 end = lookup_commit_reference(sha1[1]);
161 if (!end || parse_commit(end) < 0)
162 die("bad ending commit object");
165 commit_list_insert(commit, &list);
167 list = limit_list(list, end);
169 show_commit_list(list);