1#include "cache.h"
2#include "commit.h"
3
4int main(int argc, char **argv)
5{
6 unsigned char sha1[20];
7 struct commit_list *list = NULL;
8 struct commit *commit;
9 char *commit_arg = NULL;
10 int i;
11 unsigned long max_age = -1;
12 unsigned long min_age = -1;
13 int max_count = -1;
14
15 for (i = 1 ; i < argc; i++) {
16 char *arg = argv[i];
17
18 if (!strncmp(arg, "--max-count=", 12)) {
19 max_count = atoi(arg + 12);
20 } else if (!strncmp(arg, "--max-age=", 10)) {
21 max_age = atoi(arg + 10);
22 } else if (!strncmp(arg, "--min-age=", 10)) {
23 min_age = atoi(arg + 10);
24 } else {
25 commit_arg = arg;
26 }
27 }
28
29 if (!commit_arg || get_sha1(commit_arg, sha1))
30 usage("usage: rev-list [OPTION] commit-id\n"
31 " --max-count=nr\n"
32 " --max-age=epoch\n"
33 " --min-age=epoch\n");
34
35 commit = lookup_commit(sha1);
36 if (!commit || parse_commit(commit) < 0)
37 die("bad commit object");
38
39 commit_list_insert(commit, &list);
40 do {
41 struct commit *commit = pop_most_recent_commit(&list, 0x1);
42
43 if (min_age != -1 && (commit->date > min_age))
44 continue;
45 if (max_age != -1 && (commit->date < max_age))
46 break;
47 if (max_count != -1 && !max_count--)
48 break;
49 printf("%s\n", sha1_to_hex(commit->object.sha1));
50 } while (list);
51 return 0;
52}